/** * @param object|class $controller * @return string Name of matchig method */ public static function getMatchingMethod($controller) { $reflClass = new ReflectionClass($controller); $classAnnotation = $reflClass->getAnnotation(RequestMapping::class); $requestHelper = Helper::getService(HttpServletRequest::class); $pathInfo = $requestHelper->getServer(HttpServletRequest::PATH_INFO); if (!$pathInfo) { $pathInfo = $requestHelper->getServer(HttpServletRequest::REQUEST_URI); } /* @var $reflMethod ReflectionMethod */ foreach ($reflClass->getMethods(PHP_ReflectionMethod::IS_PUBLIC) as $reflMethod) { /* @var $methodAnnotation RequestMapping */ $methodAnnotation = $reflMethod->getAnnotation(RequestMapping::class); /* @var $requestHelper HttpServletRequest */ $url = ''; if ($classAnnotation) { $url .= $classAnnotation->value; } if ($methodAnnotation) { $url .= $methodAnnotation->value; } $regexp = '/^' . str_replace('/', '\\/', $url) . '/'; $test = preg_match($regexp, $pathInfo, $prop); $test &= $methodAnnotation !== null && self::isMatching($methodAnnotation); if ($url && $methodAnnotation && $test) { foreach ($prop as $key => $value) { if (!is_numeric($key)) { $requestHelper->setParam($key, $value); } } return $reflMethod->getName(); } } return null; }
private function handleUnAuthorizedException($instance, $ex) { $reflClass = new ReflectionClass($instance); $throwFurther = true; foreach ($reflClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { if ($method->hasAnnotation(ExceptionHandler::class)) { $throwFurther &= MethodInvoker::invoke($instance, $method->getName(), array()); } } if ($throwFurther) { throw $ex; } }