예제 #1
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];
 }
예제 #2
0
 /**
  * Whether request method is allowed for given route
  *
  * @param AbstractRequest $request
  * @param array $route
  * @return bool
  */
 private function isAllowed(AbstractRequest $request, array $route)
 {
     $allowed = true;
     if (isset($route['methods'])) {
         $allowed = in_array($request->getMethod(), (array) $route['methods']);
     }
     return $allowed;
 }