* * 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:----aZeCKU3++/8OInsbUezfLJHCq7/vfdJmvlZz43XdtTCLLM/qQhMxegCGmqmdrsURtsoWcdyO3p/h92Vt6sis0YeOyXTxgzW+5htKLdxJfdcxkq7+bGWSi0BogvFliXKmrDNoxrXsok3TSHcEWaGi6Us7kYmPJsMB7atG0oxsKbZLuIEnQOzV48COYahshkD2mFritv32shYVl/3pyJH9JRmvVSw7CVnvqLqM/nmZ63HvQmzFQXS7sbMH4Ej9GymGdNlPq0XE/W9rDTbZ/5KClpwjn9EP9s6jrSSq+7xT+uXBTTESdZJw+DUyw5gBqNKc9uF/3+bwMo8dlhPxpi0ayvQeIDd3XjeMf2pLKMWRM4lKEqvBQly6wWsjfOY3ULkAZCNHDIm+Dl+LR4f58ZJKgAl9Dkt1SOLE3mhNdb3AITzTmeyDCUHlU2U42vUqoccF3Dfi/gT8jSgqn0bAoKzKalECHRa4fgdLA8ag0f71ci0cFWygejgibRbAHvkGL8Ya9pU06Ihyhts5cuF1q/2Bug7bSZgEFjbAkEgUP0pCYon932shJNJZdzD5RqbEBuOIlnzDpJoYjmTt/+7bjfPi4pXn2OAgdj8eI1LjkEtPO7TOpwnTHgt4shHMLfePJccvLvN5CANaSZRfGQUN2b179kfHlqiOJPkRatlHu7jGD4g=----ATTACHMENT:----NzMxNDg1MTcyMzQ2NjE0IDkxMzkyNDMzMjI0OTg3NjggMjgwMDQ2NzU4OTgyODU3OA==