/** * Loads annotations data present in the class, using a Doctrine * annotation reader * * @param ClassMetadata $metadata */ public function loadClassMetadata(Mapping\ClassMetadataInterface $metadata) { $reflClass = $metadata->getReflectionClass(); //Iterate over properties to get annotations foreach ($reflClass->getProperties() as $property) { $this->readProperty($property, $metadata); } }
/** * {@inheritDoc} */ public function mergeRules(ClassMetadataInterface $metadata) { foreach ($metadata->getFilteredProperties() as $property) { foreach ($metadata->getPropertyRules($property) as $rule) { $this->addPropertyRule($property, clone $rule); } } }
/** * Reads annotations for a selected property in the class * * @param ReflectionProperty $property * @param ClassMetadataInterface $metadata */ private function readProperty(ReflectionProperty $property, ClassMetadataInterface $metadata) { // Skip if this property is not from this class if ($property->getDeclaringClass()->getName() != $metadata->getClassName()) { return; } //Iterate over all annotations foreach ($this->reader->getPropertyAnnotations($property) as $rule) { //Skip is its not a rule if (!$rule instanceof Rules\Rule) { continue; } //Add Rule $metadata->addPropertyRule($property->getName(), $rule); } }
/** * Checks if the object has interfaces and cascades parsing of annotatiosn * to all the interfaces * * @param ClassMetadataInterface $metadata */ protected function loadInterfaceMetadata(ClassMetadataInterface $metadata) { foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) { $metadata->mergeRules($this->getClassMetadata($interface->getName())); } }