コード例 #1
0
ファイル: View.php プロジェクト: poliander/janeiro
 /**
  * Set templateDirectory/template from controller action method annotations
  *
  * @param string $class controller class
  * @param string $method action method
  * @param string $view view class name
  */
 public final function init($class, $method, $view = '')
 {
     $reflector = $this->container->getFactory($class)->getReflection();
     $templateDirectory = realpath(dirname($reflector->getFileName()) . '/../View');
     $templateDirectory = $reflector->getAnnotation('templateDirectory', $method, $templateDirectory);
     $this->setView($reflector->getAnnotation('view', $method, $view));
     $this->setTemplate($reflector->getAnnotation('template', $method, ''));
     $this->setTemplateDirectory($templateDirectory);
 }
コード例 #2
0
ファイル: Dispatcher.php プロジェクト: poliander/janeiro
 /**
  * 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];
 }