Exemplo n.º 1
0
 /**
  * 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();
     $property = new ReflectionProperty(get_class($object), $propertyName);
     $value = $propertyInjection->getValue();
     if ($value instanceof EntryReference) {
         try {
             $value = $this->container->get($value->getName());
         } catch (DependencyException $e) {
             throw $e;
         } catch (Exception $e) {
             throw new DependencyException(sprintf("Error while injecting '%s' in %s::%s. %s", $value->getName(), get_class($object), $propertyName, $e->getMessage()), 0, $e);
         }
     }
     if (!$property->isPublic()) {
         $property->setAccessible(true);
     }
     $property->setValue($object, $value);
 }
Exemplo n.º 2
0
 /**
  * @param PropertyInjection $propertyInjection
  */
 public function addPropertyInjection(PropertyInjection $propertyInjection)
 {
     $this->propertyInjections[$propertyInjection->getPropertyName()] = $propertyInjection;
 }