/** * @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); }
/** * @param string $controller * @throws RouterConfigurationException */ public function configure($controller) { $controllerAnnotations = Annotations::ofClass($controller, Controller::class); if (!count($controllerAnnotations)) { throw new RouterConfigurationException("Controller class {$controller} should be annotated with @controller"); } $controllerPath = $controllerAnnotations[0]->path; if ($controllerPath === null) { throw new RouterConfigurationException("@controller annotation of class {$controller} should have path set. E.g. @controller('path' => '/user')"); } $reflector = new ReflectionClass($controller); $methods = $reflector->getMethods(); foreach ($methods as $method) { $this->configureControllerMethod($method, $controllerPath); } }
protected function testFilterUnresolvedAnnotationClass() { $annotations = Annotations::ofClass('TestBase', false); $this->check($annotations === array(), 'empty annotation list when filtering failed'); }