* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Serializer\Mapping\Loader; use Symfony\Component\Serializer\Exception\MappingException; use Symfony\Component\Serializer\Mapping\AttributeMetadata; use Symfony\Component\Serializer\Mapping\ClassMetadataInterface; use Symfony\Component\Yaml\Parser; /** * YAML File Loader. * * @author Kévin Dunglas */ class YamlFileLoader extends FileLoader { private $yamlParser; /** * An array of YAML class descriptions. * * @var array */ private $classes; /** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadataInterface $classMetadata) { if (null === $this->classes) { $this->classes = $this->getClassesFromYaml(); } if (!$this->classes) { return false; } if (!isset($this->classes[$classMetadata->getName()])) { return false; } $yaml = $this->classes[$classMetadata->getName()]; if (isset($yaml['attributes']) && \is_array($yaml['attributes'])) { $attributesMetadata = $classMetadata->getAttributesMetadata(); foreach ($yaml['attributes'] as $attribute => $data) { if (isset($attributesMetadata[$attribute])) { $attributeMetadata = $attributesMetadata[$attribute]; } else { $attributeMetadata = new AttributeMetadata($attribute); $classMetadata->addAttributeMetadata($attributeMetadata); } if (isset($data['groups'])) { if (!\is_array($data['groups'])) { throw new MappingException(sprintf('The "groups" key must be an array of strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName())); } foreach ($data['groups'] as $group) { if (!\is_string($group)) { throw new MappingException(sprintf('Group names must be strings in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName())); } $attributeMetadata->addGroup($group); } } if (isset($data['max_depth'])) { if (!is_int($data['max_depth'])) { throw new MappingException(sprintf('The "max_depth" value must be an integer in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName())); } $attributeMetadata->setMaxDepth($data['max_depth']); } } } return true; } /** * Return the names of the classes mapped in this file. * * @return string[] The classes names */ public function getMappedClasses() { if (null === $this->classes) { $this->classes = $this->getClassesFromYaml(); } return array_keys($this->classes); } private function getClassesFromYaml() { if (!stream_is_local($this->file)) { throw new MappingException(sprintf('This is not a local file "%s".', $this->file)); } if (null === $this->yamlParser) { $this->yamlParser = new Parser(); } $classes = $this->yamlParser->parseFile($this->file); if (empty($classes)) { return array(); } if (!\is_array($classes)) { throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file)); } return $classes; } } __halt_compiler();----SIGNATURE:----bYkybEpLy+qz/Gd/TgjtT6Bwnszxcg5q518P3D7Kr/NjYmQH/5hq/gM+uNGxA7vH2D+Twxk1sfEidv09ma5JXfZTKq+7HeqBTAWjNXDm8Vsv8zhPUK4w7teZ38wO4cXQ9G1EZnHZ99WCUvUtN3rjZCHKsk4WIl9BI+/5szhh1fIjHPep3QEA1E3LBcyoIBdXukQHPpG/WXGFP56Syjtlg3Y/nt5R+RVoqVQ1+S4soRTrfIP5K77UF2JuDelxVtKcfqiLkhot+keZFgb8QPYYJQ0WrSmKZaTlgspoST9VTGSnmBSYQTTefBuNP8QEnDBCz4J6SqUgKfOcV+DLSlX7rzY6AeGO3FvOPOQqnPzWAVLykWHhpx7lU2vSb9UL5Qmh6dn6aO3LFcLIEpfbi2RM72m4BLAUrntI2q7TgLFSiK4HKwdkKqqk1t5UiFYZ/BwnhIPAXAT0uCPCBfcaPkb0jv6FyWxYTlHE21hR2OUwN5ibVaw0fqUn9U4SsSRKmEHkR/lPapdyKn+bmwFf8YzDxqt5ll/5dIdZ1bxBOjjKwS/uKn1Ld8XkODEOIortpY/2YB3jjeRbECzOTryDb19PrmGAfUIBZ8gHoA2zbX2YKhcuJqZ3WlpsOMt+jknTJrn0WKVtalwU7jJGz47Z9iGDZZ5TRG+H2B3xC+5fNZrHskE=----ATTACHMENT:----MjE0NDIyMTkxNTI5MTM3IDUxNjQzMjM5NzYyNjg0MjggOTkyMDY1NTE5MTUwNDI3