Beispiel #1
0
 /**
  * @param \ReflectionClass $class
  * @return object
  */
 private function resolveObject(\ReflectionClass $class)
 {
     if ($class->name === $this->container->getClass()) {
         $argument = $this->container;
     } else {
         $argument = $this->container->resolve($class->name);
     }
     return $argument;
 }
Beispiel #2
0
 /**
  * @param string $name service identifier
  * @param \Janeiro\Di\Container $container
  */
 public function register($name, Container $container)
 {
     $container->set($name, function () use($container, $name) {
         /** @var \Janeiro\Mvc\View $service */
         $service = $container->resolve('\\Janeiro\\Mvc\\View');
         foreach ($container['registry']->get('views') as $class => $suffixes) {
             $service->registerEngine($class, $suffixes);
         }
         return $service;
     });
 }
Beispiel #3
0
 /**
  * Create controller object
  *
  * @param \Janeiro\Request\AbstractRequest $request
  * @throws \Janeiro\Mvc\Exception
  * @return array
  */
 private function getController(AbstractRequest $request)
 {
     if (false === ($target = $this->getControllerClassAndMethod())) {
         throw new Exception('Resource not found', Exception::HTTP_NOT_FOUND);
     }
     list($class, $method) = $target;
     $controllerReflector = $this->container->getFactory($class)->getReflection();
     $methodAnnotation = $controllerReflector->getAnnotation('method', $method, $request->getMethod());
     if (false === in_array($request->getMethod(), explode(',', $methodAnnotation))) {
         throw new Exception(sprintf('%s method not allowed', $request->getMethod()), Exception::HTTP_METHOD_NOT_ALLOWED);
     }
     $this->view->init($class, $method);
     return [$this->container->resolve($class, null), $method];
 }
Beispiel #4
0
 /**
  * @expectedException \Janeiro\Di\Exception
  * @expectedExceptionMessage Could not inject parameter #0 into "\Janeiro\Di\ServiceDummyWithParameters::__construct"
  */
 public function testResolveWithAutoWiringException()
 {
     $this->container->resolve('\\Janeiro\\Di\\ServiceDummyWithParameters');
 }