* * 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; /** * @author Bernhard Schussek */ class ValueToDuplicatesTransformer implements DataTransformerInterface { private $keys; public function __construct(array $keys) { $this->keys = $keys; } /** * Duplicates the given value through the array. * * @param mixed $value The value * * @return array The array */ public function transform($value) { $result = array(); foreach ($this->keys as $key) { $result[$key] = $value; } return $result; } /** * Extracts the duplicated value from an array. * * @return mixed The value * * @throws TransformationFailedException if the given value is not an array or * if the given array can not be transformed */ public function reverseTransform($array) { if (!is_array($array)) { throw new TransformationFailedException('Expected an array.'); } $result = current($array); $emptyKeys = array(); foreach ($this->keys as $key) { if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && array() !== $array[$key]) { if ($array[$key] !== $result) { throw new TransformationFailedException( 'All values in the array should be the same' ); } } else { $emptyKeys[] = $key; } } if (count($emptyKeys) > 0) { if (count($emptyKeys) == count($this->keys)) { // All keys empty return; } throw new TransformationFailedException( sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys) )); } return $result; } } __halt_compiler();----SIGNATURE:----IWrsDiZoF4KT7uDH8ZRLoxejU57W+ROgXDy/dbdiOyeCP7pnkTwXTJ/G+sq5JCaC2X5ZCLfQJERhtsIbbZspNAugEACqWOMb9tHMQjk+He2B+wH+eZ5e/1hhT8DDAqpw+jhy9bFret+EQfUNsee+wZqAZigAPEhXPQrGUkgIM7utf1ZJqxvg1CDMsP1IOQEokWfMs34ensSkYwnWMRvk9X3FN4J2NVWkvkmUore5SIVGNS/W8hYZ6BMBGCdV589feat/OXHXRRSn2f4UxqmIrAhAgKo2GO5CykN0lus9307gaos9GyTypAkiI7AIvtfC25ws16q+hCT5U6AQ0VxlgYhymz7JuaZVyDKnmfxmH/noQ9n4ldQb98C82mwHlheQ4+79V0nLQvjXo7DBN/uytry/26+VfmAEOv5bfDTVTN0d9pMZY9GApxMAkbIEtPVIH29jGSPUsKJiMWyS2xum4ZjMSQvAPT8wVJSX/ouR7yqPfuPz2JwhxTQKgl15bI/l1gYA0B+azbvfzKfDdS6C+Em/sdiTXB2BWsMrvC2S3siU+13TSqlP6f6/7MggjJd2QncH9S44L9D5O46KZSjRCoNYXQmawep285Qs0W9zUfyygkxYC3ok3QfI6lCBAJIv7LkTbEUJg4+npcHXhA7YYOsJbl3JDMQgzXJuDYTINFk=----ATTACHMENT:----MTUwNTM4NTIyNzg5ODQ0NiA1NTI0OTE4NDA2ODk1MzI1IDUyMzgwODI5MjUzOTgzMDk=