Example #1
0
 /**
  * @param Container $container
  * @param string    $key
  * @param bool      $same
  */
 private function assertResult(Container $container, $key, $same)
 {
     $a = $container->get($key);
     $b = $container->get($key);
     $this->assertInstanceOf(DatabaseConnection::class, $a);
     $this->assertInstanceOf(DatabaseConnection::class, $b);
     $same ? $this->assertSame($a, $b) : $this->assertNotSame($a, $b);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function resolve(Container $container)
 {
     $parameters = $container->get($this->usingParameters);
     $parameters = $parameters + $this->withParameters;
     if ($this->target instanceof \Closure) {
         return $container->getInjector()->invoke($this->target, $parameters);
     }
     return $container->getInjector()->instantiate($this->target, $parameters);
 }
Example #3
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);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function resolve(Container $container)
 {
     return $container->get($this->target);
 }
Example #5
0
 /**
  * Creates an application using the given dependency injection container.
  *
  * @param Container $container
  *
  * @return Application
  */
 public static function createWithContainer(Container $container)
 {
     return new Application($container->getValueResolver(), $container->getInjectionPolicy());
 }