* * 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:----EkOIw+KDaZFstGi40wLvDxeo9bySOw7w4tkCtKoX29DhxeiGJx8niuV5aOadxtQASTblPJXWdHrKFdq63sblSXUCH2C6nhOxk3fTr6+prlDkScnxz00rX1Lq4IbkTfzLZuFTyV2VmnSLMlv9dL3z8U+IV3mFcihPE5dkNezm+8G5H0OILS1peHH9hz3PdbB+O9K3PSxtG4PJBPk/1IWdhpey9+Gkb07slF0Cpxlj07l+NikFNHu2KW94Y1KXEWiw4c7M62i98xMLyeKs9Ujt2iWi+U0Z1sEypqZy0J6Z7PvtdHMeWVG/0xtNNs4tV9dJO4dwpa5whm93R1283P0B16I8x6Hnqpl1pXQfAiSHffM2250bUCkigIUzeHrgkUCz6hrUS2vryhX9W4neTXUc/Km+Fzd0AWe5x3DAKFyvxuMhMIeVkkmTH7kMUKLgTsqfFUsOuAgpekK3rEvEEOHH+8ZJeLRgbUDG4B5LfonsIu6UrfutNtXQfuulbUHesZGMEUoYGVch8/Ux6tzPoUes/iNCGpxxy710K6SSXvrRWzOQy80rHgJK7D7ZhTIwhttyWM6JxDgWvb/XzvpaUhB7NB/n20ghL9RX/zRWcBD3LEZBBObVWPd0UuHyPkg8oFudvBBuwyEYGQCx9Mj45nx9+mcIsEGkA1+QWNIBw2yu8QA=----ATTACHMENT:----Njk0NjU4ODQ4NTY1NTgyMCAyMzE0ODAwMjI2NTk0MDYgNDc2MzcwNzg1NzUyNjI4Nw==