Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
RouterTestTrait.php
Go to the documentation of this file.
1<?php
2
4
6
18
19 public static function testRoutes($path, $method = null): array {
20 $response = [ ];
21 if (isset ( $path )) {
22 $path = self::slashPath ( $path );
23 if (isset ( self::$routes [$path] )) {
24 self::addTestRoute ( $response, $path, $method );
25 }
26 }
27 foreach ( self::$routes as $routePath => $routeDetails ) {
28 if (\preg_match ( "@^{$routePath}\$@s", $path ) || $path == null) {
29 self::addTestRoute ( $response, $routePath, $method );
30 }
31 }
32 return $response;
33 }
34
35 private static function addTestRoute(&$response, $path, $method = null): void {
36 if (isset ( $method )) {
37 $restrict = false;
38 if (UString::startswith ( $method, '-' )) {
39 $restrict = true;
40 $method = \ltrim ( $method, '-' );
41 }
42 $routeMethod = self::getMethod ( self::$routes [$path] );
43 if ((\count ( $routeMethod ) == 0 && ! $restrict) || \array_search ( \strtolower ( $method ), $routeMethod ) !== false) {
44 $response [$path] = self::$routes [$path];
45 }
46 } else {
47 $response [$path] = self::$routes [$path];
48 }
49 }
50
51 private static function getMethod($routeDetails): array {
52 if (! isset ( $routeDetails ['controller'] )) {
53 return \array_keys ( $routeDetails );
54 }
55 return [ ];
56 }
57}
58
static addTestRoute(&$response, $path, $method=null)
String utilities.
Definition UString.php:15