vendor/symfony/form/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php line 45

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.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\Extension\Core\DataTransformer;
  11. use Symfony\Component\Form\Exception\TransformationFailedException;
  12. /**
  13.  * Transforms between an integer and a localized number with grouping
  14.  * (each thousand) and comma separators.
  15.  *
  16.  * @author Bernhard Schussek <bschussek@gmail.com>
  17.  */
  18. class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransformer
  19. {
  20.     /**
  21.      * Constructs a transformer.
  22.      *
  23.      * @param bool $grouping     Whether thousands should be grouped
  24.      * @param int  $roundingMode One of the ROUND_ constants in this class
  25.      */
  26.     public function __construct($grouping false$roundingMode self::ROUND_DOWN)
  27.     {
  28.         if (\is_int($grouping) || \is_bool($roundingMode) || < \func_num_args()) {
  29.             @trigger_error(sprintf('Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.'__CLASS__), E_USER_DEPRECATED);
  30.             $grouping $roundingMode;
  31.             $roundingMode < \func_num_args() ? func_get_arg(2) : self::ROUND_DOWN;
  32.         }
  33.         parent::__construct(0$grouping$roundingMode);
  34.     }
  35.     /**
  36.      * {@inheritdoc}
  37.      */
  38.     public function reverseTransform($value)
  39.     {
  40.         $decimalSeparator $this->getNumberFormatter()->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
  41.         if (\is_string($value) && false !== strpos($value$decimalSeparator)) {
  42.             throw new TransformationFailedException(sprintf('The value "%s" is not a valid integer.'$value));
  43.         }
  44.         $result parent::reverseTransform($value);
  45.         return null !== $result ? (int) $result null;
  46.     }
  47.     /**
  48.      * @internal
  49.      */
  50.     protected function castParsedValue($value)
  51.     {
  52.         return $value;
  53.     }
  54. }