29 public static function addRoute($path, $controller, $action =
'index', $methods =
null, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
30 self::
addRouteToRoutes ( self::$routes, $path, $controller, $action, $methods, $name, $cache, $duration, $requirements, $priority );
33 public static function addRouteToRoutes(&$routesArray, $path, $controller, $action =
'index', $methods =
null, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0, $callback =
null): void {
34 if (\class_exists ( $controller )) {
35 $method = new \ReflectionMethod ( $controller, $action );
36 $path = ControllerParser::parseMethodPath ( $method, $path );
37 self::_addRoute ( $method, $routesArray, $path, $controller, $action, $methods, $name, $cache, $duration, $requirements, $priority, $callback );
41 private static function _addRoute(\ReflectionMethod $method, &$routesArray, $path, $controller, $action =
'index', $methods =
null, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0, $callback =
null): void {
43 ControllerParser::parseRouteArray ( $result, $controller, [
'path' => $path,
'methods' => $methods,
'name' => $name,
'cache' => $cache,
'duration' => $duration,
'requirements' => $requirements,
'priority' => $priority,
'callback' => $callback ], $method, $action );
45 foreach ( $result as $k => $v ) {
46 $routesArray [$k] = $v;
49 $count = \count ( $routesArray );
51 foreach ( $routesArray as $k => $v ) {
52 if ($priority < $count --) {
58 $routesArray = \array_diff_key ( $routesArray, $newArray );
59 foreach ( $result as $k => $v ) {
62 foreach ( $routesArray as $k => $v ) {
65 $routesArray = $newArray;
69 public static function addCallableRoute($path, $callable, $methods =
null, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
70 if ($callable instanceof \Closure) {
71 $reflectionFunction = new \ReflectionFunction ( $callable );
72 $path = ControllerParser::parseMethodPath ( $reflectionFunction, $path );
73 self::_addCallableRoute ( $reflectionFunction, self::$routes, $path, $callable, $methods, $name, $cache, $duration, $requirements, $priority );
77 public static function get($path, $callable, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
78 self::addCallableRoute ( $path, $callable, [
'get' ], $name, $cache, $duration, $requirements, $priority );
81 public static function post($path, $callable, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
82 self::addCallableRoute ( $path, $callable, [
'post' ], $name, $cache, $duration, $requirements, $priority );
85 public static function delete($path, $callable, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
86 self::addCallableRoute ( $path, $callable, [
'delete' ], $name, $cache, $duration, $requirements, $priority );
89 public static function put($path, $callable, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
90 self::addCallableRoute ( $path, $callable, [
'put' ], $name, $cache, $duration, $requirements, $priority );
93 public static function patch($path, $callable, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
94 self::addCallableRoute ( $path, $callable, [
'patch' ], $name, $cache, $duration, $requirements, $priority );
97 public static function options($path, $callable, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
98 self::addCallableRoute ( $path, $callable, [
'options' ], $name, $cache, $duration, $requirements, $priority );
101 private static function _addCallableRoute(\ReflectionFunction $reflectionFunction, &$routesArray, $path, $callable, $methods =
null, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
103 CallableParser::parseRouteArray ( $result, $callable, [
'path' => $path,
'methods' => $methods,
'name' => $name,
'cache' => $cache,
'duration' => $duration,
'requirements' => $requirements,
'priority' => $priority ], $reflectionFunction );
104 foreach ( $result as $k => $v ) {
105 $routesArray [$k] = $v;
109 public static function addRoutesToRoutes(&$routesArray, $paths, $controller, $action =
'index', $methods =
null, $name =
'', $cache =
false, $duration =
null, $requirements = [], $priority = 0): void {
110 if (\class_exists ( $controller )) {
111 $method = new \ReflectionMethod ( $controller, $action );
112 foreach ( $paths as $path ) {
113 self::_addRoute ( $method, $routesArray, $path, $controller, $action, $methods, $name, $cache, $duration, $requirements, $priority );
Ubiquity\cache\parser$CallableParser This class is part of Ubiquity.
Scans a controller to detect routes defined by annotations or attributes.
Ubiquity\controllers\traits$RouterModifierTrait This class is part of Ubiquity.
static _addRoute(\ReflectionMethod $method, &$routesArray, $path, $controller, $action='index', $methods=null, $name='', $cache=false, $duration=null, $requirements=[], $priority=0, $callback=null)
static patch($path, $callable, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)
static addRouteToRoutes(&$routesArray, $path, $controller, $action='index', $methods=null, $name='', $cache=false, $duration=null, $requirements=[], $priority=0, $callback=null)
static options($path, $callable, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)
static post($path, $callable, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)
static addRoutesToRoutes(&$routesArray, $paths, $controller, $action='index', $methods=null, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)
static addRoute($path, $controller, $action='index', $methods=null, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)
static _addCallableRoute(\ReflectionFunction $reflectionFunction, &$routesArray, $path, $callable, $methods=null, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)
static addCallableRoute($path, $callable, $methods=null, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)
static put($path, $callable, $name='', $cache=false, $duration=null, $requirements=[], $priority=0)