@@ -26,18 +26,18 @@ |
||
26 | 26 | * @param string $post_template |
27 | 27 | * @param string|string[] $post_types |
28 | 28 | */ |
29 | - public function __construct( $post_template, $post_types = [] ) { |
|
29 | + public function __construct($post_template, $post_types = []) { |
|
30 | 30 | $this->post_template = $post_template; |
31 | - $this->post_types = is_array( $post_types ) ? $post_types : [$post_types]; |
|
31 | + $this->post_types = is_array($post_types) ? $post_types : [$post_types]; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * {@inheritDoc} |
36 | 36 | */ |
37 | 37 | public function satisfied() { |
38 | - $template = get_post_meta( get_the_ID(), '_wp_page_template', true ); |
|
38 | + $template = get_post_meta(get_the_ID(), '_wp_page_template', true); |
|
39 | 39 | $template = $template ? $template : 'default'; |
40 | - return ( is_singular( $this->post_types ) && $this->post_template === $template ); |
|
40 | + return (is_singular($this->post_types) && $this->post_template === $template); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -18,7 +18,7 @@ |
||
18 | 18 | * |
19 | 19 | * @param string $post_type |
20 | 20 | */ |
21 | - public function __construct( $post_type ) { |
|
21 | + public function __construct($post_type) { |
|
22 | 22 | $this->post_type = $post_type; |
23 | 23 | } |
24 | 24 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | * |
19 | 19 | * @param string $post_id |
20 | 20 | */ |
21 | - public function __construct( $post_id ) { |
|
21 | + public function __construct($post_id) { |
|
22 | 22 | $this->post_id = $post_id; |
23 | 23 | } |
24 | 24 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @param string $post_slug |
20 | 20 | */ |
21 | - public function __construct( $post_slug ) { |
|
21 | + public function __construct($post_slug) { |
|
22 | 22 | $this->post_slug = $post_slug; |
23 | 23 | } |
24 | 24 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function satisfied() { |
29 | 29 | $post = get_post(); |
30 | - return ( $post && $this->post_slug === $post->post_name ); |
|
30 | + return ($post && $this->post_slug === $post->post_name); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param string|Closure $handler |
24 | 24 | */ |
25 | - public function __construct( $handler ) { |
|
26 | - $this->set( $handler ); |
|
25 | + public function __construct($handler) { |
|
26 | + $this->set($handler); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -32,15 +32,15 @@ discard block |
||
32 | 32 | * @param string|Closure $handler |
33 | 33 | * @return callable|null |
34 | 34 | */ |
35 | - protected function parse( $handler ) { |
|
36 | - if ( $handler instanceof Closure ) { |
|
35 | + protected function parse($handler) { |
|
36 | + if ($handler instanceof Closure) { |
|
37 | 37 | return $handler; |
38 | 38 | } |
39 | 39 | |
40 | - if ( is_string( $handler ) ) { |
|
41 | - $handlerPieces = preg_split( '/@|::/', $handler, 2 ); |
|
42 | - if ( count( $handlerPieces ) === 1 ) { |
|
43 | - if ( is_callable( $handlerPieces ) ) { |
|
40 | + if (is_string($handler)) { |
|
41 | + $handlerPieces = preg_split('/@|::/', $handler, 2); |
|
42 | + if (count($handlerPieces) === 1) { |
|
43 | + if (is_callable($handlerPieces)) { |
|
44 | 44 | return $handlerPieces[0]; |
45 | 45 | } else { |
46 | 46 | return null; |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | * @param string|Closure $new_handler |
63 | 63 | * @return null |
64 | 64 | */ |
65 | - public function set( $new_handler ) { |
|
66 | - $handler = $this->parse( $new_handler ); |
|
65 | + public function set($new_handler) { |
|
66 | + $handler = $this->parse($new_handler); |
|
67 | 67 | |
68 | - if ( $handler === null ) { |
|
69 | - throw new Exception( 'No or invalid handler provided.' ); |
|
68 | + if ($handler === null) { |
|
69 | + throw new Exception('No or invalid handler provided.'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $this->handler = $handler; |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function execute() { |
81 | 81 | $arguments = func_get_args(); |
82 | - if ( ! is_array( $this->handler ) ) { |
|
83 | - return call_user_func_array( $this->handler, $arguments ); |
|
82 | + if ( ! is_array($this->handler)) { |
|
83 | + return call_user_func_array($this->handler, $arguments); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | $class = $this->handler['class']; |
87 | 87 | $method = $this->handler['method']; |
88 | 88 | |
89 | - $controller = Framework::instantiate( $class ); |
|
90 | - return call_user_func_array( [$controller, $method], $arguments ); |
|
89 | + $controller = Framework::instantiate($class); |
|
90 | + return call_user_func_array([$controller, $method], $arguments); |
|
91 | 91 | } |
92 | 92 | } |
@@ -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,17 +29,17 @@ 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 | |
36 | - foreach ( $routes as $route ) { |
|
37 | - $route->addMiddleware( $global_middleware ); |
|
36 | + foreach ($routes as $route) { |
|
37 | + $route->addMiddleware($global_middleware); |
|
38 | 38 | } |
39 | 39 | |
40 | - foreach ( $routes as $route ) { |
|
41 | - if ( $route->satisfied() ) { |
|
42 | - return $this->handle( $route ); |
|
40 | + foreach ($routes as $route) { |
|
41 | + if ($route->satisfied()) { |
|
42 | + return $this->handle($route); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
@@ -52,18 +52,18 @@ discard block |
||
52 | 52 | * @param RouteInterface $route |
53 | 53 | * @return string |
54 | 54 | */ |
55 | - protected function handle( RouteInterface $route ) { |
|
55 | + protected function handle(RouteInterface $route) { |
|
56 | 56 | $request = Request::fromGlobals(); |
57 | - $response = $route->handle( $request ); |
|
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 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @param RouteInterface $route |
22 | 22 | * @return RouteInterface |
23 | 23 | */ |
24 | - public function addRoute( $route ); |
|
24 | + public function addRoute($route); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Create and add a new route |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param string|Closure $handler |
32 | 32 | * @return RouteInterface |
33 | 33 | */ |
34 | - public function route( $methods, $target, $handler ); |
|
34 | + public function route($methods, $target, $handler); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Create and add a route group |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param Closure $callable |
41 | 41 | * @return RouteInterface |
42 | 42 | */ |
43 | - public function group( $target, Closure $callable ); |
|
43 | + public function group($target, Closure $callable); |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Create and add a route for the GET and HEAD methods |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string|Closure $handler |
50 | 50 | * @return RouteInterface |
51 | 51 | */ |
52 | - public function get( $target, $handler ); |
|
52 | + public function get($target, $handler); |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Create and add a route for the POST method |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param string|Closure $handler |
59 | 59 | * @return RouteInterface |
60 | 60 | */ |
61 | - public function post( $target, $handler ); |
|
61 | + public function post($target, $handler); |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * Create and add a route for the PUT method |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param string|Closure $handler |
68 | 68 | * @return RouteInterface |
69 | 69 | */ |
70 | - public function put( $target, $handler ); |
|
70 | + public function put($target, $handler); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Create and add a route for the PATCH method |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param string|Closure $handler |
77 | 77 | * @return RouteInterface |
78 | 78 | */ |
79 | - public function patch( $target, $handler ); |
|
79 | + public function patch($target, $handler); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Create and add a route for the DELETE method |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string|Closure $handler |
86 | 86 | * @return RouteInterface |
87 | 87 | */ |
88 | - public function delete( $target, $handler ); |
|
88 | + public function delete($target, $handler); |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * Create and add a route for the OPTIONS method |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param string|Closure $handler |
95 | 95 | * @return RouteInterface |
96 | 96 | */ |
97 | - public function options( $target, $handler ); |
|
97 | + public function options($target, $handler); |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Create and add a route for all supported methods |
@@ -103,5 +103,5 @@ discard block |
||
103 | 103 | * @param string|Closure $handler |
104 | 104 | * @return RouteInterface |
105 | 105 | */ |
106 | - public function any( $target, $handler ); |
|
106 | + public function any($target, $handler); |
|
107 | 107 | } |
@@ -44,29 +44,29 @@ discard block |
||
44 | 44 | * @param any $target |
45 | 45 | * @param string|\Closure $handler |
46 | 46 | */ |
47 | - public function __construct( $methods, $target, $handler ) { |
|
48 | - if ( is_string( $target ) ) { |
|
49 | - $target = new UrlCondition( $target ); |
|
47 | + public function __construct($methods, $target, $handler) { |
|
48 | + if (is_string($target)) { |
|
49 | + $target = new UrlCondition($target); |
|
50 | 50 | } |
51 | 51 | |
52 | - if ( is_array( $target ) ) { |
|
53 | - $target = $this->condition( $target ); |
|
52 | + if (is_array($target)) { |
|
53 | + $target = $this->condition($target); |
|
54 | 54 | } |
55 | 55 | |
56 | - if ( ! is_a( $target, ConditionInterface::class ) ) { |
|
57 | - throw new Exception( 'Route target is not a valid route string or condition.' ); |
|
56 | + if ( ! is_a($target, ConditionInterface::class)) { |
|
57 | + throw new Exception('Route target is not a valid route string or condition.'); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->methods = $methods; |
61 | 61 | $this->target = $target; |
62 | - $this->handler = new Handler( $handler ); |
|
62 | + $this->handler = new Handler($handler); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * {@inheritDoc} |
67 | 67 | */ |
68 | 68 | public function satisfied() { |
69 | - if ( ! in_array( $_SERVER['REQUEST_METHOD'], $this->methods) ) { |
|
69 | + if ( ! in_array($_SERVER['REQUEST_METHOD'], $this->methods)) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | 72 | return $this->target->satisfied(); |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | /** |
76 | 76 | * {@inheritDoc} |
77 | 77 | */ |
78 | - public function handle( $request ) { |
|
79 | - $arguments = array_merge( [$request], $this->target->getArguments() ); |
|
80 | - return $this->executeMiddleware( $this->getMiddleware(), $request, function() use ( $arguments ) { |
|
81 | - return call_user_func_array( [$this->handler, 'execute'], $arguments ); |
|
78 | + public function handle($request) { |
|
79 | + $arguments = array_merge([$request], $this->target->getArguments()); |
|
80 | + return $this->executeMiddleware($this->getMiddleware(), $request, function() use ($arguments) { |
|
81 | + return call_user_func_array([$this->handler, 'execute'], $arguments); |
|
82 | 82 | } ); |
83 | 83 | } |
84 | 84 | |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | * @param array $options |
89 | 89 | * @return ConditionInterface |
90 | 90 | */ |
91 | - public function condition( $options ) { |
|
92 | - if ( count( $options ) === 0 ) { |
|
93 | - throw new Exception( 'No condition type specified.' ); |
|
91 | + public function condition($options) { |
|
92 | + if (count($options) === 0) { |
|
93 | + throw new Exception('No condition type specified.'); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $condition_type = $options[0]; |
97 | - $arguments = array_slice( $options, 1 ); |
|
97 | + $arguments = array_slice($options, 1); |
|
98 | 98 | |
99 | - $condition_class = Framework::resolve( 'framework.routing.conditions.' . $condition_type ); |
|
100 | - if ( $condition_class === null ) { |
|
101 | - throw new Exception( 'Unknown condition type specified: ' . $condition_type ); |
|
99 | + $condition_class = Framework::resolve('framework.routing.conditions.' . $condition_type); |
|
100 | + if ($condition_class === null) { |
|
101 | + throw new Exception('Unknown condition type specified: ' . $condition_type); |
|
102 | 102 | } |
103 | 103 | |
104 | - $reflection = new ReflectionClass( $condition_class ); |
|
105 | - $condition = $reflection->newInstanceArgs( $arguments ); |
|
104 | + $reflection = new ReflectionClass($condition_class); |
|
105 | + $condition = $reflection->newInstanceArgs($arguments); |
|
106 | 106 | return $condition; |
107 | 107 | } |
108 | 108 | } |
@@ -30,18 +30,18 @@ discard block |
||
30 | 30 | * @param string|ConditionInterface $target |
31 | 31 | * @param Closure $callable |
32 | 32 | */ |
33 | - public function __construct( $target, Closure $callable ) { |
|
34 | - if ( is_string( $target ) ) { |
|
35 | - $target = new UrlCondition( $target ); |
|
33 | + public function __construct($target, Closure $callable) { |
|
34 | + if (is_string($target)) { |
|
35 | + $target = new UrlCondition($target); |
|
36 | 36 | } |
37 | 37 | |
38 | - if ( ! is_a( $target, UrlCondition::class ) ) { |
|
39 | - throw new Exception( 'Route groups can only use route strings.' ); |
|
38 | + if ( ! is_a($target, UrlCondition::class)) { |
|
39 | + throw new Exception('Route groups can only use route strings.'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | $this->target = $target; |
43 | 43 | |
44 | - $callable( $this ); |
|
44 | + $callable($this); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | */ |
52 | 52 | protected function getSatisfiedRoute() { |
53 | 53 | $routes = $this->getRoutes(); |
54 | - foreach ( $routes as $route ) { |
|
55 | - if ( $route->satisfied() ) { |
|
54 | + foreach ($routes as $route) { |
|
55 | + if ($route->satisfied()) { |
|
56 | 56 | return $route; |
57 | 57 | } |
58 | 58 | } |
@@ -70,37 +70,37 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * {@inheritDoc} |
72 | 72 | */ |
73 | - public function handle( $request ) { |
|
73 | + public function handle($request) { |
|
74 | 74 | $route = $this->getSatisfiedRoute(); |
75 | - return $route ? $route->handle( $request ) : null; |
|
75 | + return $route ? $route->handle($request) : null; |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * {@inheritDoc} |
80 | 80 | */ |
81 | - public function route( $methods, $target, $handler ) { |
|
82 | - if ( is_string( $target ) ) { |
|
83 | - $target = new UrlCondition( $target ); |
|
81 | + public function route($methods, $target, $handler) { |
|
82 | + if (is_string($target)) { |
|
83 | + $target = new UrlCondition($target); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( ! is_a( $target, UrlCondition::class ) ) { |
|
87 | - throw new Exception( 'Routes inside route groups can only use route strings.' ); |
|
86 | + if ( ! is_a($target, UrlCondition::class)) { |
|
87 | + throw new Exception('Routes inside route groups can only use route strings.'); |
|
88 | 88 | } |
89 | 89 | |
90 | - $target = $this->target->concatenate( $target ); |
|
91 | - return $this->traitRoute( $methods, $target, $handler ); |
|
90 | + $target = $this->target->concatenate($target); |
|
91 | + return $this->traitRoute($methods, $target, $handler); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | 95 | * {@inheritDoc} |
96 | 96 | */ |
97 | - public function addMiddleware( $middleware ) { |
|
97 | + public function addMiddleware($middleware) { |
|
98 | 98 | $routes = $this->getRoutes(); |
99 | 99 | |
100 | - foreach ( $routes as $route ) { |
|
101 | - $route->addMiddleware( $middleware ); |
|
100 | + foreach ($routes as $route) { |
|
101 | + $route->addMiddleware($middleware); |
|
102 | 102 | } |
103 | 103 | |
104 | - return $this->traitAddMiddleware( $middleware ); |
|
104 | + return $this->traitAddMiddleware($middleware); |
|
105 | 105 | } |
106 | 106 | } |