Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getPropertyValue(\ReflectionProperty $property)
 {
     // Check if an injection key is available for this property.
     $key = $this->injectionPolicy->getPropertyKey($property);
     if ($key !== null) {
         return $this->container->get($key);
     }
     // Try to resolve the property by type.
     $className = $this->reflectionTools->getPropertyClass($property);
     if ($className !== null) {
         if ($this->container->has($className)) {
             return $this->container->get($className);
         }
     }
     return $this->defaultValueResolver->getPropertyValue($property);
 }
Exemplo n.º 2
0
 /**
  * @param \ReflectionClass $class
  * @param object           $object
  *
  * @return void
  */
 private function injectProperties(\ReflectionClass $class, $object)
 {
     foreach ($this->reflectionTools->getClassProperties($class) as $property) {
         if ($this->policy->isPropertyInjected($property)) {
             $value = $this->resolver->getPropertyValue($property);
             $property->setAccessible(true);
             $property->setValue($object, $value);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * @param string $key
  *
  * @return bool
  */
 public function has(string $key)
 {
     if (!isset($this->items[$key])) {
         if (class_exists($key)) {
             $class = new \ReflectionClass($key);
             $classes = $this->reflectionTools->getClassHierarchy($class);
             foreach ($classes as $class) {
                 if ($this->injectionPolicy->isClassInjected($class)) {
                     $this->bind($key);
                     // @todo allow to configure scope (singleton) with annotations
                     break;
                 }
             }
         }
     }
     return isset($this->items[$key]);
 }