@@ -20,22 +20,22 @@ |
||
20 | 20 | * |
21 | 21 | * @param string $post_slug |
22 | 22 | */ |
23 | - public function __construct( $post_slug ) { |
|
23 | + public function __construct($post_slug) { |
|
24 | 24 | $this->post_slug = $post_slug; |
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * {@inheritDoc} |
29 | 29 | */ |
30 | - public function satisfied( Request $request ) { |
|
30 | + public function satisfied(Request $request) { |
|
31 | 31 | $post = get_post(); |
32 | - return ( $post && $this->post_slug === $post->post_name ); |
|
32 | + return ($post && $this->post_slug === $post->post_name); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * {@inheritDoc} |
37 | 37 | */ |
38 | - public function getArguments( Request $request ) { |
|
38 | + public function getArguments(Request $request) { |
|
39 | 39 | return [$this->post_slug]; |
40 | 40 | } |
41 | 41 | } |
@@ -28,24 +28,24 @@ |
||
28 | 28 | * @param string $post_template |
29 | 29 | * @param string|string[] $post_types |
30 | 30 | */ |
31 | - public function __construct( $post_template, $post_types = [] ) { |
|
31 | + public function __construct($post_template, $post_types = []) { |
|
32 | 32 | $this->post_template = $post_template; |
33 | - $this->post_types = is_array( $post_types ) ? $post_types : [$post_types]; |
|
33 | + $this->post_types = is_array($post_types) ? $post_types : [$post_types]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * {@inheritDoc} |
38 | 38 | */ |
39 | - public function satisfied( Request $request ) { |
|
40 | - $template = get_post_meta( get_the_ID(), '_wp_page_template', true ); |
|
39 | + public function satisfied(Request $request) { |
|
40 | + $template = get_post_meta(get_the_ID(), '_wp_page_template', true); |
|
41 | 41 | $template = $template ? $template : 'default'; |
42 | - return ( is_singular( $this->post_types ) && $this->post_template === $template ); |
|
42 | + return (is_singular($this->post_types) && $this->post_template === $template); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * {@inheritDoc} |
47 | 47 | */ |
48 | - public function getArguments( Request $request ) { |
|
48 | + public function getArguments(Request $request) { |
|
49 | 49 | return [$this->post_template, $this->post_types]; |
50 | 50 | } |
51 | 51 | } |
@@ -28,22 +28,22 @@ |
||
28 | 28 | * @param callable $callable |
29 | 29 | * @param mixed ...$arguments |
30 | 30 | */ |
31 | - public function __construct( $callable ) { |
|
31 | + public function __construct($callable) { |
|
32 | 32 | $this->callable = $callable; |
33 | - $this->arguments = array_slice( func_get_args(), 1 ); |
|
33 | + $this->arguments = array_slice(func_get_args(), 1); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * {@inheritDoc} |
38 | 38 | */ |
39 | - public function satisfied( Request $request ) { |
|
40 | - return call_user_func_array( $this->callable, $this->arguments ); |
|
39 | + public function satisfied(Request $request) { |
|
40 | + return call_user_func_array($this->callable, $this->arguments); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
44 | 44 | * {@inheritDoc} |
45 | 45 | */ |
46 | - public function getArguments( Request $request ) { |
|
46 | + public function getArguments(Request $request) { |
|
47 | 47 | return $this->arguments; |
48 | 48 | } |
49 | 49 | } |
@@ -20,21 +20,21 @@ |
||
20 | 20 | * |
21 | 21 | * @param string $post_id |
22 | 22 | */ |
23 | - public function __construct( $post_id ) { |
|
23 | + public function __construct($post_id) { |
|
24 | 24 | $this->post_id = $post_id; |
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * {@inheritDoc} |
29 | 29 | */ |
30 | - public function satisfied( Request $request ) { |
|
30 | + public function satisfied(Request $request) { |
|
31 | 31 | return $this->post_id === get_the_ID(); |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * {@inheritDoc} |
36 | 36 | */ |
37 | - public function getArguments( Request $request ) { |
|
37 | + public function getArguments(Request $request) { |
|
38 | 38 | return [$this->post_id]; |
39 | 39 | } |
40 | 40 | } |
@@ -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 | |
@@ -117,29 +117,29 @@ discard block |
||
117 | 117 | * @param string $url |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - protected function getValidationRegex( $url ) { |
|
120 | + protected function getValidationRegex($url) { |
|
121 | 121 | $parameters = []; |
122 | 122 | |
123 | 123 | // Replace all parameters with placeholders |
124 | - $validation_regex = preg_replace_callback( $this->url_regex, function( $matches ) use ( &$parameters ) { |
|
124 | + $validation_regex = preg_replace_callback($this->url_regex, function($matches) use (&$parameters) { |
|
125 | 125 | $name = $matches['name']; |
126 | - $optional = ! empty( $matches['optional'] ); |
|
127 | - $regex = ! empty( $matches['regex'] ) ? $matches['regex'] : $this->parameter_regex; |
|
126 | + $optional = ! empty($matches['optional']); |
|
127 | + $regex = ! empty($matches['regex']) ? $matches['regex'] : $this->parameter_regex; |
|
128 | 128 | $replacement = '(?:/(?P<' . $name . '>' . $regex . '))'; |
129 | - if ( $optional ) { |
|
129 | + if ($optional) { |
|
130 | 130 | $replacement .= '?'; |
131 | 131 | } |
132 | 132 | |
133 | - $placeholder = '___placeholder_' . sha1( count( $parameters) . '_' . $replacement . '_' . uniqid() ) . '___'; |
|
134 | - $parameters[ $placeholder ] = $replacement; |
|
133 | + $placeholder = '___placeholder_' . sha1(count($parameters) . '_' . $replacement . '_' . uniqid()) . '___'; |
|
134 | + $parameters[$placeholder] = $replacement; |
|
135 | 135 | return $placeholder; |
136 | - }, $url ); |
|
136 | + }, $url); |
|
137 | 137 | |
138 | 138 | // quote the remaining string so that it does not get evaluated as regex |
139 | - $validation_regex = preg_quote( $validation_regex, '~' ); |
|
139 | + $validation_regex = preg_quote($validation_regex, '~'); |
|
140 | 140 | |
141 | 141 | // replace the placeholders with the real parameter regexes |
142 | - $validation_regex = str_replace( array_keys( $parameters ), array_values( $parameters ), $validation_regex ); |
|
142 | + $validation_regex = str_replace(array_keys($parameters), array_values($parameters), $validation_regex); |
|
143 | 143 | |
144 | 144 | // make sure that the regex matches the entire string |
145 | 145 | $validation_regex = '~\A' . $validation_regex . '\z~'; |
@@ -20,21 +20,21 @@ |
||
20 | 20 | * |
21 | 21 | * @param string $post_type |
22 | 22 | */ |
23 | - public function __construct( $post_type ) { |
|
23 | + public function __construct($post_type) { |
|
24 | 24 | $this->post_type = $post_type; |
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * {@inheritDoc} |
29 | 29 | */ |
30 | - public function satisfied( Request $request ) { |
|
30 | + public function satisfied(Request $request) { |
|
31 | 31 | return $this->post_type === get_post_type(); |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * {@inheritDoc} |
36 | 36 | */ |
37 | - public function getArguments( Request $request ) { |
|
37 | + public function getArguments(Request $request) { |
|
38 | 38 | return [$this->post_type]; |
39 | 39 | } |
40 | 40 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @param Request $request |
15 | 15 | * @return boolean |
16 | 16 | */ |
17 | - public function satisfied( Request $request ); |
|
17 | + public function satisfied(Request $request); |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Return an array of arguments for use in request |
@@ -22,5 +22,5 @@ discard block |
||
22 | 22 | * @param Request $request |
23 | 23 | * @return array |
24 | 24 | */ |
25 | - public function getArguments( Request $request ); |
|
25 | + public function getArguments(Request $request); |
|
26 | 26 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @return null |
21 | 21 | */ |
22 | 22 | public function boot() { |
23 | - add_action( 'template_include', array( $this, 'execute' ), 1000 ); |
|
23 | + add_action('template_include', array($this, 'execute'), 1000); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -29,18 +29,18 @@ discard block |
||
29 | 29 | * @param string $template |
30 | 30 | * @return string |
31 | 31 | */ |
32 | - public function execute( $template ) { |
|
32 | + public function execute($template) { |
|
33 | 33 | $routes = $this->getRoutes(); |
34 | - $global_middleware = Framework::resolve( 'framework.global_middleware' ); |
|
34 | + $global_middleware = Framework::resolve('framework.global_middleware'); |
|
35 | 35 | $request = Request::fromGlobals(); |
36 | 36 | |
37 | - foreach ( $routes as $route ) { |
|
38 | - $route->addMiddleware( $global_middleware ); |
|
37 | + foreach ($routes as $route) { |
|
38 | + $route->addMiddleware($global_middleware); |
|
39 | 39 | } |
40 | 40 | |
41 | - foreach ( $routes as $route ) { |
|
42 | - if ( $route->satisfied( $request ) ) { |
|
43 | - return $this->handle( $request, $route ); |
|
41 | + foreach ($routes as $route) { |
|
42 | + if ($route->satisfied($request)) { |
|
43 | + return $this->handle($request, $route); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
@@ -53,17 +53,17 @@ discard block |
||
53 | 53 | * @param RouteInterface $route |
54 | 54 | * @return string |
55 | 55 | */ |
56 | - protected function handle( Request $request, RouteInterface $route ) { |
|
57 | - $response = $route->handle( $request ); |
|
56 | + protected function handle(Request $request, RouteInterface $route) { |
|
57 | + $response = $route->handle($request); |
|
58 | 58 | |
59 | - if ( ! is_a( $response, ResponseInterface::class ) ) { |
|
60 | - if ( Framework::debugging() ) { |
|
61 | - throw new Exception( 'Response returned by controller is not valid (expectected ' . ResponseInterface::class . '; received ' . gettype( $response ) . ').' ); |
|
59 | + if ( ! is_a($response, ResponseInterface::class)) { |
|
60 | + if (Framework::debugging()) { |
|
61 | + throw new Exception('Response returned by controller is not valid (expectected ' . ResponseInterface::class . '; received ' . gettype($response) . ').'); |
|
62 | 62 | } |
63 | - $response = FrameworkResponse::error( FrameworkResponse::response(), 500 ); |
|
63 | + $response = FrameworkResponse::error(FrameworkResponse::response(), 500); |
|
64 | 64 | } |
65 | 65 | |
66 | - add_filter( 'carbon_framework_response', function() use ( $response ) { |
|
66 | + add_filter('carbon_framework_response', function() use ($response) { |
|
67 | 67 | return $response; |
68 | 68 | } ); |
69 | 69 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @param Request $request |
16 | 16 | * @return boolean |
17 | 17 | */ |
18 | - public function satisfied( Request $request ); |
|
18 | + public function satisfied(Request $request); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Return a response for the given request |
@@ -23,5 +23,5 @@ discard block |
||
23 | 23 | * @param Request $request |
24 | 24 | * @return \Psr\Http\Message\ResponseInterface |
25 | 25 | */ |
26 | - public function handle( Request $request ); |
|
26 | + public function handle(Request $request); |
|
27 | 27 | } |