/** * @param PropertyInjection $propertyInjection */ public function addPropertyInjection(PropertyInjection $propertyInjection) { $this->propertyInjections[$propertyInjection->getPropertyName()] = $propertyInjection; }
/** * Inject dependencies into properties. * * @param object $object Object to inject dependencies into * @param PropertyInjection $propertyInjection Property injection definition * * @throws DependencyException * @throws DefinitionException */ private function injectProperty($object, PropertyInjection $propertyInjection) { $propertyName = $propertyInjection->getPropertyName(); $className = $propertyInjection->getClassName(); $className = $className ?: get_class($object); $property = new ReflectionProperty($className, $propertyName); $value = $propertyInjection->getValue(); if ($value instanceof DefinitionHelper) { /** @var Definition $nestedDefinition */ $nestedDefinition = $value->getDefinition(''); try { $value = $this->definitionResolver->resolve($nestedDefinition); } catch (DependencyException $e) { throw $e; } catch (Exception $e) { throw new DependencyException(sprintf("Error while injecting in %s::%s. %s", get_class($object), $propertyName, $e->getMessage()), 0, $e); } } if (!$property->isPublic()) { $property->setAccessible(true); } $property->setValue($object, $value); }
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; }