public addPropertyInjection ( DI\Definition\ObjectDefinition\PropertyInjection $propertyInjection ) | ||
$propertyInjection | DI\Definition\ObjectDefinition\PropertyInjection |
private function readProperty(ReflectionProperty $property, ObjectDefinition $definition, $classname = null) { // Look for @Inject annotation /** @var $annotation Inject */ $annotation = $this->getAnnotationReader()->getPropertyAnnotation($property, 'DI\\Annotation\\Inject'); if ($annotation === null) { return null; } // @Inject("name") or look for @var content $entryName = $annotation->getName() ?: $this->getPhpDocReader()->getPropertyClass($property); if ($entryName === null) { throw new AnnotationException(sprintf('@Inject found on property %s::%s but unable to guess what to inject, use a @var annotation', $property->getDeclaringClass()->getName(), $property->getName())); } $definition->addPropertyInjection(new PropertyInjection($property->getName(), new EntryReference($entryName), $classname)); }
/** * Browse the class properties looking for annotated properties. * * @param ReflectionClass $reflectionClass * @param ObjectDefinition $objectDefinition */ private function readProperties(ReflectionClass $reflectionClass, ObjectDefinition $objectDefinition) { // This will look in all the properties, including those of the parent classes foreach ($reflectionClass->getProperties() as $property) { // Ignore static properties if ($property->isStatic()) { continue; } $propertyInjection = $this->getPropertyInjection($property); if ($propertyInjection) { $objectDefinition->addPropertyInjection($propertyInjection); } } }