Exemplo n.º 1
0
 function it_shares_an_instance_of_the_default_logger_in_the_container()
 {
     $channelManager = $this->createChannelManager();
     expect($this->container->has(LoggerInterface::class))->shouldBe(false);
     $this->initialize($this->container, $channelManager);
     expect($this->container->has(LoggerInterface::class))->shouldBe(true);
     expect($this->container->has(Logger::class))->shouldBe(true);
     $logger = $this->container->get(LoggerInterface::class);
     $defaultLogger = $channelManager->getLogger();
     expect($logger)->shouldBe($defaultLogger);
 }
 /**
  * @param IRoute $route
  * @param IContainer $container
  *
  * @return mixed
  */
 public function invoke(IRoute $route, IContainer $container)
 {
     list($controller, $method) = $this->extractControllerAndMethod($route->getAction());
     $this->ensureClassExists($controller);
     $instance = $container->get($controller);
     $this->ensureMethodExists($instance, $method);
     return $container->callMethod($instance, $method, $route->getParameters());
 }
 /**
  * @param $class
  *
  * @return mixed
  */
 protected function createSubscriber($class)
 {
     return $this->container->get($class);
 }
 /**
  * @param $providerClass
  * @param IDictionary $shared
  *
  * @return mixed
  */
 public function create($providerClass, IDictionary $shared)
 {
     $provider = $this->container->get($providerClass, ['shared' => $shared]);
     $this->container->set($providerClass, $provider);
     return $provider;
 }
 /**
  * @param $class
  *
  * @return mixed
  */
 protected function createHandler($class)
 {
     return $this->container->get($class);
 }
Exemplo n.º 6
0
 /**
  * @param IContainer $container
  * @param ReflectionParameter $parameter
  *
  * @return mixed
  * @throws Exception
  * @throws ValueNotFoundException
  */
 protected function getParameterFromContainer(IContainer $container, ReflectionParameter $parameter)
 {
     try {
         return $container->get($parameter->getClass()->getName());
     } catch (Exception $ex) {
         $ignoreException = $ex instanceof ValueNotFoundException || $ex instanceof ImplementationNotFoundException;
         if (!($ignoreException && $parameter->isDefaultValueAvailable())) {
             throw $ex;
         }
     }
 }