DI\Definition\ObjectDefinition::addPropertyInjection PHP Method

addPropertyInjection() public method

public addPropertyInjection ( DI\Definition\ObjectDefinition\PropertyInjection $propertyInjection )
$propertyInjection DI\Definition\ObjectDefinition\PropertyInjection
    public function addPropertyInjection(PropertyInjection $propertyInjection)
    {
        $className = $propertyInjection->getClassName();
        if ($className) {
            // Index with the class name to avoid collisions between parent and
            // child private properties with the same name
            $key = $className . '::' . $propertyInjection->getPropertyName();
        } else {
            $key = $propertyInjection->getPropertyName();
        }
        $this->propertyInjections[$key] = $propertyInjection;
    }

Usage Example

示例#1
0
 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));
 }
All Usage Examples Of DI\Definition\ObjectDefinition::addPropertyInjection