@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @return Request |
57 | 57 | */ |
58 | 58 | public static function fromGlobals() { |
59 | - return new static( stripslashes_deep( $_GET ), stripslashes_deep( $_POST ), $_COOKIE, $_FILES, $_SERVER, getallheaders() ); |
|
59 | + return new static(stripslashes_deep($_GET), stripslashes_deep($_POST), $_COOKIE, $_FILES, $_SERVER, getallheaders()); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param array $server |
70 | 70 | * @param array $headers |
71 | 71 | */ |
72 | - public function __construct( $get, $post, $cookie, $files, $server, $headers ) { |
|
72 | + public function __construct($get, $post, $cookie, $files, $server, $headers) { |
|
73 | 73 | $this->get = $get; |
74 | 74 | $this->post = $post; |
75 | 75 | $this->cookie = $cookie; |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | * @return string |
85 | 85 | */ |
86 | 86 | public function getMethod() { |
87 | - $method = (string) Arr::get( $this->server, 'REQUEST_METHOD', 'GET' ); |
|
87 | + $method = (string) Arr::get($this->server, 'REQUEST_METHOD', 'GET'); |
|
88 | 88 | |
89 | - $override = (string) Arr::get( $this->headers, 'X-HTTP-METHOD-OVERRIDE' ); |
|
90 | - if ( $method === 'POST' && $override ) { |
|
89 | + $override = (string) Arr::get($this->headers, 'X-HTTP-METHOD-OVERRIDE'); |
|
90 | + if ($method === 'POST' && $override) { |
|
91 | 91 | $method = $override; |
92 | 92 | } |
93 | 93 | |
94 | - return strtoupper( $method ); |
|
94 | + return strtoupper($method); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | * @return string |
101 | 101 | */ |
102 | 102 | public function getUrl() { |
103 | - $https = Arr::get( $this->server, 'HTTPS' ); |
|
103 | + $https = Arr::get($this->server, 'HTTPS'); |
|
104 | 104 | |
105 | 105 | $protocol = $https ? 'https' : 'http'; |
106 | - $host = (string) Arr::get( $this->server, 'HTTP_HOST', '' ); |
|
107 | - $uri = (string) Arr::get( $this->server, 'REQUEST_URI', '' ); |
|
106 | + $host = (string) Arr::get($this->server, 'HTTP_HOST', ''); |
|
107 | + $uri = (string) Arr::get($this->server, 'REQUEST_URI', ''); |
|
108 | 108 | |
109 | 109 | return $protocol . '://' . $host . $uri; |
110 | 110 | } |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | $args = func_get_args(); |
119 | 119 | $source = $this->{$args[0]}; |
120 | 120 | |
121 | - if ( count( $args ) === 1 ) { |
|
121 | + if (count($args) === 1) { |
|
122 | 122 | return $source; |
123 | 123 | } |
124 | 124 | |
125 | 125 | $args[0] = $source; |
126 | - return call_user_func_array( [Arr::class, 'get'], $args ); |
|
126 | + return call_user_func_array([Arr::class, 'get'], $args); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | * @return mixed |
133 | 133 | */ |
134 | 134 | public function get() { |
135 | - return call_user_func_array( [$this, 'input'], array_merge( ['get'], func_get_args() ) ); |
|
135 | + return call_user_func_array([$this, 'input'], array_merge(['get'], func_get_args())); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | 143 | public function post() { |
144 | - return call_user_func_array( [$this, 'input'], array_merge( ['post'], func_get_args() ) ); |
|
144 | + return call_user_func_array([$this, 'input'], array_merge(['post'], func_get_args())); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return mixed |
151 | 151 | */ |
152 | 152 | public function cookie() { |
153 | - return call_user_func_array( [$this, 'input'], array_merge( ['cookie'], func_get_args() ) ); |
|
153 | + return call_user_func_array([$this, 'input'], array_merge(['cookie'], func_get_args())); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * @return mixed |
160 | 160 | */ |
161 | 161 | public function files() { |
162 | - return call_user_func_array( [$this, 'input'], array_merge( ['files'], func_get_args() ) ); |
|
162 | + return call_user_func_array([$this, 'input'], array_merge(['files'], func_get_args())); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @return mixed |
169 | 169 | */ |
170 | 170 | public function server() { |
171 | - return call_user_func_array( [$this, 'input'], array_merge( ['server'], func_get_args() ) ); |
|
171 | + return call_user_func_array([$this, 'input'], array_merge(['server'], func_get_args())); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -177,6 +177,6 @@ discard block |
||
177 | 177 | * @return mixed |
178 | 178 | */ |
179 | 179 | public function headers() { |
180 | - return call_user_func_array( [$this, 'input'], array_merge( ['headers'], func_get_args() ) ); |
|
180 | + return call_user_func_array([$this, 'input'], array_merge(['headers'], func_get_args())); |
|
181 | 181 | } |
182 | 182 | } |
@@ -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,28 +181,28 @@ 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 ); |
|
188 | - if ( $instance === null ) { |
|
187 | + $instance = static::resolve($class); |
|
188 | + if ($instance === null) { |
|
189 | 189 | try { |
190 | - $reflection = new ReflectionMethod( $class, '__construct' ); |
|
190 | + $reflection = new ReflectionMethod($class, '__construct'); |
|
191 | 191 | |
192 | - if ( ! $reflection->isPublic() ) { |
|
193 | - throw new Exception( $class . '::__construct() is not public.' ); |
|
192 | + if ( ! $reflection->isPublic()) { |
|
193 | + throw new Exception($class . '::__construct() is not public.'); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | $parameters = $reflection->getParameters(); |
197 | 197 | |
198 | - $required_parameters = array_filter( $parameters, function( $parameter ) { |
|
198 | + $required_parameters = array_filter($parameters, function($parameter) { |
|
199 | 199 | return ! $parameter->isOptional(); |
200 | 200 | } ); |
201 | 201 | |
202 | - if ( ! empty( $required_parameters ) ) { |
|
203 | - throw new Exception( $class . '::__construct() has requird parameters but could not be resolved from container. Did you miss to define it into the container?' ); |
|
202 | + if ( ! empty($required_parameters)) { |
|
203 | + throw new Exception($class . '::__construct() has requird parameters but could not be resolved from container. Did you miss to define it into the container?'); |
|
204 | 204 | } |
205 | - } catch ( ReflectionException $e ) { |
|
205 | + } catch (ReflectionException $e) { |
|
206 | 206 | // __constructor is not defined so we are free to create a new instance |
207 | 207 | } |
208 | 208 | |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @param ResponseInterface $response |
219 | 219 | * @return null |
220 | 220 | */ |
221 | - public static function respond( ResponseInterface $response ) { |
|
222 | - Response::respond( $response ); |
|
221 | + public static function respond(ResponseInterface $response) { |
|
222 | + Response::respond($response); |
|
223 | 223 | } |
224 | 224 | } |
@@ -19,35 +19,35 @@ |
||
19 | 19 | /** |
20 | 20 | * @see Response::output() |
21 | 21 | */ |
22 | - protected function output( $output ) { |
|
23 | - return Response::output( $this->response(), $output ); |
|
22 | + protected function output($output) { |
|
23 | + return Response::output($this->response(), $output); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @see Response::template() |
28 | 28 | */ |
29 | - protected function template( $templates, $context = array() ) { |
|
30 | - return Response::template( $this->response(), $templates, $context ); |
|
29 | + protected function template($templates, $context = array()) { |
|
30 | + return Response::template($this->response(), $templates, $context); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @see Response::json() |
35 | 35 | */ |
36 | - protected function json( $data ) { |
|
37 | - return Response::json( $this->response(), $data ); |
|
36 | + protected function json($data) { |
|
37 | + return Response::json($this->response(), $data); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @see Response::redirect() |
42 | 42 | */ |
43 | - protected function redirect( $url, $status = 302 ) { |
|
44 | - return Response::redirect( $this->response(), $url, $status ); |
|
43 | + protected function redirect($url, $status = 302) { |
|
44 | + return Response::redirect($this->response(), $url, $status); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @see Response::error() |
49 | 49 | */ |
50 | - protected function error( $code ) { |
|
51 | - return Response::error( $this->response(), $code ); |
|
50 | + protected function error($code) { |
|
51 | + return Response::error($this->response(), $code); |
|
52 | 52 | } |
53 | 53 | } |
@@ -9,165 +9,165 @@ |
||
9 | 9 | */ |
10 | 10 | class AliasLoader |
11 | 11 | { |
12 | - /** |
|
13 | - * The array of class aliases. |
|
14 | - * |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $aliases; |
|
18 | - |
|
19 | - /** |
|
20 | - * Indicates if a loader has been registered. |
|
21 | - * |
|
22 | - * @var bool |
|
23 | - */ |
|
24 | - protected $registered = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * The singleton instance of the loader. |
|
28 | - * |
|
29 | - * @var \CarbonFramework\Support\AliasLoader |
|
30 | - */ |
|
31 | - protected static $instance; |
|
32 | - |
|
33 | - /** |
|
34 | - * Create a new AliasLoader instance. |
|
35 | - * |
|
36 | - * @param array $aliases |
|
37 | - */ |
|
38 | - private function __construct($aliases) |
|
39 | - { |
|
40 | - $this->aliases = $aliases; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Get or create the singleton alias loader instance. |
|
45 | - * |
|
46 | - * @param array $aliases |
|
47 | - * @return \CarbonFramework\Support\AliasLoader |
|
48 | - */ |
|
49 | - public static function getInstance(array $aliases = []) |
|
50 | - { |
|
51 | - if (is_null(static::$instance)) { |
|
52 | - return static::$instance = new static($aliases); |
|
53 | - } |
|
54 | - |
|
55 | - $aliases = array_merge(static::$instance->getAliases(), $aliases); |
|
56 | - |
|
57 | - static::$instance->setAliases($aliases); |
|
58 | - |
|
59 | - return static::$instance; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Load a class alias if it is registered. |
|
64 | - * |
|
65 | - * @param string $alias |
|
66 | - * @return bool|null |
|
67 | - */ |
|
68 | - public function load($alias) |
|
69 | - { |
|
70 | - if (isset($this->aliases[$alias])) { |
|
71 | - return class_alias($this->aliases[$alias], $alias); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Add an alias to the loader. |
|
77 | - * |
|
78 | - * @param string $class |
|
79 | - * @param string $alias |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function alias($class, $alias) |
|
83 | - { |
|
84 | - $this->aliases[$class] = $alias; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Register the loader on the auto-loader stack. |
|
89 | - * |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - public function register() |
|
93 | - { |
|
94 | - if (! $this->registered) { |
|
95 | - $this->prependToLoaderStack(); |
|
96 | - |
|
97 | - $this->registered = true; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Prepend the load method to the auto-loader stack. |
|
103 | - * |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - protected function prependToLoaderStack() |
|
107 | - { |
|
108 | - spl_autoload_register([$this, 'load'], true, true); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Get the registered aliases. |
|
113 | - * |
|
114 | - * @return array |
|
115 | - */ |
|
116 | - public function getAliases() |
|
117 | - { |
|
118 | - return $this->aliases; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Set the registered aliases. |
|
123 | - * |
|
124 | - * @param array $aliases |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public function setAliases(array $aliases) |
|
128 | - { |
|
129 | - $this->aliases = $aliases; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Indicates if the loader has been registered. |
|
134 | - * |
|
135 | - * @return bool |
|
136 | - */ |
|
137 | - public function isRegistered() |
|
138 | - { |
|
139 | - return $this->registered; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Set the "registered" state of the loader. |
|
144 | - * |
|
145 | - * @param bool $value |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - public function setRegistered($value) |
|
149 | - { |
|
150 | - $this->registered = $value; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Set the value of the singleton alias loader. |
|
155 | - * |
|
156 | - * @param \CarbonFramework\Support\AliasLoader $loader |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public static function setInstance($loader) |
|
160 | - { |
|
161 | - static::$instance = $loader; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Clone method. |
|
166 | - * |
|
167 | - * @return void |
|
168 | - */ |
|
169 | - private function __clone() |
|
170 | - { |
|
171 | - // |
|
172 | - } |
|
12 | + /** |
|
13 | + * The array of class aliases. |
|
14 | + * |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $aliases; |
|
18 | + |
|
19 | + /** |
|
20 | + * Indicates if a loader has been registered. |
|
21 | + * |
|
22 | + * @var bool |
|
23 | + */ |
|
24 | + protected $registered = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * The singleton instance of the loader. |
|
28 | + * |
|
29 | + * @var \CarbonFramework\Support\AliasLoader |
|
30 | + */ |
|
31 | + protected static $instance; |
|
32 | + |
|
33 | + /** |
|
34 | + * Create a new AliasLoader instance. |
|
35 | + * |
|
36 | + * @param array $aliases |
|
37 | + */ |
|
38 | + private function __construct($aliases) |
|
39 | + { |
|
40 | + $this->aliases = $aliases; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Get or create the singleton alias loader instance. |
|
45 | + * |
|
46 | + * @param array $aliases |
|
47 | + * @return \CarbonFramework\Support\AliasLoader |
|
48 | + */ |
|
49 | + public static function getInstance(array $aliases = []) |
|
50 | + { |
|
51 | + if (is_null(static::$instance)) { |
|
52 | + return static::$instance = new static($aliases); |
|
53 | + } |
|
54 | + |
|
55 | + $aliases = array_merge(static::$instance->getAliases(), $aliases); |
|
56 | + |
|
57 | + static::$instance->setAliases($aliases); |
|
58 | + |
|
59 | + return static::$instance; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Load a class alias if it is registered. |
|
64 | + * |
|
65 | + * @param string $alias |
|
66 | + * @return bool|null |
|
67 | + */ |
|
68 | + public function load($alias) |
|
69 | + { |
|
70 | + if (isset($this->aliases[$alias])) { |
|
71 | + return class_alias($this->aliases[$alias], $alias); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Add an alias to the loader. |
|
77 | + * |
|
78 | + * @param string $class |
|
79 | + * @param string $alias |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function alias($class, $alias) |
|
83 | + { |
|
84 | + $this->aliases[$class] = $alias; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Register the loader on the auto-loader stack. |
|
89 | + * |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + public function register() |
|
93 | + { |
|
94 | + if (! $this->registered) { |
|
95 | + $this->prependToLoaderStack(); |
|
96 | + |
|
97 | + $this->registered = true; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Prepend the load method to the auto-loader stack. |
|
103 | + * |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + protected function prependToLoaderStack() |
|
107 | + { |
|
108 | + spl_autoload_register([$this, 'load'], true, true); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Get the registered aliases. |
|
113 | + * |
|
114 | + * @return array |
|
115 | + */ |
|
116 | + public function getAliases() |
|
117 | + { |
|
118 | + return $this->aliases; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Set the registered aliases. |
|
123 | + * |
|
124 | + * @param array $aliases |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public function setAliases(array $aliases) |
|
128 | + { |
|
129 | + $this->aliases = $aliases; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Indicates if the loader has been registered. |
|
134 | + * |
|
135 | + * @return bool |
|
136 | + */ |
|
137 | + public function isRegistered() |
|
138 | + { |
|
139 | + return $this->registered; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Set the "registered" state of the loader. |
|
144 | + * |
|
145 | + * @param bool $value |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + public function setRegistered($value) |
|
149 | + { |
|
150 | + $this->registered = $value; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Set the value of the singleton alias loader. |
|
155 | + * |
|
156 | + * @param \CarbonFramework\Support\AliasLoader $loader |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public static function setInstance($loader) |
|
160 | + { |
|
161 | + static::$instance = $loader; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Clone method. |
|
166 | + * |
|
167 | + * @return void |
|
168 | + */ |
|
169 | + private function __clone() |
|
170 | + { |
|
171 | + // |
|
172 | + } |
|
173 | 173 | } |
@@ -10,495 +10,495 @@ |
||
10 | 10 | */ |
11 | 11 | class Arr |
12 | 12 | { |
13 | - /** |
|
14 | - * Determine whether the given value is array accessible. |
|
15 | - * |
|
16 | - * @param mixed $value |
|
17 | - * @return bool |
|
18 | - */ |
|
19 | - public static function accessible($value) |
|
20 | - { |
|
21 | - return is_array($value) || $value instanceof ArrayAccess; |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
25 | - * Add an element to an array using "dot" notation if it doesn't exist. |
|
26 | - * |
|
27 | - * @param array $array |
|
28 | - * @param string $key |
|
29 | - * @param mixed $value |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public static function add($array, $key, $value) |
|
33 | - { |
|
34 | - if (is_null(static::get($array, $key))) { |
|
35 | - static::set($array, $key, $value); |
|
36 | - } |
|
37 | - |
|
38 | - return $array; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Collapse an array of arrays into a single array. |
|
43 | - * |
|
44 | - * @param array $array |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public static function collapse($array) |
|
48 | - { |
|
49 | - $results = []; |
|
50 | - foreach ($array as $values) { |
|
51 | - if (! is_array($values)) { |
|
52 | - continue; |
|
53 | - } |
|
54 | - $results = array_merge($results, $values); |
|
55 | - } |
|
56 | - return $results; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Divide an array into two arrays. One with keys and the other with values. |
|
61 | - * |
|
62 | - * @param array $array |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public static function divide($array) |
|
66 | - { |
|
67 | - return [array_keys($array), array_values($array)]; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Flatten a multi-dimensional associative array with dots. |
|
72 | - * |
|
73 | - * @param array $array |
|
74 | - * @param string $prepend |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - public static function dot($array, $prepend = '') |
|
78 | - { |
|
79 | - $results = []; |
|
80 | - |
|
81 | - foreach ($array as $key => $value) { |
|
82 | - if (is_array($value) && ! empty($value)) { |
|
83 | - $results = array_merge($results, static::dot($value, $prepend.$key.'.')); |
|
84 | - } else { |
|
85 | - $results[$prepend.$key] = $value; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - return $results; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Get all of the given array except for a specified array of items. |
|
94 | - * |
|
95 | - * @param array $array |
|
96 | - * @param array|string $keys |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public static function except($array, $keys) |
|
100 | - { |
|
101 | - static::forget($array, $keys); |
|
102 | - |
|
103 | - return $array; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Determine if the given key exists in the provided array. |
|
108 | - * |
|
109 | - * @param \ArrayAccess|array $array |
|
110 | - * @param string|int $key |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public static function exists($array, $key) |
|
114 | - { |
|
115 | - if ($array instanceof ArrayAccess) { |
|
116 | - return $array->offsetExists($key); |
|
117 | - } |
|
118 | - |
|
119 | - return array_key_exists($key, $array); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Return the first element in an array passing a given truth test. |
|
124 | - * |
|
125 | - * @param array $array |
|
126 | - * @param callable|null $callback |
|
127 | - * @param mixed $default |
|
128 | - * @return mixed |
|
129 | - */ |
|
130 | - public static function first($array, callable $callback = null, $default = null) |
|
131 | - { |
|
132 | - if (is_null($callback)) { |
|
133 | - if (empty($array)) { |
|
134 | - return $default; |
|
135 | - } |
|
136 | - |
|
137 | - foreach ($array as $item) { |
|
138 | - return $item; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - foreach ($array as $key => $value) { |
|
143 | - if (call_user_func($callback, $value, $key)) { |
|
144 | - return $value; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - return $default; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Return the last element in an array passing a given truth test. |
|
153 | - * |
|
154 | - * @param array $array |
|
155 | - * @param callable|null $callback |
|
156 | - * @param mixed $default |
|
157 | - * @return mixed |
|
158 | - */ |
|
159 | - public static function last($array, callable $callback = null, $default = null) |
|
160 | - { |
|
161 | - if (is_null($callback)) { |
|
162 | - return empty($array) ? $default : end($array); |
|
163 | - } |
|
164 | - |
|
165 | - return static::first(array_reverse($array, true), $callback, $default); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Remove one or many array items from a given array using "dot" notation. |
|
170 | - * |
|
171 | - * @param array $array |
|
172 | - * @param array|string $keys |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public static function forget(&$array, $keys) |
|
176 | - { |
|
177 | - $original = &$array; |
|
178 | - |
|
179 | - $keys = (array) $keys; |
|
180 | - |
|
181 | - if (count($keys) === 0) { |
|
182 | - return; |
|
183 | - } |
|
184 | - |
|
185 | - foreach ($keys as $key) { |
|
186 | - // if the exact key exists in the top-level, remove it |
|
187 | - if (static::exists($array, $key)) { |
|
188 | - unset($array[$key]); |
|
189 | - |
|
190 | - continue; |
|
191 | - } |
|
192 | - |
|
193 | - $parts = explode('.', $key); |
|
194 | - |
|
195 | - // clean up before each pass |
|
196 | - $array = &$original; |
|
197 | - |
|
198 | - while (count($parts) > 1) { |
|
199 | - $part = array_shift($parts); |
|
200 | - |
|
201 | - if (isset($array[$part]) && is_array($array[$part])) { |
|
202 | - $array = &$array[$part]; |
|
203 | - } else { |
|
204 | - continue 2; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - unset($array[array_shift($parts)]); |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Get an item from an array using "dot" notation. |
|
214 | - * |
|
215 | - * @param \ArrayAccess|array $array |
|
216 | - * @param string $key |
|
217 | - * @param mixed $default |
|
218 | - * @return mixed |
|
219 | - */ |
|
220 | - public static function get($array, $key, $default = null) |
|
221 | - { |
|
222 | - if (! static::accessible($array)) { |
|
223 | - return $default; |
|
224 | - } |
|
225 | - |
|
226 | - if (is_null($key)) { |
|
227 | - return $array; |
|
228 | - } |
|
229 | - |
|
230 | - if (static::exists($array, $key)) { |
|
231 | - return $array[$key]; |
|
232 | - } |
|
233 | - |
|
234 | - foreach (explode('.', $key) as $segment) { |
|
235 | - if (static::accessible($array) && static::exists($array, $segment)) { |
|
236 | - $array = $array[$segment]; |
|
237 | - } else { |
|
238 | - return $default; |
|
239 | - } |
|
240 | - } |
|
241 | - |
|
242 | - return $array; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * Check if an item or items exist in an array using "dot" notation. |
|
247 | - * |
|
248 | - * @param \ArrayAccess|array $array |
|
249 | - * @param string|array $keys |
|
250 | - * @return bool |
|
251 | - */ |
|
252 | - public static function has($array, $keys) |
|
253 | - { |
|
254 | - if (is_null($keys)) { |
|
255 | - return false; |
|
256 | - } |
|
257 | - |
|
258 | - $keys = (array) $keys; |
|
259 | - |
|
260 | - if (! $array) { |
|
261 | - return false; |
|
262 | - } |
|
263 | - |
|
264 | - if ($keys === []) { |
|
265 | - return false; |
|
266 | - } |
|
267 | - |
|
268 | - foreach ($keys as $key) { |
|
269 | - $subKeyArray = $array; |
|
270 | - |
|
271 | - if (static::exists($array, $key)) { |
|
272 | - continue; |
|
273 | - } |
|
274 | - |
|
275 | - foreach (explode('.', $key) as $segment) { |
|
276 | - if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) { |
|
277 | - $subKeyArray = $subKeyArray[$segment]; |
|
278 | - } else { |
|
279 | - return false; |
|
280 | - } |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - return true; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Determines if an array is associative. |
|
289 | - * |
|
290 | - * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. |
|
291 | - * |
|
292 | - * @param array $array |
|
293 | - * @return bool |
|
294 | - */ |
|
295 | - public static function isAssoc(array $array) |
|
296 | - { |
|
297 | - $keys = array_keys($array); |
|
298 | - |
|
299 | - return array_keys($keys) !== $keys; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Get a subset of the items from the given array. |
|
304 | - * |
|
305 | - * @param array $array |
|
306 | - * @param array|string $keys |
|
307 | - * @return array |
|
308 | - */ |
|
309 | - public static function only($array, $keys) |
|
310 | - { |
|
311 | - return array_intersect_key($array, array_flip((array) $keys)); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Pluck an array of values from an array. |
|
316 | - * |
|
317 | - * @param array $array |
|
318 | - * @param string|array $value |
|
319 | - * @param string|array|null $key |
|
320 | - * @return array |
|
321 | - */ |
|
322 | - public static function pluck($array, $value, $key = null) |
|
323 | - { |
|
324 | - $results = []; |
|
325 | - |
|
326 | - list($value, $key) = static::explodePluckParameters($value, $key); |
|
327 | - |
|
328 | - foreach ($array as $item) { |
|
329 | - $itemValue = static::data_get($item, $value); |
|
330 | - |
|
331 | - // If the key is "null", we will just append the value to the array and keep |
|
332 | - // looping. Otherwise we will key the array using the value of the key we |
|
333 | - // received from the developer. Then we'll return the final array form. |
|
334 | - if (is_null($key)) { |
|
335 | - $results[] = $itemValue; |
|
336 | - } else { |
|
337 | - $itemKey = static::data_get($item, $key); |
|
338 | - |
|
339 | - $results[$itemKey] = $itemValue; |
|
340 | - } |
|
341 | - } |
|
342 | - |
|
343 | - return $results; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Explode the "value" and "key" arguments passed to "pluck". |
|
348 | - * |
|
349 | - * @param string|array $value |
|
350 | - * @param string|array|null $key |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - protected static function explodePluckParameters($value, $key) |
|
354 | - { |
|
355 | - $value = is_string($value) ? explode('.', $value) : $value; |
|
356 | - |
|
357 | - $key = is_null($key) || is_array($key) ? $key : explode('.', $key); |
|
358 | - |
|
359 | - return [$value, $key]; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Push an item onto the beginning of an array. |
|
364 | - * |
|
365 | - * @param array $array |
|
366 | - * @param mixed $value |
|
367 | - * @param mixed $key |
|
368 | - * @return array |
|
369 | - */ |
|
370 | - public static function prepend($array, $value, $key = null) |
|
371 | - { |
|
372 | - if (is_null($key)) { |
|
373 | - array_unshift($array, $value); |
|
374 | - } else { |
|
375 | - $array = [$key => $value] + $array; |
|
376 | - } |
|
377 | - |
|
378 | - return $array; |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Get a value from the array, and remove it. |
|
383 | - * |
|
384 | - * @param array $array |
|
385 | - * @param string $key |
|
386 | - * @param mixed $default |
|
387 | - * @return mixed |
|
388 | - */ |
|
389 | - public static function pull(&$array, $key, $default = null) |
|
390 | - { |
|
391 | - $value = static::get($array, $key, $default); |
|
392 | - |
|
393 | - static::forget($array, $key); |
|
394 | - |
|
395 | - return $value; |
|
396 | - } |
|
397 | - |
|
398 | - /** |
|
399 | - * Set an array item to a given value using "dot" notation. |
|
400 | - * |
|
401 | - * If no key is given to the method, the entire array will be replaced. |
|
402 | - * |
|
403 | - * @param array $array |
|
404 | - * @param string $key |
|
405 | - * @param mixed $value |
|
406 | - * @return array |
|
407 | - */ |
|
408 | - public static function set(&$array, $key, $value) |
|
409 | - { |
|
410 | - if (is_null($key)) { |
|
411 | - return $array = $value; |
|
412 | - } |
|
413 | - |
|
414 | - $keys = explode('.', $key); |
|
415 | - |
|
416 | - while (count($keys) > 1) { |
|
417 | - $key = array_shift($keys); |
|
418 | - |
|
419 | - // If the key doesn't exist at this depth, we will just create an empty array |
|
420 | - // to hold the next value, allowing us to create the arrays to hold final |
|
421 | - // values at the correct depth. Then we'll keep digging into the array. |
|
422 | - if (! isset($array[$key]) || ! is_array($array[$key])) { |
|
423 | - $array[$key] = []; |
|
424 | - } |
|
425 | - |
|
426 | - $array = &$array[$key]; |
|
427 | - } |
|
428 | - |
|
429 | - $array[array_shift($keys)] = $value; |
|
430 | - |
|
431 | - return $array; |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Shuffle the given array and return the result. |
|
436 | - * |
|
437 | - * @param array $array |
|
438 | - * @return array |
|
439 | - */ |
|
440 | - public static function shuffle($array) |
|
441 | - { |
|
442 | - shuffle($array); |
|
443 | - |
|
444 | - return $array; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Recursively sort an array by keys and values. |
|
449 | - * |
|
450 | - * @param array $array |
|
451 | - * @return array |
|
452 | - */ |
|
453 | - public static function sortRecursive($array) |
|
454 | - { |
|
455 | - foreach ($array as &$value) { |
|
456 | - if (is_array($value)) { |
|
457 | - $value = static::sortRecursive($value); |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - if (static::isAssoc($array)) { |
|
462 | - ksort($array); |
|
463 | - } else { |
|
464 | - sort($array); |
|
465 | - } |
|
466 | - |
|
467 | - return $array; |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Get an item from an array or object using "dot" notation. |
|
472 | - * |
|
473 | - * @param mixed $target |
|
474 | - * @param string|array $key |
|
475 | - * @param mixed $default |
|
476 | - * @return mixed |
|
477 | - */ |
|
478 | - public static function function data_get($target, $key, $default = null) |
|
479 | - { |
|
480 | - if (is_null($key)) { |
|
481 | - return $target; |
|
482 | - } |
|
483 | - $key = is_array($key) ? $key : explode('.', $key); |
|
484 | - while (! is_null($segment = array_shift($key))) { |
|
485 | - if ($segment === '*') { |
|
486 | - if ($target instanceof Collection) { |
|
487 | - $target = $target->all(); |
|
488 | - } elseif (! is_array($target)) { |
|
489 | - return $default; |
|
490 | - } |
|
491 | - $result = static::pluck($target, $key); |
|
492 | - return in_array('*', $key) ? static::collapse($result) : $result; |
|
493 | - } |
|
494 | - if (static::accessible($target) && static::exists($target, $segment)) { |
|
495 | - $target = $target[$segment]; |
|
496 | - } elseif (is_object($target) && isset($target->{$segment})) { |
|
497 | - $target = $target->{$segment}; |
|
498 | - } else { |
|
499 | - return $default; |
|
500 | - } |
|
501 | - } |
|
502 | - return $target; |
|
503 | - } |
|
13 | + /** |
|
14 | + * Determine whether the given value is array accessible. |
|
15 | + * |
|
16 | + * @param mixed $value |
|
17 | + * @return bool |
|
18 | + */ |
|
19 | + public static function accessible($value) |
|
20 | + { |
|
21 | + return is_array($value) || $value instanceof ArrayAccess; |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | + * Add an element to an array using "dot" notation if it doesn't exist. |
|
26 | + * |
|
27 | + * @param array $array |
|
28 | + * @param string $key |
|
29 | + * @param mixed $value |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public static function add($array, $key, $value) |
|
33 | + { |
|
34 | + if (is_null(static::get($array, $key))) { |
|
35 | + static::set($array, $key, $value); |
|
36 | + } |
|
37 | + |
|
38 | + return $array; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Collapse an array of arrays into a single array. |
|
43 | + * |
|
44 | + * @param array $array |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public static function collapse($array) |
|
48 | + { |
|
49 | + $results = []; |
|
50 | + foreach ($array as $values) { |
|
51 | + if (! is_array($values)) { |
|
52 | + continue; |
|
53 | + } |
|
54 | + $results = array_merge($results, $values); |
|
55 | + } |
|
56 | + return $results; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Divide an array into two arrays. One with keys and the other with values. |
|
61 | + * |
|
62 | + * @param array $array |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public static function divide($array) |
|
66 | + { |
|
67 | + return [array_keys($array), array_values($array)]; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Flatten a multi-dimensional associative array with dots. |
|
72 | + * |
|
73 | + * @param array $array |
|
74 | + * @param string $prepend |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + public static function dot($array, $prepend = '') |
|
78 | + { |
|
79 | + $results = []; |
|
80 | + |
|
81 | + foreach ($array as $key => $value) { |
|
82 | + if (is_array($value) && ! empty($value)) { |
|
83 | + $results = array_merge($results, static::dot($value, $prepend.$key.'.')); |
|
84 | + } else { |
|
85 | + $results[$prepend.$key] = $value; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + return $results; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Get all of the given array except for a specified array of items. |
|
94 | + * |
|
95 | + * @param array $array |
|
96 | + * @param array|string $keys |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public static function except($array, $keys) |
|
100 | + { |
|
101 | + static::forget($array, $keys); |
|
102 | + |
|
103 | + return $array; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Determine if the given key exists in the provided array. |
|
108 | + * |
|
109 | + * @param \ArrayAccess|array $array |
|
110 | + * @param string|int $key |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public static function exists($array, $key) |
|
114 | + { |
|
115 | + if ($array instanceof ArrayAccess) { |
|
116 | + return $array->offsetExists($key); |
|
117 | + } |
|
118 | + |
|
119 | + return array_key_exists($key, $array); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Return the first element in an array passing a given truth test. |
|
124 | + * |
|
125 | + * @param array $array |
|
126 | + * @param callable|null $callback |
|
127 | + * @param mixed $default |
|
128 | + * @return mixed |
|
129 | + */ |
|
130 | + public static function first($array, callable $callback = null, $default = null) |
|
131 | + { |
|
132 | + if (is_null($callback)) { |
|
133 | + if (empty($array)) { |
|
134 | + return $default; |
|
135 | + } |
|
136 | + |
|
137 | + foreach ($array as $item) { |
|
138 | + return $item; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + foreach ($array as $key => $value) { |
|
143 | + if (call_user_func($callback, $value, $key)) { |
|
144 | + return $value; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + return $default; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Return the last element in an array passing a given truth test. |
|
153 | + * |
|
154 | + * @param array $array |
|
155 | + * @param callable|null $callback |
|
156 | + * @param mixed $default |
|
157 | + * @return mixed |
|
158 | + */ |
|
159 | + public static function last($array, callable $callback = null, $default = null) |
|
160 | + { |
|
161 | + if (is_null($callback)) { |
|
162 | + return empty($array) ? $default : end($array); |
|
163 | + } |
|
164 | + |
|
165 | + return static::first(array_reverse($array, true), $callback, $default); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Remove one or many array items from a given array using "dot" notation. |
|
170 | + * |
|
171 | + * @param array $array |
|
172 | + * @param array|string $keys |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public static function forget(&$array, $keys) |
|
176 | + { |
|
177 | + $original = &$array; |
|
178 | + |
|
179 | + $keys = (array) $keys; |
|
180 | + |
|
181 | + if (count($keys) === 0) { |
|
182 | + return; |
|
183 | + } |
|
184 | + |
|
185 | + foreach ($keys as $key) { |
|
186 | + // if the exact key exists in the top-level, remove it |
|
187 | + if (static::exists($array, $key)) { |
|
188 | + unset($array[$key]); |
|
189 | + |
|
190 | + continue; |
|
191 | + } |
|
192 | + |
|
193 | + $parts = explode('.', $key); |
|
194 | + |
|
195 | + // clean up before each pass |
|
196 | + $array = &$original; |
|
197 | + |
|
198 | + while (count($parts) > 1) { |
|
199 | + $part = array_shift($parts); |
|
200 | + |
|
201 | + if (isset($array[$part]) && is_array($array[$part])) { |
|
202 | + $array = &$array[$part]; |
|
203 | + } else { |
|
204 | + continue 2; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + unset($array[array_shift($parts)]); |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Get an item from an array using "dot" notation. |
|
214 | + * |
|
215 | + * @param \ArrayAccess|array $array |
|
216 | + * @param string $key |
|
217 | + * @param mixed $default |
|
218 | + * @return mixed |
|
219 | + */ |
|
220 | + public static function get($array, $key, $default = null) |
|
221 | + { |
|
222 | + if (! static::accessible($array)) { |
|
223 | + return $default; |
|
224 | + } |
|
225 | + |
|
226 | + if (is_null($key)) { |
|
227 | + return $array; |
|
228 | + } |
|
229 | + |
|
230 | + if (static::exists($array, $key)) { |
|
231 | + return $array[$key]; |
|
232 | + } |
|
233 | + |
|
234 | + foreach (explode('.', $key) as $segment) { |
|
235 | + if (static::accessible($array) && static::exists($array, $segment)) { |
|
236 | + $array = $array[$segment]; |
|
237 | + } else { |
|
238 | + return $default; |
|
239 | + } |
|
240 | + } |
|
241 | + |
|
242 | + return $array; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * Check if an item or items exist in an array using "dot" notation. |
|
247 | + * |
|
248 | + * @param \ArrayAccess|array $array |
|
249 | + * @param string|array $keys |
|
250 | + * @return bool |
|
251 | + */ |
|
252 | + public static function has($array, $keys) |
|
253 | + { |
|
254 | + if (is_null($keys)) { |
|
255 | + return false; |
|
256 | + } |
|
257 | + |
|
258 | + $keys = (array) $keys; |
|
259 | + |
|
260 | + if (! $array) { |
|
261 | + return false; |
|
262 | + } |
|
263 | + |
|
264 | + if ($keys === []) { |
|
265 | + return false; |
|
266 | + } |
|
267 | + |
|
268 | + foreach ($keys as $key) { |
|
269 | + $subKeyArray = $array; |
|
270 | + |
|
271 | + if (static::exists($array, $key)) { |
|
272 | + continue; |
|
273 | + } |
|
274 | + |
|
275 | + foreach (explode('.', $key) as $segment) { |
|
276 | + if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) { |
|
277 | + $subKeyArray = $subKeyArray[$segment]; |
|
278 | + } else { |
|
279 | + return false; |
|
280 | + } |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + return true; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Determines if an array is associative. |
|
289 | + * |
|
290 | + * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. |
|
291 | + * |
|
292 | + * @param array $array |
|
293 | + * @return bool |
|
294 | + */ |
|
295 | + public static function isAssoc(array $array) |
|
296 | + { |
|
297 | + $keys = array_keys($array); |
|
298 | + |
|
299 | + return array_keys($keys) !== $keys; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Get a subset of the items from the given array. |
|
304 | + * |
|
305 | + * @param array $array |
|
306 | + * @param array|string $keys |
|
307 | + * @return array |
|
308 | + */ |
|
309 | + public static function only($array, $keys) |
|
310 | + { |
|
311 | + return array_intersect_key($array, array_flip((array) $keys)); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Pluck an array of values from an array. |
|
316 | + * |
|
317 | + * @param array $array |
|
318 | + * @param string|array $value |
|
319 | + * @param string|array|null $key |
|
320 | + * @return array |
|
321 | + */ |
|
322 | + public static function pluck($array, $value, $key = null) |
|
323 | + { |
|
324 | + $results = []; |
|
325 | + |
|
326 | + list($value, $key) = static::explodePluckParameters($value, $key); |
|
327 | + |
|
328 | + foreach ($array as $item) { |
|
329 | + $itemValue = static::data_get($item, $value); |
|
330 | + |
|
331 | + // If the key is "null", we will just append the value to the array and keep |
|
332 | + // looping. Otherwise we will key the array using the value of the key we |
|
333 | + // received from the developer. Then we'll return the final array form. |
|
334 | + if (is_null($key)) { |
|
335 | + $results[] = $itemValue; |
|
336 | + } else { |
|
337 | + $itemKey = static::data_get($item, $key); |
|
338 | + |
|
339 | + $results[$itemKey] = $itemValue; |
|
340 | + } |
|
341 | + } |
|
342 | + |
|
343 | + return $results; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Explode the "value" and "key" arguments passed to "pluck". |
|
348 | + * |
|
349 | + * @param string|array $value |
|
350 | + * @param string|array|null $key |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + protected static function explodePluckParameters($value, $key) |
|
354 | + { |
|
355 | + $value = is_string($value) ? explode('.', $value) : $value; |
|
356 | + |
|
357 | + $key = is_null($key) || is_array($key) ? $key : explode('.', $key); |
|
358 | + |
|
359 | + return [$value, $key]; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Push an item onto the beginning of an array. |
|
364 | + * |
|
365 | + * @param array $array |
|
366 | + * @param mixed $value |
|
367 | + * @param mixed $key |
|
368 | + * @return array |
|
369 | + */ |
|
370 | + public static function prepend($array, $value, $key = null) |
|
371 | + { |
|
372 | + if (is_null($key)) { |
|
373 | + array_unshift($array, $value); |
|
374 | + } else { |
|
375 | + $array = [$key => $value] + $array; |
|
376 | + } |
|
377 | + |
|
378 | + return $array; |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Get a value from the array, and remove it. |
|
383 | + * |
|
384 | + * @param array $array |
|
385 | + * @param string $key |
|
386 | + * @param mixed $default |
|
387 | + * @return mixed |
|
388 | + */ |
|
389 | + public static function pull(&$array, $key, $default = null) |
|
390 | + { |
|
391 | + $value = static::get($array, $key, $default); |
|
392 | + |
|
393 | + static::forget($array, $key); |
|
394 | + |
|
395 | + return $value; |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | + * Set an array item to a given value using "dot" notation. |
|
400 | + * |
|
401 | + * If no key is given to the method, the entire array will be replaced. |
|
402 | + * |
|
403 | + * @param array $array |
|
404 | + * @param string $key |
|
405 | + * @param mixed $value |
|
406 | + * @return array |
|
407 | + */ |
|
408 | + public static function set(&$array, $key, $value) |
|
409 | + { |
|
410 | + if (is_null($key)) { |
|
411 | + return $array = $value; |
|
412 | + } |
|
413 | + |
|
414 | + $keys = explode('.', $key); |
|
415 | + |
|
416 | + while (count($keys) > 1) { |
|
417 | + $key = array_shift($keys); |
|
418 | + |
|
419 | + // If the key doesn't exist at this depth, we will just create an empty array |
|
420 | + // to hold the next value, allowing us to create the arrays to hold final |
|
421 | + // values at the correct depth. Then we'll keep digging into the array. |
|
422 | + if (! isset($array[$key]) || ! is_array($array[$key])) { |
|
423 | + $array[$key] = []; |
|
424 | + } |
|
425 | + |
|
426 | + $array = &$array[$key]; |
|
427 | + } |
|
428 | + |
|
429 | + $array[array_shift($keys)] = $value; |
|
430 | + |
|
431 | + return $array; |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Shuffle the given array and return the result. |
|
436 | + * |
|
437 | + * @param array $array |
|
438 | + * @return array |
|
439 | + */ |
|
440 | + public static function shuffle($array) |
|
441 | + { |
|
442 | + shuffle($array); |
|
443 | + |
|
444 | + return $array; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Recursively sort an array by keys and values. |
|
449 | + * |
|
450 | + * @param array $array |
|
451 | + * @return array |
|
452 | + */ |
|
453 | + public static function sortRecursive($array) |
|
454 | + { |
|
455 | + foreach ($array as &$value) { |
|
456 | + if (is_array($value)) { |
|
457 | + $value = static::sortRecursive($value); |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + if (static::isAssoc($array)) { |
|
462 | + ksort($array); |
|
463 | + } else { |
|
464 | + sort($array); |
|
465 | + } |
|
466 | + |
|
467 | + return $array; |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Get an item from an array or object using "dot" notation. |
|
472 | + * |
|
473 | + * @param mixed $target |
|
474 | + * @param string|array $key |
|
475 | + * @param mixed $default |
|
476 | + * @return mixed |
|
477 | + */ |
|
478 | + public static function function data_get($target, $key, $default = null) |
|
479 | + { |
|
480 | + if (is_null($key)) { |
|
481 | + return $target; |
|
482 | + } |
|
483 | + $key = is_array($key) ? $key : explode('.', $key); |
|
484 | + while (! is_null($segment = array_shift($key))) { |
|
485 | + if ($segment === '*') { |
|
486 | + if ($target instanceof Collection) { |
|
487 | + $target = $target->all(); |
|
488 | + } elseif (! is_array($target)) { |
|
489 | + return $default; |
|
490 | + } |
|
491 | + $result = static::pluck($target, $key); |
|
492 | + return in_array('*', $key) ? static::collapse($result) : $result; |
|
493 | + } |
|
494 | + if (static::accessible($target) && static::exists($target, $segment)) { |
|
495 | + $target = $target[$segment]; |
|
496 | + } elseif (is_object($target) && isset($target->{$segment})) { |
|
497 | + $target = $target->{$segment}; |
|
498 | + } else { |
|
499 | + return $default; |
|
500 | + } |
|
501 | + } |
|
502 | + return $target; |
|
503 | + } |
|
504 | 504 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | { |
49 | 49 | $results = []; |
50 | 50 | foreach ($array as $values) { |
51 | - if (! is_array($values)) { |
|
51 | + if ( ! is_array($values)) { |
|
52 | 52 | continue; |
53 | 53 | } |
54 | 54 | $results = array_merge($results, $values); |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | |
81 | 81 | foreach ($array as $key => $value) { |
82 | 82 | if (is_array($value) && ! empty($value)) { |
83 | - $results = array_merge($results, static::dot($value, $prepend.$key.'.')); |
|
83 | + $results = array_merge($results, static::dot($value, $prepend . $key . '.')); |
|
84 | 84 | } else { |
85 | - $results[$prepend.$key] = $value; |
|
85 | + $results[$prepend . $key] = $value; |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public static function get($array, $key, $default = null) |
221 | 221 | { |
222 | - if (! static::accessible($array)) { |
|
222 | + if ( ! static::accessible($array)) { |
|
223 | 223 | return $default; |
224 | 224 | } |
225 | 225 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | |
258 | 258 | $keys = (array) $keys; |
259 | 259 | |
260 | - if (! $array) { |
|
260 | + if ( ! $array) { |
|
261 | 261 | return false; |
262 | 262 | } |
263 | 263 | |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | // If the key doesn't exist at this depth, we will just create an empty array |
420 | 420 | // to hold the next value, allowing us to create the arrays to hold final |
421 | 421 | // values at the correct depth. Then we'll keep digging into the array. |
422 | - if (! isset($array[$key]) || ! is_array($array[$key])) { |
|
422 | + if ( ! isset($array[$key]) || ! is_array($array[$key])) { |
|
423 | 423 | $array[$key] = []; |
424 | 424 | } |
425 | 425 | |
@@ -481,11 +481,11 @@ discard block |
||
481 | 481 | return $target; |
482 | 482 | } |
483 | 483 | $key = is_array($key) ? $key : explode('.', $key); |
484 | - while (! is_null($segment = array_shift($key))) { |
|
484 | + while ( ! is_null($segment = array_shift($key))) { |
|
485 | 485 | if ($segment === '*') { |
486 | 486 | if ($target instanceof Collection) { |
487 | 487 | $target = $target->all(); |
488 | - } elseif (! is_array($target)) { |
|
488 | + } elseif ( ! is_array($target)) { |
|
489 | 489 | return $default; |
490 | 490 | } |
491 | 491 | $result = static::pluck($target, $key); |
@@ -44,29 +44,29 @@ discard block |
||
44 | 44 | * @param mixed $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 | } |
@@ -26,16 +26,16 @@ |
||
26 | 26 | * @param callable $callable |
27 | 27 | * @param mixed ...$arguments |
28 | 28 | */ |
29 | - public function __construct( $callable ) { |
|
29 | + public function __construct($callable) { |
|
30 | 30 | $this->callable = $callable; |
31 | - $this->arguments = array_slice( func_get_args(), 1 ); |
|
31 | + $this->arguments = array_slice(func_get_args(), 1); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
35 | 35 | * {@inheritDoc} |
36 | 36 | */ |
37 | 37 | public function satisfied() { |
38 | - return call_user_func_array( $this->callable, $this->arguments ); |
|
38 | + return call_user_func_array($this->callable, $this->arguments); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | * @param mixed $middleware |
24 | 24 | * @return boolean |
25 | 25 | */ |
26 | - protected function isMiddleware( $middleware ) { |
|
27 | - if ( is_callable( $middleware ) ) { |
|
26 | + protected function isMiddleware($middleware) { |
|
27 | + if (is_callable($middleware)) { |
|
28 | 28 | return true; |
29 | 29 | } |
30 | 30 | |
31 | - if ( is_a( $middleware, MiddlewareInterface::class, true ) ) { |
|
31 | + if (is_a($middleware, MiddlewareInterface::class, true)) { |
|
32 | 32 | return true; |
33 | 33 | } |
34 | 34 | |
@@ -50,16 +50,16 @@ discard block |
||
50 | 50 | * @param string|callable|\CarbonFramework\Routing\Middleware\MiddlewareInterface|array $middleware |
51 | 51 | * @return object |
52 | 52 | */ |
53 | - public function addMiddleware( $middleware ) { |
|
54 | - $middleware = is_array( $middleware ) ? $middleware : [$middleware]; |
|
53 | + public function addMiddleware($middleware) { |
|
54 | + $middleware = is_array($middleware) ? $middleware : [$middleware]; |
|
55 | 55 | |
56 | - foreach ( $middleware as $item ) { |
|
57 | - if ( ! $this->isMiddleware( $item ) ) { |
|
58 | - throw new Exception( 'Passed middleware must be a callable or the name of a class which implements the ' . MiddlewareInterface::class . ' interface.' ); |
|
56 | + foreach ($middleware as $item) { |
|
57 | + if ( ! $this->isMiddleware($item)) { |
|
58 | + throw new Exception('Passed middleware must be a callable or the name of a class which implements the ' . MiddlewareInterface::class . ' interface.'); |
|
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - $this->middleware = array_merge( $this->getMiddleware(), $middleware ); |
|
62 | + $this->middleware = array_merge($this->getMiddleware(), $middleware); |
|
63 | 63 | return $this; |
64 | 64 | } |
65 | 65 | |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * @param string|callable|\CarbonFramework\Routing\Middleware\MiddlewareInterface|array $middleware |
70 | 70 | * @return object |
71 | 71 | */ |
72 | - public function add( $middleware ) { |
|
73 | - return $this->addMiddleware( $middleware ); |
|
72 | + public function add($middleware) { |
|
73 | + return $this->addMiddleware($middleware); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -81,22 +81,22 @@ discard block |
||
81 | 81 | * @param Closure $next |
82 | 82 | * @return ResponseInterface |
83 | 83 | */ |
84 | - public function executeMiddleware( $middleware, $request, Closure $next ) { |
|
85 | - $top_middleware = array_pop( $middleware ); |
|
84 | + public function executeMiddleware($middleware, $request, Closure $next) { |
|
85 | + $top_middleware = array_pop($middleware); |
|
86 | 86 | |
87 | - if ( $top_middleware === null ) { |
|
88 | - return $next( $request ); |
|
87 | + if ($top_middleware === null) { |
|
88 | + return $next($request); |
|
89 | 89 | } |
90 | 90 | |
91 | - $top_middleware_next = function( $request ) use ( $middleware, $next ) { |
|
92 | - return $this->executeMiddleware( $middleware, $request, $next ); |
|
91 | + $top_middleware_next = function($request) use ($middleware, $next) { |
|
92 | + return $this->executeMiddleware($middleware, $request, $next); |
|
93 | 93 | }; |
94 | 94 | |
95 | - if ( is_callable( $top_middleware ) ) { |
|
96 | - return call_user_func( $top_middleware, $request, $top_middleware_next ); |
|
95 | + if (is_callable($top_middleware)) { |
|
96 | + return call_user_func($top_middleware, $request, $top_middleware_next); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | $instance = new $top_middleware(); |
100 | - return $instance->handle( $request, $top_middleware_next ); |
|
100 | + return $instance->handle($request, $top_middleware_next); |
|
101 | 101 | } |
102 | 102 | } |
@@ -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|array|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[0] ) ) { |
|
40 | + if (is_string($handler)) { |
|
41 | + $handlerPieces = preg_split('/@|::/', $handler, 2); |
|
42 | + if (count($handlerPieces) === 1) { |
|
43 | + if (is_callable($handlerPieces[0])) { |
|
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 | } |