* * 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 Doctrine\Common\Annotations\Reader; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\MaxDepth; use Symfony\Component\Serializer\Exception\MappingException; use Symfony\Component\Serializer\Mapping\AttributeMetadata; use Symfony\Component\Serializer\Mapping\ClassMetadataInterface; /** * Annotation loader. * * @author Kévin Dunglas */ class AnnotationLoader implements LoaderInterface { private $reader; public function __construct(Reader $reader) { $this->reader = $reader; } /** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadataInterface $classMetadata) { $reflectionClass = $classMetadata->getReflectionClass(); $className = $reflectionClass->name; $loaded = false; $attributesMetadata = $classMetadata->getAttributesMetadata(); foreach ($reflectionClass->getProperties() as $property) { if (!isset($attributesMetadata[$property->name])) { $attributesMetadata[$property->name] = new AttributeMetadata($property->name); $classMetadata->addAttributeMetadata($attributesMetadata[$property->name]); } if ($property->getDeclaringClass()->name === $className) { foreach ($this->reader->getPropertyAnnotations($property) as $annotation) { if ($annotation instanceof Groups) { foreach ($annotation->getGroups() as $group) { $attributesMetadata[$property->name]->addGroup($group); } } elseif ($annotation instanceof MaxDepth) { $attributesMetadata[$property->name]->setMaxDepth($annotation->getMaxDepth()); } $loaded = true; } } } foreach ($reflectionClass->getMethods() as $method) { if ($method->getDeclaringClass()->name !== $className) { continue; } $accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches); if ($accessorOrMutator) { $attributeName = lcfirst($matches[2]); if (isset($attributesMetadata[$attributeName])) { $attributeMetadata = $attributesMetadata[$attributeName]; } else { $attributesMetadata[$attributeName] = $attributeMetadata = new AttributeMetadata($attributeName); $classMetadata->addAttributeMetadata($attributeMetadata); } } foreach ($this->reader->getMethodAnnotations($method) as $annotation) { if ($annotation instanceof Groups) { if (!$accessorOrMutator) { throw new MappingException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name)); } foreach ($annotation->getGroups() as $group) { $attributeMetadata->addGroup($group); } } elseif ($annotation instanceof MaxDepth) { if (!$accessorOrMutator) { throw new MappingException(sprintf('MaxDepth on "%s::%s" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name)); } $attributeMetadata->setMaxDepth($annotation->getMaxDepth()); } $loaded = true; } } return $loaded; } } __halt_compiler();----SIGNATURE:----BsW9S00gjF0k2cT+pRIWp7bipeCnZl1VnIpKDfCH7o2C8ZaDd05ytuhxO8tKFVAj4xr9Tg0TzIVT3gZy7Sk5HdwDbaq/wM89IeyOa100gpBiB4KybpwGvri+5f1baSNxF1qXpDa+dopKxXIU20eTvhRqsjJ1ubb/BKVcQ17bFRnwcNBDCuwVt3yT6VbjsEFWlvGf01rBf1W6mf9YrycERXV8hxLDZHcBBKPXpDobUKfzZuYOws8V89Krqhv00VhOWU2kVdO+VLaQ7SC5r2St93pe3bSk/x6BB7HQeo8KonLVHmOvtRXn+4OfswPGEbWArSAWlvLTMq6eWAsI1a9hN0P5qlA1IjsuTU/pCOjmrzlziFUA52+m3ahB2k6ZdnqJO9AIoul5Q1xlmM/ecbXH0XDe4HH21jtm8EY8pc9MbG15T7Oq8p6M2GuKQRYq21cNVznOXGoc00qC+BpX4F05vHaVq7gwTsgZ6G6D77gboMLTLIltABmaWfRt80y4QQx2/J00lVoLe5J3lb/rvu5YkbenqMhZVFj1jk3+CpxqOBF79jx5XAsSVjDyICR74IjjVjTsLXTjy0zy1ge8w6tg+7qp/1Tr49gmaB4lY1SbtW1NA4nGKbaF3YT3wCyeSL5kXAhs5lI+N/aqgXv2Ie2Oykkb7CL0WaZSd16Or5XpgXw=----ATTACHMENT:----ODYxNzAwMDI2Njc5NjQ5NSA5Nzg5OTM1ODY5MzY1Njc1IDcwNTE5NzU0NTQxMDEzNTY=