1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ubiquity\controllers\traits; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author jcheron <[email protected]> |
7
|
|
|
* @property array $routes |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
trait RouterAdminTrait { |
11
|
|
|
|
12
|
|
|
abstract protected static function slashPath($path); |
13
|
|
|
|
14
|
1 |
|
public static function getRouteInfoByControllerAction($controller, $action) { |
15
|
1 |
|
foreach ( self::$routes as $routePath => $routeDetails ) { |
16
|
1 |
|
if (! isset ( $routeDetails ["controller"] )) { |
17
|
1 |
|
$routeDetails = \current ( $routeDetails ); |
18
|
|
|
} |
19
|
1 |
|
if ($controller === $routeDetails ["controller"] && $action === $routeDetails ["action"]) { |
20
|
|
|
$routeDetails ["path"] = $routePath; |
21
|
|
|
return $routeDetails; |
22
|
|
|
} |
23
|
|
|
} |
24
|
1 |
|
return false; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public static function getRouteInfo($path) { |
28
|
|
|
$path = self::slashPath ( $path ); |
29
|
|
|
foreach ( self::$routes as $routePath => $routeDetails ) { |
30
|
|
|
if (preg_match ( "@^" . $routePath . "$@s", $path, $matches ) || \stripslashes ( $routePath ) == $path) { |
31
|
|
|
if (! isset ( $routeDetails ["controller"] )) { |
32
|
|
|
return \current ( $routeDetails ); |
33
|
|
|
} else |
34
|
|
|
return $routeDetails; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
return false; |
38
|
|
|
} |
39
|
|
|
|
40
|
1 |
|
public static function getAnnotations($controllerName, $actionName) { |
41
|
1 |
|
$result = [ ]; |
42
|
1 |
|
foreach ( self::$routes as $routePath => $routeDetails ) { |
43
|
1 |
|
if (! isset ( $routeDetails ["controller"] )) { |
44
|
1 |
|
$routeDetails = \current ( $routeDetails ); |
45
|
|
|
} |
46
|
1 |
|
if ($routeDetails ["controller"] === $controllerName && $routeDetails ["action"] === $actionName) |
47
|
1 |
|
$result [$routePath] = $routeDetails; |
48
|
|
|
} |
49
|
1 |
|
return $result; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function filterRoutes($path) { |
53
|
|
|
$path = self::slashPath ( $path ); |
54
|
|
|
$result = [ ]; |
55
|
|
|
foreach ( self::$routes as $routePath => $routeDetails ) { |
56
|
|
|
if (preg_match ( "@^" . $routePath . ".*?$@s", $path, $matches )) { |
57
|
|
|
$result [$routePath] = $routeDetails; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
return $result; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|