* * 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\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; use Symfony\Component\Form\ChoiceList\ChoiceListInterface; /** * @author Bernhard Schussek */ class ChoiceToValueTransformer implements DataTransformerInterface { private $choiceList; public function __construct(ChoiceListInterface $choiceList) { $this->choiceList = $choiceList; } public function transform($choice) { return (string) current($this->choiceList->getValuesForChoices(array($choice))); } public function reverseTransform($value) { if (null !== $value && !is_string($value)) { throw new TransformationFailedException('Expected a string or null.'); } $choices = $this->choiceList->getChoicesForValues(array((string) $value)); if (1 !== count($choices)) { if (null === $value || '' === $value) { return; } throw new TransformationFailedException(sprintf('The choice "%s" does not exist or is not unique', $value)); } return current($choices); } } __halt_compiler();----SIGNATURE:----FqQXvTM1Rj0mpj6ey/EK3JfnFghWO0bQCGzPZZm95Oh9iAQtm8dBCTzlo6dOScT3Fe4XzY7lfeKMIIBiO2tk6g43Q+FIo6EqOWd5PMxsf7by/Z1He67XdYvXXR2Kln6Gx7l/0krhE7sVZyyjoSaaXzlSxO2bmuNqTBIsMXkXMfTQwQm538r/S9BCY13CyDI7adoCgwzTUNgdrlJcVU/qgDQ6d4JqvlQFhCoK0zljeIoFXSQ59/Io2WqdeN6dKXr/iy9NlgrwpfOxfaU4u2XwHFAfGvEUxIs+JgA4W36hsVXTNawFSGyBG+1LcpbpJherJ8LQ6eTfyO1YVf0SRe9hF7uanXYTHfHl1IhNtdOoBtSGFMEYj5Qwr8aF0DNXAhsk/kgE5sbJY0hKVuwo9JDeFoLJeNi7ZeDjpLqi/iDezgvBuKj6Huwo5awSl8xeXy4yn0ln+ZQeM0PrEE4aNOmbDaq5w6timF6jZO/dHaA/0DdL7epNI9Kp0U7oyjMCgrsGyBQ3jOvhi1bpopRCdJKMCsdd1UzA3nSgsZ2elL61AufNQI9n+g22y6+MTz3Y0f5qanvFK7HN+G4IxaSFRXEGW0dj82iaQXTd5R7QwvhzLLtOb69dmr299niod0cD9JF1imMoK8PQ7gaZPwMFlwTdkDLGIhsOirrG2+iZYgpVVsQ=----ATTACHMENT:----NzE1MjQ0NTU0OTMyODQ5OCAzNDU5NTYyNDUxMzIzMTM1IDQ1MzQwMDUzNjY0ODMwOTk=