Esempio n. 1
0
 /**
  * @param RequestContext $requestContext
  * @param InterceptorStack $stack
  * @return Result
  */
 public function intercept(RequestContext $requestContext, InterceptorStack $stack)
 {
     if ($requestContext->routerOptions->devMode) {
         error_log("### Request {$requestContext->requestUri} > {$requestContext->controllerMethodFullName}");
     }
     return $stack->next();
 }
Esempio n. 2
0
 /**
  * @param RequestContext $requestContext
  * @param InterceptorStack $stack
  * @return Result
  */
 public function intercept(RequestContext $requestContext, InterceptorStack $stack)
 {
     try {
         return $stack->next();
     } catch (Exception $e) {
         error_log("Internal error: {$e}");
         return Results::http('Internal error', 500);
     }
 }
 /**
  * @param RequestContext $requestContext
  * @param InterceptorStack $stack
  * @return Result
  */
 public function intercept(RequestContext $requestContext, InterceptorStack $stack)
 {
     $annotations = Annotations::ofClass($requestContext->controllerMethod->getDeclaringClass(), PublicAccess::class);
     $isPublic = count($annotations) > 0;
     if ($isPublic) {
         return $stack->next();
     }
     if (key_exists('loggedInUser', $_SESSION)) {
         $requestContext->inject('loggedInUser', $_SESSION['loggedInUser']);
         return $stack->next();
     }
     return Results::http('Unauthorized', 401);
 }
Esempio n. 4
0
 /**
  * @param RequestContext $requestContext
  * @param array $pathParams
  * @return Result
  * @throws RouterConfigurationException
  */
 public function process(RequestContext $requestContext, array &$pathParams)
 {
     $reflectionMethod = $requestContext->controllerMethod;
     $invokeControllerMethod = function () use($requestContext, $reflectionMethod, &$pathParams) {
         $controller = $this->instantiateController($reflectionMethod, $requestContext);
         $methodArgs = $this->getMethodArgs($reflectionMethod, $pathParams);
         return $reflectionMethod->invokeArgs($controller, $methodArgs);
     };
     $interceptorStack = new InterceptorStack($this->interceptors, $requestContext, $invokeControllerMethod);
     $result = $interceptorStack->next();
     if ($result === null) {
         return Results::nothing();
     }
     if ($result instanceof Result) {
         return $result;
     }
     throw new RouterConfigurationException("Controller method {$requestContext->controllerMethodFullName} should return an instance of Router\\Result");
 }