/** * @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; }
/** * @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; }); }
/** * 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]; }
/** * @expectedException \Janeiro\Di\Exception * @expectedExceptionMessage Could not inject parameter #0 into "\Janeiro\Di\ServiceDummyWithParameters::__construct" */ public function testResolveWithAutoWiringException() { $this->container->resolve('\\Janeiro\\Di\\ServiceDummyWithParameters'); }