* * 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:----ftrjZ8JbwVInQgvetbXLQbgvN3IVnuM+Sq7A4qbaFfCfRR0mYEobR+e4E+cfKilT+DGXHy+S0hk7xTQuiOZXQgE1lXWUVfWKoS0p6RGgiC5pTB41LDjjwJc2TNExASSANkpDWJ1lBDOUrFp+rEN1fR/lrvmm1KJt6457iEz7Y8VwxRDeI88hTwi2bjV1GZmlwDBKJdv7OvNcQw0U2V5NzvAD6Nz8ORCCnXQYIbJgiN1mN7RHCAWHQjNiK/MP+eUSHrg7kcb3OVgoISsSOP8BcPNztmJpqeC5qvRau2KURMc+JmlkvTH/DTexIEi8lX8BfmzDA4YtH/TW+s5U8kx4FzAwAWexcZ/Qm4g3XM3YF1ofBBvgfTh55AgBpYv4F/SGgu6wFDe0AkkTPQnO9f79/x7NaNgPwNmzdaHD2Ju0dTu1OeyeVmNMMxGIcz4PEoY6DId+6TszWC9YFEfqHgEmzrDy/eMe3QxsGyEMS1EwVvu3CJ2d7038rn4BzDU+sRvEWkG1V8n4xCxfRdZMBDYPTDzalH9DNWJFdf4bUtw1a/Z+XYpthvibSW0GCK9ILBLfMgur9F0gFq0yYBnDWxAOLogM65KykcA+tZU+thKfTmF+24h59aj4rUe9VN75hdkVwbOwj5phfUxNL99c5keQifo/ZB9eqxB8FNW3k8Mvxw4=----ATTACHMENT:----MzU1MjU3MTM4MTcxNDUzMSA2MDAwMzEzOTc2MjMzODQ2IDQwMTI5Njg4NjE2NTE3MTc=