IntegerField.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form;
  11. use Symfony\Component\Form\ValueTransformer\NumberToLocalizedStringTransformer;
  12. /*
  13. * This file is part of the Symfony package.
  14. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  15. *
  16. * For the full copyright and license information, please view the LICENSE
  17. * file that was distributed with this source code.
  18. */
  19. /**
  20. * A localized field for entering integers.
  21. *
  22. * The rounding-mode option defaults to rounding down. The available values are:
  23. * * NumberToLocalizedStringTransformer::ROUND_DOWN
  24. * * NumberToLocalizedStringTransformer::ROUND_UP
  25. * * NumberToLocalizedStringTransformer::ROUND_FLOOR
  26. * * NumberToLocalizedStringTransformer::ROUND_CEILING
  27. *
  28. * @see Symfony\Component\Form\NumberField
  29. * @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
  30. */
  31. class IntegerField extends NumberField
  32. {
  33. /**
  34. * {@inheritDoc}
  35. */
  36. protected function configure()
  37. {
  38. $this->addOption('precision', 0);
  39. // Integer cast rounds towards 0, so do the same when displaying fractions
  40. $this->addOption('rounding-mode', NumberToLocalizedStringTransformer::ROUND_DOWN);
  41. parent::configure();
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function getData()
  47. {
  48. return (int)parent::getData();
  49. }
  50. }