* * 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 ArrayToPartsTransformer implements DataTransformerInterface { private $partMapping; public function __construct(array $partMapping) { $this->partMapping = $partMapping; } public function transform($array) { if (null === $array) { $array = array(); } if (!is_array($array)) { throw new TransformationFailedException('Expected an array.'); } $result = array(); foreach ($this->partMapping as $partKey => $originalKeys) { if (empty($array)) { $result[$partKey] = null; } else { $result[$partKey] = array_intersect_key($array, array_flip($originalKeys)); } } return $result; } public function reverseTransform($array) { if (!is_array($array)) { throw new TransformationFailedException('Expected an array.'); } $result = array(); $emptyKeys = array(); foreach ($this->partMapping as $partKey => $originalKeys) { if (!empty($array[$partKey])) { foreach ($originalKeys as $originalKey) { if (isset($array[$partKey][$originalKey])) { $result[$originalKey] = $array[$partKey][$originalKey]; } } } else { $emptyKeys[] = $partKey; } } if (count($emptyKeys) > 0) { if (count($emptyKeys) === count($this->partMapping)) { // All parts empty return; } throw new TransformationFailedException( sprintf('The keys "%s" should not be empty', implode('", "', $emptyKeys) )); } return $result; } } __halt_compiler();----SIGNATURE:----l81Br/6bSl0JqTrNsEtrzC5iFIBtib7HuV2PjU2UYlyWTzyL1ybfz9i9BvVq1QWYK4Yz0/3mKnvoImX9HooreVeXKgBbVziXTtS9XDbayZoOr0JD4ajhE3ydPvJ4Ly2xa4g6hi1KmdP8z3PfJsAwuGIqCFAZgJWkyIfGe8uYOLiWVwlrhLM8/SVLTK1FrA0QmQE5cIza761uJDB/vL9m0R2w+AcixnUWCot35JierJTPPUi5tyoc5CJLNeUC3wzhOUbfd6rRt4KneeJdgo3TKH7u8Z7Yh1Pmrot8/OyeRVuYqaNtmdyj2+WVfnqXCVITLjPVjtNbfNK2uyRPiXgJDk8p3rRppFd+K0wfvkkFIiomrbd2mk272wwMzwgejurBoE4Eos2hdKxxYdOPdZbF8rDchaAIaHuH7PJEdNtYFZif3RpCxRba3/cEoOTA2mBC43GP2C7rCxV+mPIT+vO1ooKkQ+0lhLFifhDyVkoIm864u5UVayi1br87/+sru5vlLP34eABqyqXvXSBnY/7evdREVj3Z1Clu3KKwGRmuQBMbBKEhXz8HeW35Qh8BxJgg2sSmP/aO8ySZ1yK5/Xy/Zsc4WDlkTys9wUAaBwawRERzy21l9derYKZetSkYbRXTscBjSdmm77/xu5o5EpR5eVjjlqgbaqH9dTZJrGX2bdo=----ATTACHMENT:----MzU3NzAyMjQzMjgyODczNyA1NTI4MjAzNDA4MDIwMzIgMzEwMzE5NjI3ODIyMTE1MA==