@@ -3,7 +3,7 @@ |
||
3 | 3 | * Template used to override the loaded template file by WordPress when a route is handled |
4 | 4 | */ |
5 | 5 | use CarbonFramework\Framework; |
6 | -$response = apply_filters( 'carbon_framework_response', null ); |
|
7 | -if ( $response !== null ) { |
|
8 | - Framework::respond( $response ); |
|
6 | +$response = apply_filters('carbon_framework_response', null); |
|
7 | +if ($response !== null) { |
|
8 | + Framework::respond($response); |
|
9 | 9 | } |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | /** |
12 | 12 | * {@inheritDoc} |
13 | 13 | */ |
14 | - public function register( $container ) { |
|
15 | - $container['framework.config'] = array_merge( [ |
|
14 | + public function register($container) { |
|
15 | + $container['framework.config'] = array_merge([ |
|
16 | 16 | 'global_middleware' => [], |
17 | - ], $container['framework.config'] ); |
|
17 | + ], $container['framework.config']); |
|
18 | 18 | |
19 | 19 | $container['framework.routing.global_middleware'] = $container['framework.config']['global_middleware']; |
20 | - $container['framework.routing.global_middleware'] = apply_filters( 'carbon_framework_global_middleware', $container['framework.routing.global_middleware'] ); |
|
20 | + $container['framework.routing.global_middleware'] = apply_filters('carbon_framework_global_middleware', $container['framework.routing.global_middleware']); |
|
21 | 21 | |
22 | 22 | $container['framework.routing.conditions.custom'] = \CarbonFramework\Routing\Conditions\Custom::class; |
23 | 23 | $container['framework.routing.conditions.url'] = \CarbonFramework\Routing\Conditions\Url::class; |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | return new \CarbonFramework\Routing\Router(); |
31 | 31 | }; |
32 | 32 | |
33 | - Framework::facade( 'Router', \CarbonFramework\Facades\Router::class ); |
|
33 | + Framework::facade('Router', \CarbonFramework\Facades\Router::class); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * {@inheritDoc} |
38 | 38 | */ |
39 | - public function boot( $container ) { |
|
39 | + public function boot($container) { |
|
40 | 40 | \Router::boot(); // facade |
41 | 41 | } |
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -12,22 +12,22 @@ |
||
12 | 12 | /** |
13 | 13 | * {@inheritDoc} |
14 | 14 | */ |
15 | - public function register( $container ) { |
|
16 | - $container['framework.routing.global_middleware'] = array_merge( $container['framework.routing.global_middleware'], [ |
|
15 | + public function register($container) { |
|
16 | + $container['framework.routing.global_middleware'] = array_merge($container['framework.routing.global_middleware'], [ |
|
17 | 17 | OldInputMiddleware::class, |
18 | - ] ); |
|
18 | + ]); |
|
19 | 19 | |
20 | 20 | $container['framework.old_input.old_input'] = function() { |
21 | 21 | return new \CarbonFramework\Input\OldInput(); |
22 | 22 | }; |
23 | 23 | |
24 | - Framework::facade( 'OldInput', \CarbonFramework\Facades\OldInput::class ); |
|
24 | + Framework::facade('OldInput', \CarbonFramework\Facades\OldInput::class); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * {@inheritDoc} |
29 | 29 | */ |
30 | - public function boot( $container ) { |
|
30 | + public function boot($container) { |
|
31 | 31 | // nothing to boot |
32 | 32 | } |
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @return boolean |
39 | 39 | */ |
40 | 40 | public static function debugging() { |
41 | - return ( defined( 'WP_DEBUG' ) && WP_DEBUG ); |
|
41 | + return (defined('WP_DEBUG') && WP_DEBUG); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | * @return null |
58 | 58 | */ |
59 | 59 | protected static function verifyBoot() { |
60 | - if ( ! static::isBooted() ) { |
|
61 | - throw new Exception( get_called_class() . ' must be booted first.' ); |
|
60 | + if ( ! static::isBooted()) { |
|
61 | + throw new Exception(get_called_class() . ' must be booted first.'); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return Container |
69 | 69 | */ |
70 | 70 | public static function getContainer() { |
71 | - if ( static::$container === null ) { |
|
71 | + if (static::$container === null) { |
|
72 | 72 | static::$container = new Container(); |
73 | 73 | } |
74 | 74 | return static::$container; |
@@ -82,29 +82,29 @@ discard block |
||
82 | 82 | * @throws Exception |
83 | 83 | * @return null |
84 | 84 | */ |
85 | - public static function boot( $config = [] ) { |
|
86 | - if ( static::isBooted() ) { |
|
87 | - throw new Exception( get_called_class() . ' already booted.' ); |
|
85 | + public static function boot($config = []) { |
|
86 | + if (static::isBooted()) { |
|
87 | + throw new Exception(get_called_class() . ' already booted.'); |
|
88 | 88 | } |
89 | 89 | static::$booted = true; |
90 | 90 | |
91 | 91 | $container = static::getContainer(); |
92 | 92 | |
93 | - $container['framework.config'] = array_merge( [ |
|
93 | + $container['framework.config'] = array_merge([ |
|
94 | 94 | 'providers' => [], |
95 | - ], $config ); |
|
95 | + ], $config); |
|
96 | 96 | |
97 | - $container['framework.service_providers'] = array_merge( [ |
|
97 | + $container['framework.service_providers'] = array_merge([ |
|
98 | 98 | RoutingServiceProvider::class, |
99 | 99 | FlashServiceProvider::class, |
100 | 100 | OldInputServiceProvider::class, |
101 | 101 | TemplatingServiceProvider::class, |
102 | - ], $container['framework.config']['providers'] ); |
|
102 | + ], $container['framework.config']['providers']); |
|
103 | 103 | |
104 | - Facade::setFacadeApplication( $container ); |
|
104 | + Facade::setFacadeApplication($container); |
|
105 | 105 | AliasLoader::getInstance()->register(); |
106 | 106 | |
107 | - static::loadServiceProviders( $container ); |
|
107 | + static::loadServiceProviders($container); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | * @param Container $container |
114 | 114 | * @return null |
115 | 115 | */ |
116 | - protected static function loadServiceProviders( $container ) { |
|
117 | - $container['framework.service_providers'] = apply_filters( 'carbon_framework_service_providers', $container['framework.service_providers'] ); |
|
116 | + protected static function loadServiceProviders($container) { |
|
117 | + $container['framework.service_providers'] = apply_filters('carbon_framework_service_providers', $container['framework.service_providers']); |
|
118 | 118 | |
119 | - $service_providers = array_map( function( $service_provider ) { |
|
119 | + $service_providers = array_map(function($service_provider) { |
|
120 | 120 | return new $service_provider(); |
121 | - }, $container['framework.service_providers'] ); |
|
121 | + }, $container['framework.service_providers']); |
|
122 | 122 | |
123 | - static::registerServiceProviders( $service_providers, $container ); |
|
124 | - static::bootServiceProviders( $service_providers, $container ); |
|
123 | + static::registerServiceProviders($service_providers, $container); |
|
124 | + static::bootServiceProviders($service_providers, $container); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | * @param Container $container |
131 | 131 | * @return null |
132 | 132 | */ |
133 | - protected static function registerServiceProviders( $service_providers, $container ) { |
|
134 | - foreach ( $service_providers as $provider ) { |
|
135 | - $provider->register( $container ); |
|
133 | + protected static function registerServiceProviders($service_providers, $container) { |
|
134 | + foreach ($service_providers as $provider) { |
|
135 | + $provider->register($container); |
|
136 | 136 | } |
137 | 137 | } |
138 | 138 | |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * @param Container $container |
143 | 143 | * @return null |
144 | 144 | */ |
145 | - protected static function bootServiceProviders( $service_providers, $container ) { |
|
146 | - foreach ( $service_providers as $provider ) { |
|
147 | - $provider->boot( $container ); |
|
145 | + protected static function bootServiceProviders($service_providers, $container) { |
|
146 | + foreach ($service_providers as $provider) { |
|
147 | + $provider->boot($container); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @param string $facade_class |
156 | 156 | * @return null |
157 | 157 | */ |
158 | - public static function facade( $alias, $facade_class ) { |
|
159 | - AliasLoader::getInstance()->alias( $alias, $facade_class ); |
|
158 | + public static function facade($alias, $facade_class) { |
|
159 | + AliasLoader::getInstance()->alias($alias, $facade_class); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | * @param string $key |
166 | 166 | * @return mixed|null |
167 | 167 | */ |
168 | - public static function resolve( $key ) { |
|
168 | + public static function resolve($key) { |
|
169 | 169 | static::verifyBoot(); |
170 | 170 | |
171 | - if ( ! isset( static::getContainer()[ $key ] ) ) { |
|
171 | + if ( ! isset(static::getContainer()[$key])) { |
|
172 | 172 | return null; |
173 | 173 | } |
174 | 174 | |
175 | - return static::getContainer()[ $key ]; |
|
175 | + return static::getContainer()[$key]; |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | * @param string $class |
182 | 182 | * @return object |
183 | 183 | */ |
184 | - public static function instantiate( $class ) { |
|
184 | + public static function instantiate($class) { |
|
185 | 185 | static::verifyBoot(); |
186 | 186 | |
187 | - $instance = static::resolve( $class ); |
|
187 | + $instance = static::resolve($class); |
|
188 | 188 | |
189 | - if ( $instance === null ) { |
|
189 | + if ($instance === null) { |
|
190 | 190 | $instance = new $class(); |
191 | 191 | } |
192 | 192 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * @param ResponseInterface $response |
201 | 201 | * @return null |
202 | 202 | */ |
203 | - public static function respond( ResponseInterface $response ) { |
|
204 | - Response::respond( $response ); |
|
203 | + public static function respond(ResponseInterface $response) { |
|
204 | + Response::respond($response); |
|
205 | 205 | } |
206 | 206 | } |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | * @return null |
21 | 21 | */ |
22 | 22 | public function boot() { |
23 | - add_action( 'init', array( $this, 'registerRewriteRules' ), 1000 ); |
|
24 | - add_action( 'template_include', array( $this, 'execute' ), 1000 ); |
|
23 | + add_action('init', array($this, 'registerRewriteRules'), 1000); |
|
24 | + add_action('template_include', array($this, 'execute'), 1000); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | * @return null |
31 | 31 | */ |
32 | 32 | public function registerRewriteRules() { |
33 | - $rules = apply_filters( 'carbon_framework_routing_rewrite_rules', [] ); |
|
34 | - foreach ( $rules as $rule => $rewrite_to ) { |
|
35 | - add_rewrite_rule( $rule, $rewrite_to, 'top' ); |
|
33 | + $rules = apply_filters('carbon_framework_routing_rewrite_rules', []); |
|
34 | + foreach ($rules as $rule => $rewrite_to) { |
|
35 | + add_rewrite_rule($rule, $rewrite_to, 'top'); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | * @param string $template |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function execute( $template ) { |
|
45 | + public function execute($template) { |
|
46 | 46 | $routes = $this->getRoutes(); |
47 | - $global_middleware = Framework::resolve( 'framework.routing.global_middleware' ); |
|
47 | + $global_middleware = Framework::resolve('framework.routing.global_middleware'); |
|
48 | 48 | $request = Request::fromGlobals(); |
49 | 49 | |
50 | - foreach ( $routes as $route ) { |
|
51 | - $route->addMiddleware( $global_middleware ); |
|
50 | + foreach ($routes as $route) { |
|
51 | + $route->addMiddleware($global_middleware); |
|
52 | 52 | } |
53 | 53 | |
54 | - foreach ( $routes as $route ) { |
|
55 | - if ( $route->satisfied( $request ) ) { |
|
56 | - return $this->handle( $request, $route ); |
|
54 | + foreach ($routes as $route) { |
|
55 | + if ($route->satisfied($request)) { |
|
56 | + return $this->handle($request, $route); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | * @param RouteInterface $route |
67 | 67 | * @return string |
68 | 68 | */ |
69 | - protected function handle( Request $request, RouteInterface $route ) { |
|
70 | - $response = $route->handle( $request ); |
|
69 | + protected function handle(Request $request, RouteInterface $route) { |
|
70 | + $response = $route->handle($request); |
|
71 | 71 | |
72 | - if ( ! is_a( $response, ResponseInterface::class ) ) { |
|
73 | - if ( Framework::debugging() ) { |
|
74 | - throw new Exception( 'Response returned by controller is not valid (expectected ' . ResponseInterface::class . '; received ' . gettype( $response ) . ').' ); |
|
72 | + if ( ! is_a($response, ResponseInterface::class)) { |
|
73 | + if (Framework::debugging()) { |
|
74 | + throw new Exception('Response returned by controller is not valid (expectected ' . ResponseInterface::class . '; received ' . gettype($response) . ').'); |
|
75 | 75 | } |
76 | - $response = FrameworkResponse::error( FrameworkResponse::response(), 500 ); |
|
76 | + $response = FrameworkResponse::error(FrameworkResponse::response(), 500); |
|
77 | 77 | } |
78 | 78 | |
79 | - add_filter( 'carbon_framework_response', function() use ( $response ) { |
|
79 | + add_filter('carbon_framework_response', function() use ($response) { |
|
80 | 80 | return $response; |
81 | 81 | } ); |
82 | 82 |
@@ -45,22 +45,22 @@ discard block |
||
45 | 45 | * @param mixed $target |
46 | 46 | * @param string|\Closure $handler |
47 | 47 | */ |
48 | - public function __construct( $methods, $target, $handler ) { |
|
49 | - if ( is_string( $target ) ) { |
|
50 | - $target = new UrlCondition( $target ); |
|
48 | + public function __construct($methods, $target, $handler) { |
|
49 | + if (is_string($target)) { |
|
50 | + $target = new UrlCondition($target); |
|
51 | 51 | } |
52 | 52 | |
53 | - if ( is_array( $target ) ) { |
|
54 | - $target = $this->condition( $target ); |
|
53 | + if (is_array($target)) { |
|
54 | + $target = $this->condition($target); |
|
55 | 55 | } |
56 | 56 | |
57 | - if ( ! is_a( $target, ConditionInterface::class ) ) { |
|
58 | - throw new Exception( 'Route target is not a valid route string or condition.' ); |
|
57 | + if ( ! is_a($target, ConditionInterface::class)) { |
|
58 | + throw new Exception('Route target is not a valid route string or condition.'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | $this->methods = $methods; |
62 | 62 | $this->target = $target; |
63 | - $this->handler = new Handler( $handler ); |
|
63 | + $this->handler = new Handler($handler); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -69,41 +69,41 @@ discard block |
||
69 | 69 | * @param array $options |
70 | 70 | * @return ConditionInterface |
71 | 71 | */ |
72 | - protected function condition( $options ) { |
|
73 | - if ( count( $options ) === 0 ) { |
|
74 | - throw new Exception( 'No condition type specified.' ); |
|
72 | + protected function condition($options) { |
|
73 | + if (count($options) === 0) { |
|
74 | + throw new Exception('No condition type specified.'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | $condition_type = $options[0]; |
78 | - $arguments = array_slice( $options, 1 ); |
|
78 | + $arguments = array_slice($options, 1); |
|
79 | 79 | |
80 | - $condition_class = Framework::resolve( 'framework.routing.conditions.' . $condition_type ); |
|
81 | - if ( $condition_class === null ) { |
|
82 | - throw new Exception( 'Unknown condition type specified: ' . $condition_type ); |
|
80 | + $condition_class = Framework::resolve('framework.routing.conditions.' . $condition_type); |
|
81 | + if ($condition_class === null) { |
|
82 | + throw new Exception('Unknown condition type specified: ' . $condition_type); |
|
83 | 83 | } |
84 | 84 | |
85 | - $reflection = new ReflectionClass( $condition_class ); |
|
86 | - $condition = $reflection->newInstanceArgs( $arguments ); |
|
85 | + $reflection = new ReflectionClass($condition_class); |
|
86 | + $condition = $reflection->newInstanceArgs($arguments); |
|
87 | 87 | return $condition; |
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
91 | 91 | * {@inheritDoc} |
92 | 92 | */ |
93 | - public function satisfied( Request $request ) { |
|
94 | - if ( ! in_array( $request->getMethod(), $this->methods) ) { |
|
93 | + public function satisfied(Request $request) { |
|
94 | + if ( ! in_array($request->getMethod(), $this->methods)) { |
|
95 | 95 | return false; |
96 | 96 | } |
97 | - return $this->target->satisfied( $request ); |
|
97 | + return $this->target->satisfied($request); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | 101 | * {@inheritDoc} |
102 | 102 | */ |
103 | - public function handle( Request $request ) { |
|
104 | - $arguments = array_merge( [$request], $this->target->getArguments( $request ) ); |
|
105 | - return $this->executeMiddleware( $this->getMiddleware(), $request, function() use ( $arguments ) { |
|
106 | - return call_user_func_array( [$this->handler, 'execute'], $arguments ); |
|
103 | + public function handle(Request $request) { |
|
104 | + $arguments = array_merge([$request], $this->target->getArguments($request)); |
|
105 | + return $this->executeMiddleware($this->getMiddleware(), $request, function() use ($arguments) { |
|
106 | + return call_user_func_array([$this->handler, 'execute'], $arguments); |
|
107 | 107 | } ); |
108 | 108 | } |
109 | 109 | |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | * @param string $rewrite_to |
114 | 114 | * @return RouteInterface |
115 | 115 | */ |
116 | - public function rewrite( $rewrite_to ) { |
|
117 | - if ( ! is_a( $this->target, UrlCondition::class ) ) { |
|
118 | - throw new Exception( 'Only routes with url targets can add rewrite rules.' ); |
|
116 | + public function rewrite($rewrite_to) { |
|
117 | + if ( ! is_a($this->target, UrlCondition::class)) { |
|
118 | + throw new Exception('Only routes with url targets can add rewrite rules.'); |
|
119 | 119 | } |
120 | 120 | |
121 | - $regex = $this->target->getValidationRegex( $this->target->getUrl(), false ); |
|
122 | - $regex = preg_replace( '~^\^/~', '^', $regex ); // rewrite rules require NO leading slash |
|
121 | + $regex = $this->target->getValidationRegex($this->target->getUrl(), false); |
|
122 | + $regex = preg_replace('~^\^/~', '^', $regex); // rewrite rules require NO leading slash |
|
123 | 123 | |
124 | - add_filter( 'carbon_framework_routing_rewrite_rules', function( $rules ) use ( $regex, $rewrite_to ) { |
|
125 | - $rules[ $regex ] = $rewrite_to; |
|
124 | + add_filter('carbon_framework_routing_rewrite_rules', function($rules) use ($regex, $rewrite_to) { |
|
125 | + $rules[$regex] = $rewrite_to; |
|
126 | 126 | return $rules; |
127 | 127 | } ); |
128 | 128 |
@@ -43,38 +43,38 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param string $url |
45 | 45 | */ |
46 | - public function __construct( $url ) { |
|
47 | - $url = UrlUtility::addLeadingSlash( $url ); |
|
48 | - $url = UrlUtility::addTrailingSlash( $url ); |
|
46 | + public function __construct($url) { |
|
47 | + $url = UrlUtility::addLeadingSlash($url); |
|
48 | + $url = UrlUtility::addTrailingSlash($url); |
|
49 | 49 | $this->url = $url; |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | 53 | * {@inheritDoc} |
54 | 54 | */ |
55 | - public function satisfied( Request $request ) { |
|
56 | - $validation_regex = $this->getValidationRegex( $this->getUrl() ); |
|
57 | - $url = UrlUtility::getCurrentPath( $request ); |
|
58 | - return (bool) preg_match( $validation_regex, $url ); |
|
55 | + public function satisfied(Request $request) { |
|
56 | + $validation_regex = $this->getValidationRegex($this->getUrl()); |
|
57 | + $url = UrlUtility::getCurrentPath($request); |
|
58 | + return (bool) preg_match($validation_regex, $url); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | 62 | * {@inheritDoc} |
63 | 63 | */ |
64 | - public function getArguments( Request $request ) { |
|
65 | - $validation_regex = $this->getValidationRegex( $this->getUrl() ); |
|
66 | - $url = UrlUtility::getCurrentPath( $request ); |
|
64 | + public function getArguments(Request $request) { |
|
65 | + $validation_regex = $this->getValidationRegex($this->getUrl()); |
|
66 | + $url = UrlUtility::getCurrentPath($request); |
|
67 | 67 | $matches = []; |
68 | - $success = preg_match( $validation_regex, $url, $matches ); |
|
68 | + $success = preg_match($validation_regex, $url, $matches); |
|
69 | 69 | |
70 | - if ( ! $success ) { |
|
70 | + if ( ! $success) { |
|
71 | 71 | return []; // this should not normally happen |
72 | 72 | } |
73 | 73 | |
74 | 74 | $arguments = []; |
75 | - $parameter_names = $this->getParameterNames( $this->getUrl() ); |
|
76 | - foreach ( $parameter_names as $parameter_name ) { |
|
77 | - $arguments[] = ! empty( $matches[ $parameter_name ] ) ? $matches[ $parameter_name ] : ''; |
|
75 | + $parameter_names = $this->getParameterNames($this->getUrl()); |
|
76 | + foreach ($parameter_names as $parameter_name) { |
|
77 | + $arguments[] = ! empty($matches[$parameter_name]) ? $matches[$parameter_name] : ''; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | return $arguments; |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | * @param Url $url |
96 | 96 | * @return Url |
97 | 97 | */ |
98 | - public function concatenate( Url $url ) { |
|
99 | - return new static( UrlUtility::removeTrailingSlash( $this->getUrl() ) . $url->getUrl() ); |
|
98 | + public function concatenate(Url $url) { |
|
99 | + return new static(UrlUtility::removeTrailingSlash($this->getUrl()) . $url->getUrl()); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param string $url |
106 | 106 | * @return string[] |
107 | 107 | */ |
108 | - protected function getParameterNames( $url ) { |
|
108 | + protected function getParameterNames($url) { |
|
109 | 109 | $matches = []; |
110 | - preg_match_all( $this->url_regex, $url, $matches ); |
|
110 | + preg_match_all($this->url_regex, $url, $matches); |
|
111 | 111 | return $matches['name']; |
112 | 112 | } |
113 | 113 | |
@@ -118,29 +118,29 @@ discard block |
||
118 | 118 | * @param boolean $wrap |
119 | 119 | * @return string |
120 | 120 | */ |
121 | - public function getValidationRegex( $url, $wrap = true ) { |
|
121 | + public function getValidationRegex($url, $wrap = true) { |
|
122 | 122 | $parameters = []; |
123 | 123 | |
124 | 124 | // Replace all parameters with placeholders |
125 | - $validation_regex = preg_replace_callback( $this->url_regex, function( $matches ) use ( &$parameters ) { |
|
125 | + $validation_regex = preg_replace_callback($this->url_regex, function($matches) use (&$parameters) { |
|
126 | 126 | $name = $matches['name']; |
127 | - $optional = ! empty( $matches['optional'] ); |
|
128 | - $regex = ! empty( $matches['regex'] ) ? $matches['regex'] : $this->parameter_regex; |
|
127 | + $optional = ! empty($matches['optional']); |
|
128 | + $regex = ! empty($matches['regex']) ? $matches['regex'] : $this->parameter_regex; |
|
129 | 129 | $replacement = '(?P<' . $name . '>' . $regex . ')'; |
130 | - if ( $optional ) { |
|
130 | + if ($optional) { |
|
131 | 131 | $replacement .= '?'; |
132 | 132 | } |
133 | 133 | |
134 | - $placeholder = '___placeholder_' . sha1( count( $parameters) . '_' . $replacement . '_' . uniqid() ) . '___'; |
|
135 | - $parameters[ $placeholder ] = $replacement; |
|
134 | + $placeholder = '___placeholder_' . sha1(count($parameters) . '_' . $replacement . '_' . uniqid()) . '___'; |
|
135 | + $parameters[$placeholder] = $replacement; |
|
136 | 136 | return $placeholder; |
137 | - }, $url ); |
|
137 | + }, $url); |
|
138 | 138 | |
139 | 139 | // quote the remaining string so that it does not get evaluated as regex |
140 | - $validation_regex = preg_quote( $validation_regex, '~' ); |
|
140 | + $validation_regex = preg_quote($validation_regex, '~'); |
|
141 | 141 | |
142 | 142 | // replace the placeholders with the real parameter regexes |
143 | - $validation_regex = str_replace( array_keys( $parameters ), array_values( $parameters ), $validation_regex ); |
|
143 | + $validation_regex = str_replace(array_keys($parameters), array_values($parameters), $validation_regex); |
|
144 | 144 | |
145 | 145 | // add a question mark to the end to make the trailing slash optional |
146 | 146 | $validation_regex = $validation_regex . '?'; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | // make sure the regex matches the beginning of the url |
149 | 149 | $validation_regex = '^' . $validation_regex; |
150 | 150 | |
151 | - if ( $wrap ) { |
|
151 | + if ($wrap) { |
|
152 | 152 | $validation_regex = '~' . $validation_regex . '~'; |
153 | 153 | } |
154 | 154 |