* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form\Extension\Core\DataTransformer; use Symfony\Component\Form\Exception\TransformationFailedException; /** * Transforms between a normalized format and a localized money string. * * @author Bernhard Schussek * @author Florian Eckerstorfer */ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransformer { private $divisor; public function __construct($scale = 2, $grouping = true, $roundingMode = self::ROUND_HALF_UP, $divisor = 1) { if (null === $grouping) { $grouping = true; } if (null === $scale) { $scale = 2; } parent::__construct($scale, $grouping, $roundingMode); if (null === $divisor) { $divisor = 1; } $this->divisor = $divisor; } /** * Transforms a normalized format into a localized money string. * * @param int|float $value Normalized number * * @return string Localized money string * * @throws TransformationFailedException if the given value is not numeric or * if the value can not be transformed */ public function transform($value) { if (null !== $value && 1 !== $this->divisor) { if (!is_numeric($value)) { throw new TransformationFailedException('Expected a numeric.'); } $value = (string) ($value / $this->divisor); } return parent::transform($value); } /** * Transforms a localized money string into a normalized format. * * @param string $value Localized money string * * @return int|float Normalized number * * @throws TransformationFailedException if the given value is not a string * or if the value can not be transformed */ public function reverseTransform($value) { $value = parent::reverseTransform($value); if (null !== $value && 1 !== $this->divisor) { $value = (float) (string) ($value * $this->divisor); } return $value; } } __halt_compiler();----SIGNATURE:----dTeM1nRxeB2ykEaodNM26Tgv/0hY+MEFwJRIimD+T3b1MvpFmEOncKNR6XhJGy155wn3ZipDLCWl2KQFxLZpGfoLUrW2HtTnLZlXmsoHW+rf4VtSoHOfIYuJ13VMUiuZG8obfNn1fYvdNODg92F4/vJqRSKoxmLssbqKUiMHvFN5ruYnG9gbXZUruy2cwuB1gI0CwdD0qrzdNW7g83CT+6meRjlpi6I/1zcYsOHMm+utycSS6pN6eiVmtgv60xdBzhenVOTolsOv5uLH+hy6jOhWWc+oaGsp8IAtABw7pEtymtjk/ZLN9UhFKu+2E2so/cOCvv3jaFkU0VyscAhXjK17Nb6/q1ybuwUa5E2N7KlemhJUhbWJuqRPhOyGft0cSUSj9ThJUjHmAQBIQsoY1QG4JxRlbbxpKFq0bD408fSYUElOfvDmu4PYx/OLrS3tbcOKFdoz+zyN59CVVik5PB/j4VPB0vvOvA+aEIXPoCsjxoG0dG3QgWaSAJt0Wfk5wzgBt5A6T49pctMUdcO6C4XelAwu9Mvh/k9mkw2LtJQBRRDuHAmEk8O9A7pMuLAomHJrY5RFPgBJ4NDI8JhNIk7bgNEKKKfQ6YIuQS3Dasvsz2KJsts6KWCMsom989l8OYx7tEe7v22WmjjH12WYxn+L5OGIVLeaP097UgprDPs=----ATTACHMENT:----MjExNjM4MDEzMjg1MTggOTc3NTY1ODkwNjIzOTcyMiAzODE3MTI2MjYxODU4NDc4