/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { $reflClass = $metadata->getReflectionClass(); $className = $reflClass->name; $loaded = false; foreach ($reflClass->getProperties() as $property) { if ($property->getDeclaringClass()->name == $className) { foreach ($this->reader->getPropertyAnnotations($property) as $groups) { if ($groups instanceof Groups) { foreach ($groups->getGroups() as $group) { $metadata->addAttributeGroup($property->name, $group); } } $loaded = true; } } } foreach ($reflClass->getMethods() as $method) { if ($method->getDeclaringClass()->name == $className) { foreach ($this->reader->getMethodAnnotations($method) as $groups) { if ($groups instanceof Groups) { if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) { foreach ($groups->getGroups() as $group) { $metadata->addAttributeGroup(lcfirst($matches[2]), $group); } } else { throw new \BadMethodCallException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name)); } } $loaded = true; } } } return $loaded; }
public static function createXmlCLassMetadata() { $expected = new ClassMetadata('Symfony\\Component\\Serializer\\Tests\\Fixtures\\GroupDummy'); $expected->addAttributeGroup('foo', 'group1'); $expected->addAttributeGroup('foo', 'group2'); $expected->addAttributeGroup('bar', 'group2'); return $expected; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { 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->parse(file_get_contents($this->file)); if (empty($classes)) { return false; } // not an array if (!is_array($classes)) { throw new MappingException(sprintf('The file "%s" must contain a YAML array.', $this->file)); } $this->classes = $classes; } if (isset($this->classes[$metadata->getClassName()])) { $yaml = $this->classes[$metadata->getClassName()]; if (isset($yaml['attributes']) && is_array($yaml['attributes'])) { foreach ($yaml['attributes'] as $attribute => $data) { if (isset($data['groups'])) { foreach ($data['groups'] as $group) { $metadata->addAttributeGroup($attribute, $group); } } } } return true; } return false; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { $this->classes = array(); $xml = $this->parseFile($this->file); foreach ($xml->class as $class) { $this->classes[(string) $class['name']] = $class; } } if (isset($this->classes[$metadata->getClassName()])) { $xml = $this->classes[$metadata->getClassName()]; foreach ($xml->attribute as $attribute) { foreach ($attribute->group as $group) { $metadata->addAttributeGroup((string) $attribute['name'], (string) $group); } } return true; } return false; }