@@ -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 | } |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | * @param string|ConditionInterface $target |
32 | 32 | * @param Closure $callable |
33 | 33 | */ |
34 | - public function __construct( $target, Closure $callable ) { |
|
35 | - if ( is_string( $target ) ) { |
|
36 | - $target = new UrlCondition( $target ); |
|
34 | + public function __construct($target, Closure $callable) { |
|
35 | + if (is_string($target)) { |
|
36 | + $target = new UrlCondition($target); |
|
37 | 37 | } |
38 | 38 | |
39 | - if ( ! is_a( $target, UrlCondition::class ) ) { |
|
40 | - throw new Exception( 'Route groups can only use route strings.' ); |
|
39 | + if ( ! is_a($target, UrlCondition::class)) { |
|
40 | + throw new Exception('Route groups can only use route strings.'); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | $this->target = $target; |
44 | 44 | |
45 | - $callable( $this ); |
|
45 | + $callable($this); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return RouteInterface|null |
52 | 52 | */ |
53 | - protected function getSatisfiedRoute( Request $request ) { |
|
53 | + protected function getSatisfiedRoute(Request $request) { |
|
54 | 54 | $routes = $this->getRoutes(); |
55 | - foreach ( $routes as $route ) { |
|
56 | - if ( $route->satisfied( $request ) ) { |
|
55 | + foreach ($routes as $route) { |
|
56 | + if ($route->satisfied($request)) { |
|
57 | 57 | return $route; |
58 | 58 | } |
59 | 59 | } |
@@ -63,45 +63,45 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * {@inheritDoc} |
65 | 65 | */ |
66 | - public function satisfied( Request $request ) { |
|
67 | - $route = $this->getSatisfiedRoute( $request ); |
|
66 | + public function satisfied(Request $request) { |
|
67 | + $route = $this->getSatisfiedRoute($request); |
|
68 | 68 | return $route !== null; |
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
72 | 72 | * {@inheritDoc} |
73 | 73 | */ |
74 | - public function handle( Request $request ) { |
|
75 | - $route = $this->getSatisfiedRoute( $request ); |
|
76 | - return $route ? $route->handle( $request ) : null; |
|
74 | + public function handle(Request $request) { |
|
75 | + $route = $this->getSatisfiedRoute($request); |
|
76 | + return $route ? $route->handle($request) : null; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * {@inheritDoc} |
81 | 81 | */ |
82 | - public function route( $methods, $target, $handler ) { |
|
83 | - if ( is_string( $target ) ) { |
|
84 | - $target = new UrlCondition( $target ); |
|
82 | + public function route($methods, $target, $handler) { |
|
83 | + if (is_string($target)) { |
|
84 | + $target = new UrlCondition($target); |
|
85 | 85 | } |
86 | 86 | |
87 | - if ( ! is_a( $target, UrlCondition::class ) ) { |
|
88 | - throw new Exception( 'Routes inside route groups can only use route strings.' ); |
|
87 | + if ( ! is_a($target, UrlCondition::class)) { |
|
88 | + throw new Exception('Routes inside route groups can only use route strings.'); |
|
89 | 89 | } |
90 | 90 | |
91 | - $target = $this->target->concatenate( $target ); |
|
92 | - return $this->traitRoute( $methods, $target, $handler ); |
|
91 | + $target = $this->target->concatenate($target); |
|
92 | + return $this->traitRoute($methods, $target, $handler); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
96 | 96 | * {@inheritDoc} |
97 | 97 | */ |
98 | - public function addMiddleware( $middleware ) { |
|
98 | + public function addMiddleware($middleware) { |
|
99 | 99 | $routes = $this->getRoutes(); |
100 | 100 | |
101 | - foreach ( $routes as $route ) { |
|
102 | - $route->addMiddleware( $middleware ); |
|
101 | + foreach ($routes as $route) { |
|
102 | + $route->addMiddleware($middleware); |
|
103 | 103 | } |
104 | 104 | |
105 | - return $this->traitAddMiddleware( $middleware ); |
|
105 | + return $this->traitAddMiddleware($middleware); |
|
106 | 106 | } |
107 | 107 | } |
@@ -45,41 +45,41 @@ 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 | /** |
67 | 67 | * {@inheritDoc} |
68 | 68 | */ |
69 | - public function satisfied( Request $request ) { |
|
70 | - if ( ! in_array( $request->getMethod(), $this->methods) ) { |
|
69 | + public function satisfied(Request $request) { |
|
70 | + if ( ! in_array($request->getMethod(), $this->methods)) { |
|
71 | 71 | return false; |
72 | 72 | } |
73 | - return $this->target->satisfied( $request ); |
|
73 | + return $this->target->satisfied($request); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * {@inheritDoc} |
78 | 78 | */ |
79 | - public function handle( Request $request ) { |
|
80 | - $arguments = array_merge( [$request], $this->target->getArguments( $request ) ); |
|
81 | - return $this->executeMiddleware( $this->getMiddleware(), $request, function() use ( $arguments ) { |
|
82 | - return call_user_func_array( [$this->handler, 'execute'], $arguments ); |
|
79 | + public function handle(Request $request) { |
|
80 | + $arguments = array_merge([$request], $this->target->getArguments($request)); |
|
81 | + return $this->executeMiddleware($this->getMiddleware(), $request, function() use ($arguments) { |
|
82 | + return call_user_func_array([$this->handler, 'execute'], $arguments); |
|
83 | 83 | } ); |
84 | 84 | } |
85 | 85 | |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | * @param array $options |
90 | 90 | * @return ConditionInterface |
91 | 91 | */ |
92 | - public function condition( $options ) { |
|
93 | - if ( count( $options ) === 0 ) { |
|
94 | - throw new Exception( 'No condition type specified.' ); |
|
92 | + public function condition($options) { |
|
93 | + if (count($options) === 0) { |
|
94 | + throw new Exception('No condition type specified.'); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | $condition_type = $options[0]; |
98 | - $arguments = array_slice( $options, 1 ); |
|
98 | + $arguments = array_slice($options, 1); |
|
99 | 99 | |
100 | - $condition_class = Framework::resolve( 'framework.routing.conditions.' . $condition_type ); |
|
101 | - if ( $condition_class === null ) { |
|
102 | - throw new Exception( 'Unknown condition type specified: ' . $condition_type ); |
|
100 | + $condition_class = Framework::resolve('framework.routing.conditions.' . $condition_type); |
|
101 | + if ($condition_class === null) { |
|
102 | + throw new Exception('Unknown condition type specified: ' . $condition_type); |
|
103 | 103 | } |
104 | 104 | |
105 | - $reflection = new ReflectionClass( $condition_class ); |
|
106 | - $condition = $reflection->newInstanceArgs( $arguments ); |
|
105 | + $reflection = new ReflectionClass($condition_class); |
|
106 | + $condition = $reflection->newInstanceArgs($arguments); |
|
107 | 107 | return $condition; |
108 | 108 | } |
109 | 109 | } |
@@ -13,10 +13,10 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @return string |
15 | 15 | */ |
16 | - public static function getCurrentPath( Request $request ) { |
|
16 | + public static function getCurrentPath(Request $request) { |
|
17 | 17 | $url = $request->getUrl(); |
18 | - $relative_url = substr( $url, strlen( home_url( '/' ) ) ); |
|
19 | - return static::addTrailingSlash( static::addLeadingSlash( $relative_url ) ); |
|
18 | + $relative_url = substr($url, strlen(home_url('/'))); |
|
19 | + return static::addTrailingSlash(static::addLeadingSlash($relative_url)); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | * @param string $url |
26 | 26 | * @return string |
27 | 27 | */ |
28 | - public static function addLeadingSlash( $url ) { |
|
29 | - return '/' . static::removeLeadingSlash( $url ); |
|
28 | + public static function addLeadingSlash($url) { |
|
29 | + return '/' . static::removeLeadingSlash($url); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * @param string $url |
36 | 36 | * @return string |
37 | 37 | */ |
38 | - public static function removeLeadingSlash( $url ) { |
|
39 | - return preg_replace( '/^\/+/', '', $url ); |
|
38 | + public static function removeLeadingSlash($url) { |
|
39 | + return preg_replace('/^\/+/', '', $url); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @param string $url |
46 | 46 | * @return string |
47 | 47 | */ |
48 | - public static function addTrailingSlash( $url ) { |
|
49 | - return trailingslashit( $url ); |
|
48 | + public static function addTrailingSlash($url) { |
|
49 | + return trailingslashit($url); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param string $url |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - public static function removeTrailingSlash( $url ) { |
|
59 | - return untrailingslashit( $url ); |
|
58 | + public static function removeTrailingSlash($url) { |
|
59 | + return untrailingslashit($url); |
|
60 | 60 | } |
61 | 61 | } |
@@ -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 | public 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 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * @param ResponseInterface $response |
200 | 200 | * @return null |
201 | 201 | */ |
202 | - public static function respond( ResponseInterface $response ) { |
|
203 | - Response::respond( $response ); |
|
202 | + public static function respond(ResponseInterface $response) { |
|
203 | + Response::respond($response); |
|
204 | 204 | } |
205 | 205 | } |