@@ -2,6 +2,6 @@ |
||
2 | 2 | /** |
3 | 3 | * Absolute path to framework's directory |
4 | 4 | */ |
5 | -if ( ! defined( 'CARBON_FRAMEWORK_DIR' ) ) { |
|
6 | - define( 'CARBON_FRAMEWORK_DIR', __DIR__ ); |
|
5 | +if ( ! defined('CARBON_FRAMEWORK_DIR')) { |
|
6 | + define('CARBON_FRAMEWORK_DIR', __DIR__); |
|
7 | 7 | } |
@@ -7,8 +7,8 @@ |
||
7 | 7 | */ |
8 | 8 | class OldInput extends Facade |
9 | 9 | { |
10 | - protected static function getFacadeAccessor() |
|
11 | - { |
|
12 | - return 'framework.old_input.old_input'; |
|
13 | - } |
|
10 | + protected static function getFacadeAccessor() |
|
11 | + { |
|
12 | + return 'framework.old_input.old_input'; |
|
13 | + } |
|
14 | 14 | } |
@@ -7,8 +7,8 @@ |
||
7 | 7 | */ |
8 | 8 | class Router extends Facade |
9 | 9 | { |
10 | - protected static function getFacadeAccessor() |
|
11 | - { |
|
12 | - return 'framework.routing.router'; |
|
13 | - } |
|
10 | + protected static function getFacadeAccessor() |
|
11 | + { |
|
12 | + return 'framework.routing.router'; |
|
13 | + } |
|
14 | 14 | } |
@@ -7,8 +7,8 @@ |
||
7 | 7 | */ |
8 | 8 | class Flash extends Facade |
9 | 9 | { |
10 | - protected static function getFacadeAccessor() |
|
11 | - { |
|
12 | - return 'framework.flash.flash'; |
|
13 | - } |
|
10 | + protected static function getFacadeAccessor() |
|
11 | + { |
|
12 | + return 'framework.flash.flash'; |
|
13 | + } |
|
14 | 14 | } |
@@ -12,216 +12,216 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class Facade |
14 | 14 | { |
15 | - /** |
|
16 | - * The application instance being facaded. |
|
17 | - * |
|
18 | - * @var object |
|
19 | - */ |
|
20 | - protected static $app; |
|
21 | - |
|
22 | - /** |
|
23 | - * The resolved object instances. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - protected static $resolvedInstance; |
|
28 | - |
|
29 | - /** |
|
30 | - * Convert the facade into a Mockery spy. |
|
31 | - * |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public static function spy() |
|
35 | - { |
|
36 | - if (! static::isMock()) { |
|
37 | - $class = static::getMockableClass(); |
|
38 | - |
|
39 | - static::swap($class ? Mockery::spy($class) : Mockery::spy()); |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Initiate a mock expectation on the facade. |
|
45 | - * |
|
46 | - * @return \Mockery\Expectation |
|
47 | - */ |
|
48 | - public static function shouldReceive() |
|
49 | - { |
|
50 | - $name = static::getFacadeAccessor(); |
|
51 | - |
|
52 | - $mock = static::isMock() |
|
53 | - ? static::$resolvedInstance[$name] |
|
54 | - : static::createFreshMockInstance(); |
|
55 | - |
|
56 | - return $mock->shouldReceive(...func_get_args()); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Create a fresh mock instance for the given class. |
|
61 | - * |
|
62 | - * @return \Mockery\Expectation |
|
63 | - */ |
|
64 | - protected static function createFreshMockInstance() |
|
65 | - { |
|
66 | - return tap(static::createMock(), function ($mock) { |
|
67 | - static::swap($mock); |
|
68 | - |
|
69 | - $mock->shouldAllowMockingProtectedMethods(); |
|
70 | - }); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Create a fresh mock instance for the given class. |
|
75 | - * |
|
76 | - * @return \Mockery\MockInterface |
|
77 | - */ |
|
78 | - protected static function createMock() |
|
79 | - { |
|
80 | - $class = static::getMockableClass(); |
|
81 | - |
|
82 | - return $class ? Mockery::mock($class) : Mockery::mock(); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Determines whether a mock is set as the instance of the facade. |
|
87 | - * |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - protected static function isMock() |
|
91 | - { |
|
92 | - $name = static::getFacadeAccessor(); |
|
93 | - |
|
94 | - return isset(static::$resolvedInstance[$name]) && |
|
95 | - static::$resolvedInstance[$name] instanceof MockInterface; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get the mockable class for the bound instance. |
|
100 | - * |
|
101 | - * @return string|null |
|
102 | - */ |
|
103 | - protected static function getMockableClass() |
|
104 | - { |
|
105 | - if ($root = static::getFacadeRoot()) { |
|
106 | - return get_class($root); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Hotswap the underlying instance behind the facade. |
|
112 | - * |
|
113 | - * @param mixed $instance |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public static function swap($instance) |
|
117 | - { |
|
118 | - static::$resolvedInstance[static::getFacadeAccessor()] = $instance; |
|
119 | - |
|
120 | - if (isset(static::$app)) { |
|
121 | - static::$app->instance(static::getFacadeAccessor(), $instance); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Get the root object behind the facade. |
|
127 | - * |
|
128 | - * @return mixed |
|
129 | - */ |
|
130 | - public static function getFacadeRoot() |
|
131 | - { |
|
132 | - return static::resolveFacadeInstance(static::getFacadeAccessor()); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Get the registered name of the component. |
|
137 | - * |
|
138 | - * @return string |
|
139 | - * |
|
140 | - * @throws \RuntimeException |
|
141 | - */ |
|
142 | - protected static function getFacadeAccessor() |
|
143 | - { |
|
144 | - throw new RuntimeException('Facade does not implement getFacadeAccessor method.'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Resolve the facade root instance from the container. |
|
149 | - * |
|
150 | - * @param string|object $name |
|
151 | - * @return mixed |
|
152 | - */ |
|
153 | - protected static function resolveFacadeInstance($name) |
|
154 | - { |
|
155 | - if (is_object($name)) { |
|
156 | - return $name; |
|
157 | - } |
|
158 | - |
|
159 | - if (isset(static::$resolvedInstance[$name])) { |
|
160 | - return static::$resolvedInstance[$name]; |
|
161 | - } |
|
162 | - |
|
163 | - return static::$resolvedInstance[$name] = static::$app[$name]; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Clear a resolved facade instance. |
|
168 | - * |
|
169 | - * @param string $name |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public static function clearResolvedInstance($name) |
|
173 | - { |
|
174 | - unset(static::$resolvedInstance[$name]); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Clear all of the resolved instances. |
|
179 | - * |
|
180 | - * @return void |
|
181 | - */ |
|
182 | - public static function clearResolvedInstances() |
|
183 | - { |
|
184 | - static::$resolvedInstance = []; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Get the application instance behind the facade. |
|
189 | - * |
|
190 | - * @return object |
|
191 | - */ |
|
192 | - public static function getFacadeApplication() |
|
193 | - { |
|
194 | - return static::$app; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Set the application instance. |
|
199 | - * |
|
200 | - * @param object $app |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public static function setFacadeApplication($app) |
|
204 | - { |
|
205 | - static::$app = $app; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Handle dynamic, static calls to the object. |
|
210 | - * |
|
211 | - * @param string $method |
|
212 | - * @param array $args |
|
213 | - * @return mixed |
|
214 | - * |
|
215 | - * @throws \RuntimeException |
|
216 | - */ |
|
217 | - public static function __callStatic($method, $args) |
|
218 | - { |
|
219 | - $instance = static::getFacadeRoot(); |
|
220 | - |
|
221 | - if (! $instance) { |
|
222 | - throw new RuntimeException('A facade root has not been set.'); |
|
223 | - } |
|
224 | - |
|
225 | - return $instance->$method(...$args); |
|
226 | - } |
|
15 | + /** |
|
16 | + * The application instance being facaded. |
|
17 | + * |
|
18 | + * @var object |
|
19 | + */ |
|
20 | + protected static $app; |
|
21 | + |
|
22 | + /** |
|
23 | + * The resolved object instances. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + protected static $resolvedInstance; |
|
28 | + |
|
29 | + /** |
|
30 | + * Convert the facade into a Mockery spy. |
|
31 | + * |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public static function spy() |
|
35 | + { |
|
36 | + if (! static::isMock()) { |
|
37 | + $class = static::getMockableClass(); |
|
38 | + |
|
39 | + static::swap($class ? Mockery::spy($class) : Mockery::spy()); |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Initiate a mock expectation on the facade. |
|
45 | + * |
|
46 | + * @return \Mockery\Expectation |
|
47 | + */ |
|
48 | + public static function shouldReceive() |
|
49 | + { |
|
50 | + $name = static::getFacadeAccessor(); |
|
51 | + |
|
52 | + $mock = static::isMock() |
|
53 | + ? static::$resolvedInstance[$name] |
|
54 | + : static::createFreshMockInstance(); |
|
55 | + |
|
56 | + return $mock->shouldReceive(...func_get_args()); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Create a fresh mock instance for the given class. |
|
61 | + * |
|
62 | + * @return \Mockery\Expectation |
|
63 | + */ |
|
64 | + protected static function createFreshMockInstance() |
|
65 | + { |
|
66 | + return tap(static::createMock(), function ($mock) { |
|
67 | + static::swap($mock); |
|
68 | + |
|
69 | + $mock->shouldAllowMockingProtectedMethods(); |
|
70 | + }); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Create a fresh mock instance for the given class. |
|
75 | + * |
|
76 | + * @return \Mockery\MockInterface |
|
77 | + */ |
|
78 | + protected static function createMock() |
|
79 | + { |
|
80 | + $class = static::getMockableClass(); |
|
81 | + |
|
82 | + return $class ? Mockery::mock($class) : Mockery::mock(); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Determines whether a mock is set as the instance of the facade. |
|
87 | + * |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + protected static function isMock() |
|
91 | + { |
|
92 | + $name = static::getFacadeAccessor(); |
|
93 | + |
|
94 | + return isset(static::$resolvedInstance[$name]) && |
|
95 | + static::$resolvedInstance[$name] instanceof MockInterface; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get the mockable class for the bound instance. |
|
100 | + * |
|
101 | + * @return string|null |
|
102 | + */ |
|
103 | + protected static function getMockableClass() |
|
104 | + { |
|
105 | + if ($root = static::getFacadeRoot()) { |
|
106 | + return get_class($root); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Hotswap the underlying instance behind the facade. |
|
112 | + * |
|
113 | + * @param mixed $instance |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public static function swap($instance) |
|
117 | + { |
|
118 | + static::$resolvedInstance[static::getFacadeAccessor()] = $instance; |
|
119 | + |
|
120 | + if (isset(static::$app)) { |
|
121 | + static::$app->instance(static::getFacadeAccessor(), $instance); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Get the root object behind the facade. |
|
127 | + * |
|
128 | + * @return mixed |
|
129 | + */ |
|
130 | + public static function getFacadeRoot() |
|
131 | + { |
|
132 | + return static::resolveFacadeInstance(static::getFacadeAccessor()); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Get the registered name of the component. |
|
137 | + * |
|
138 | + * @return string |
|
139 | + * |
|
140 | + * @throws \RuntimeException |
|
141 | + */ |
|
142 | + protected static function getFacadeAccessor() |
|
143 | + { |
|
144 | + throw new RuntimeException('Facade does not implement getFacadeAccessor method.'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Resolve the facade root instance from the container. |
|
149 | + * |
|
150 | + * @param string|object $name |
|
151 | + * @return mixed |
|
152 | + */ |
|
153 | + protected static function resolveFacadeInstance($name) |
|
154 | + { |
|
155 | + if (is_object($name)) { |
|
156 | + return $name; |
|
157 | + } |
|
158 | + |
|
159 | + if (isset(static::$resolvedInstance[$name])) { |
|
160 | + return static::$resolvedInstance[$name]; |
|
161 | + } |
|
162 | + |
|
163 | + return static::$resolvedInstance[$name] = static::$app[$name]; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Clear a resolved facade instance. |
|
168 | + * |
|
169 | + * @param string $name |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public static function clearResolvedInstance($name) |
|
173 | + { |
|
174 | + unset(static::$resolvedInstance[$name]); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Clear all of the resolved instances. |
|
179 | + * |
|
180 | + * @return void |
|
181 | + */ |
|
182 | + public static function clearResolvedInstances() |
|
183 | + { |
|
184 | + static::$resolvedInstance = []; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Get the application instance behind the facade. |
|
189 | + * |
|
190 | + * @return object |
|
191 | + */ |
|
192 | + public static function getFacadeApplication() |
|
193 | + { |
|
194 | + return static::$app; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Set the application instance. |
|
199 | + * |
|
200 | + * @param object $app |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public static function setFacadeApplication($app) |
|
204 | + { |
|
205 | + static::$app = $app; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Handle dynamic, static calls to the object. |
|
210 | + * |
|
211 | + * @param string $method |
|
212 | + * @param array $args |
|
213 | + * @return mixed |
|
214 | + * |
|
215 | + * @throws \RuntimeException |
|
216 | + */ |
|
217 | + public static function __callStatic($method, $args) |
|
218 | + { |
|
219 | + $instance = static::getFacadeRoot(); |
|
220 | + |
|
221 | + if (! $instance) { |
|
222 | + throw new RuntimeException('A facade root has not been set.'); |
|
223 | + } |
|
224 | + |
|
225 | + return $instance->$method(...$args); |
|
226 | + } |
|
227 | 227 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public static function spy() |
35 | 35 | { |
36 | - if (! static::isMock()) { |
|
36 | + if ( ! static::isMock()) { |
|
37 | 37 | $class = static::getMockableClass(); |
38 | 38 | |
39 | 39 | static::swap($class ? Mockery::spy($class) : Mockery::spy()); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | */ |
64 | 64 | protected static function createFreshMockInstance() |
65 | 65 | { |
66 | - return tap(static::createMock(), function ($mock) { |
|
66 | + return tap(static::createMock(), function($mock) { |
|
67 | 67 | static::swap($mock); |
68 | 68 | |
69 | 69 | $mock->shouldAllowMockingProtectedMethods(); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | { |
219 | 219 | $instance = static::getFacadeRoot(); |
220 | 220 | |
221 | - if (! $instance) { |
|
221 | + if ( ! $instance) { |
|
222 | 222 | throw new RuntimeException('A facade root has not been set.'); |
223 | 223 | } |
224 | 224 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @return string |
23 | 23 | */ |
24 | 24 | public static function getCurrentUrl() { |
25 | - return home_url( add_query_arg( array() ) ); |
|
25 | + return home_url(add_query_arg(array())); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | * @param string $url |
32 | 32 | * @return string |
33 | 33 | */ |
34 | - public static function addLeadingSlash( $url ) { |
|
35 | - return '/' . static::removeLeadingSlash( $url ); |
|
34 | + public static function addLeadingSlash($url) { |
|
35 | + return '/' . static::removeLeadingSlash($url); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | * @param string $url |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - public static function removeLeadingSlash( $url ) { |
|
45 | - return preg_replace( '/^\/+/', '', $url ); |
|
44 | + public static function removeLeadingSlash($url) { |
|
45 | + return preg_replace('/^\/+/', '', $url); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @param string $url |
52 | 52 | * @return string |
53 | 53 | */ |
54 | - public static function addTrailingSlash( $url ) { |
|
55 | - return trailingslashit( $url ); |
|
54 | + public static function addTrailingSlash($url) { |
|
55 | + return trailingslashit($url); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param string $url |
62 | 62 | * @return string |
63 | 63 | */ |
64 | - public static function removeTrailingSlash( $url ) { |
|
65 | - return untrailingslashit( $url ); |
|
64 | + public static function removeTrailingSlash($url) { |
|
65 | + return untrailingslashit($url); |
|
66 | 66 | } |
67 | 67 | } |
@@ -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 \Illuminate\Foundation\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 \Illuminate\Foundation\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 \Illuminate\Foundation\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 \Illuminate\Foundation\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 \Illuminate\Foundation\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 \Illuminate\Foundation\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 | } |
@@ -91,7 +91,7 @@ |
||
91 | 91 | */ |
92 | 92 | public function register() |
93 | 93 | { |
94 | - if (! $this->registered) { |
|
94 | + if ( ! $this->registered) { |
|
95 | 95 | $this->prependToLoaderStack(); |
96 | 96 | |
97 | 97 | $this->registered = true; |
@@ -10,442 +10,442 @@ |
||
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 | - * Divide an array into two arrays. One with keys and the other with values. |
|
43 | - * |
|
44 | - * @param array $array |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public static function divide($array) |
|
48 | - { |
|
49 | - return [array_keys($array), array_values($array)]; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Flatten a multi-dimensional associative array with dots. |
|
54 | - * |
|
55 | - * @param array $array |
|
56 | - * @param string $prepend |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public static function dot($array, $prepend = '') |
|
60 | - { |
|
61 | - $results = []; |
|
62 | - |
|
63 | - foreach ($array as $key => $value) { |
|
64 | - if (is_array($value) && ! empty($value)) { |
|
65 | - $results = array_merge($results, static::dot($value, $prepend.$key.'.')); |
|
66 | - } else { |
|
67 | - $results[$prepend.$key] = $value; |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - return $results; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Get all of the given array except for a specified array of items. |
|
76 | - * |
|
77 | - * @param array $array |
|
78 | - * @param array|string $keys |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public static function except($array, $keys) |
|
82 | - { |
|
83 | - static::forget($array, $keys); |
|
84 | - |
|
85 | - return $array; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Determine if the given key exists in the provided array. |
|
90 | - * |
|
91 | - * @param \ArrayAccess|array $array |
|
92 | - * @param string|int $key |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public static function exists($array, $key) |
|
96 | - { |
|
97 | - if ($array instanceof ArrayAccess) { |
|
98 | - return $array->offsetExists($key); |
|
99 | - } |
|
100 | - |
|
101 | - return array_key_exists($key, $array); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Return the first element in an array passing a given truth test. |
|
106 | - * |
|
107 | - * @param array $array |
|
108 | - * @param callable|null $callback |
|
109 | - * @param mixed $default |
|
110 | - * @return mixed |
|
111 | - */ |
|
112 | - public static function first($array, callable $callback = null, $default = null) |
|
113 | - { |
|
114 | - if (is_null($callback)) { |
|
115 | - if (empty($array)) { |
|
116 | - return $default; |
|
117 | - } |
|
118 | - |
|
119 | - foreach ($array as $item) { |
|
120 | - return $item; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - foreach ($array as $key => $value) { |
|
125 | - if (call_user_func($callback, $value, $key)) { |
|
126 | - return $value; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - return $default; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Return the last element in an array passing a given truth test. |
|
135 | - * |
|
136 | - * @param array $array |
|
137 | - * @param callable|null $callback |
|
138 | - * @param mixed $default |
|
139 | - * @return mixed |
|
140 | - */ |
|
141 | - public static function last($array, callable $callback = null, $default = null) |
|
142 | - { |
|
143 | - if (is_null($callback)) { |
|
144 | - return empty($array) ? $default : end($array); |
|
145 | - } |
|
146 | - |
|
147 | - return static::first(array_reverse($array, true), $callback, $default); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Remove one or many array items from a given array using "dot" notation. |
|
152 | - * |
|
153 | - * @param array $array |
|
154 | - * @param array|string $keys |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - public static function forget(&$array, $keys) |
|
158 | - { |
|
159 | - $original = &$array; |
|
160 | - |
|
161 | - $keys = (array) $keys; |
|
162 | - |
|
163 | - if (count($keys) === 0) { |
|
164 | - return; |
|
165 | - } |
|
166 | - |
|
167 | - foreach ($keys as $key) { |
|
168 | - // if the exact key exists in the top-level, remove it |
|
169 | - if (static::exists($array, $key)) { |
|
170 | - unset($array[$key]); |
|
171 | - |
|
172 | - continue; |
|
173 | - } |
|
174 | - |
|
175 | - $parts = explode('.', $key); |
|
176 | - |
|
177 | - // clean up before each pass |
|
178 | - $array = &$original; |
|
179 | - |
|
180 | - while (count($parts) > 1) { |
|
181 | - $part = array_shift($parts); |
|
182 | - |
|
183 | - if (isset($array[$part]) && is_array($array[$part])) { |
|
184 | - $array = &$array[$part]; |
|
185 | - } else { |
|
186 | - continue 2; |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - unset($array[array_shift($parts)]); |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get an item from an array using "dot" notation. |
|
196 | - * |
|
197 | - * @param \ArrayAccess|array $array |
|
198 | - * @param string $key |
|
199 | - * @param mixed $default |
|
200 | - * @return mixed |
|
201 | - */ |
|
202 | - public static function get($array, $key, $default = null) |
|
203 | - { |
|
204 | - if (! static::accessible($array)) { |
|
205 | - return $default; |
|
206 | - } |
|
207 | - |
|
208 | - if (is_null($key)) { |
|
209 | - return $array; |
|
210 | - } |
|
211 | - |
|
212 | - if (static::exists($array, $key)) { |
|
213 | - return $array[$key]; |
|
214 | - } |
|
215 | - |
|
216 | - foreach (explode('.', $key) as $segment) { |
|
217 | - if (static::accessible($array) && static::exists($array, $segment)) { |
|
218 | - $array = $array[$segment]; |
|
219 | - } else { |
|
220 | - return $default; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - return $array; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Check if an item or items exist in an array using "dot" notation. |
|
229 | - * |
|
230 | - * @param \ArrayAccess|array $array |
|
231 | - * @param string|array $keys |
|
232 | - * @return bool |
|
233 | - */ |
|
234 | - public static function has($array, $keys) |
|
235 | - { |
|
236 | - if (is_null($keys)) { |
|
237 | - return false; |
|
238 | - } |
|
239 | - |
|
240 | - $keys = (array) $keys; |
|
241 | - |
|
242 | - if (! $array) { |
|
243 | - return false; |
|
244 | - } |
|
245 | - |
|
246 | - if ($keys === []) { |
|
247 | - return false; |
|
248 | - } |
|
249 | - |
|
250 | - foreach ($keys as $key) { |
|
251 | - $subKeyArray = $array; |
|
252 | - |
|
253 | - if (static::exists($array, $key)) { |
|
254 | - continue; |
|
255 | - } |
|
256 | - |
|
257 | - foreach (explode('.', $key) as $segment) { |
|
258 | - if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) { |
|
259 | - $subKeyArray = $subKeyArray[$segment]; |
|
260 | - } else { |
|
261 | - return false; |
|
262 | - } |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - return true; |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Determines if an array is associative. |
|
271 | - * |
|
272 | - * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. |
|
273 | - * |
|
274 | - * @param array $array |
|
275 | - * @return bool |
|
276 | - */ |
|
277 | - public static function isAssoc(array $array) |
|
278 | - { |
|
279 | - $keys = array_keys($array); |
|
280 | - |
|
281 | - return array_keys($keys) !== $keys; |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Get a subset of the items from the given array. |
|
286 | - * |
|
287 | - * @param array $array |
|
288 | - * @param array|string $keys |
|
289 | - * @return array |
|
290 | - */ |
|
291 | - public static function only($array, $keys) |
|
292 | - { |
|
293 | - return array_intersect_key($array, array_flip((array) $keys)); |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Pluck an array of values from an array. |
|
298 | - * |
|
299 | - * @param array $array |
|
300 | - * @param string|array $value |
|
301 | - * @param string|array|null $key |
|
302 | - * @return array |
|
303 | - */ |
|
304 | - public static function pluck($array, $value, $key = null) |
|
305 | - { |
|
306 | - $results = []; |
|
307 | - |
|
308 | - list($value, $key) = static::explodePluckParameters($value, $key); |
|
309 | - |
|
310 | - foreach ($array as $item) { |
|
311 | - $itemValue = data_get($item, $value); |
|
312 | - |
|
313 | - // If the key is "null", we will just append the value to the array and keep |
|
314 | - // looping. Otherwise we will key the array using the value of the key we |
|
315 | - // received from the developer. Then we'll return the final array form. |
|
316 | - if (is_null($key)) { |
|
317 | - $results[] = $itemValue; |
|
318 | - } else { |
|
319 | - $itemKey = data_get($item, $key); |
|
320 | - |
|
321 | - $results[$itemKey] = $itemValue; |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - return $results; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Explode the "value" and "key" arguments passed to "pluck". |
|
330 | - * |
|
331 | - * @param string|array $value |
|
332 | - * @param string|array|null $key |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected static function explodePluckParameters($value, $key) |
|
336 | - { |
|
337 | - $value = is_string($value) ? explode('.', $value) : $value; |
|
338 | - |
|
339 | - $key = is_null($key) || is_array($key) ? $key : explode('.', $key); |
|
340 | - |
|
341 | - return [$value, $key]; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Push an item onto the beginning of an array. |
|
346 | - * |
|
347 | - * @param array $array |
|
348 | - * @param mixed $value |
|
349 | - * @param mixed $key |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function prepend($array, $value, $key = null) |
|
353 | - { |
|
354 | - if (is_null($key)) { |
|
355 | - array_unshift($array, $value); |
|
356 | - } else { |
|
357 | - $array = [$key => $value] + $array; |
|
358 | - } |
|
359 | - |
|
360 | - return $array; |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Get a value from the array, and remove it. |
|
365 | - * |
|
366 | - * @param array $array |
|
367 | - * @param string $key |
|
368 | - * @param mixed $default |
|
369 | - * @return mixed |
|
370 | - */ |
|
371 | - public static function pull(&$array, $key, $default = null) |
|
372 | - { |
|
373 | - $value = static::get($array, $key, $default); |
|
374 | - |
|
375 | - static::forget($array, $key); |
|
376 | - |
|
377 | - return $value; |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Set an array item to a given value using "dot" notation. |
|
382 | - * |
|
383 | - * If no key is given to the method, the entire array will be replaced. |
|
384 | - * |
|
385 | - * @param array $array |
|
386 | - * @param string $key |
|
387 | - * @param mixed $value |
|
388 | - * @return array |
|
389 | - */ |
|
390 | - public static function set(&$array, $key, $value) |
|
391 | - { |
|
392 | - if (is_null($key)) { |
|
393 | - return $array = $value; |
|
394 | - } |
|
395 | - |
|
396 | - $keys = explode('.', $key); |
|
397 | - |
|
398 | - while (count($keys) > 1) { |
|
399 | - $key = array_shift($keys); |
|
400 | - |
|
401 | - // If the key doesn't exist at this depth, we will just create an empty array |
|
402 | - // to hold the next value, allowing us to create the arrays to hold final |
|
403 | - // values at the correct depth. Then we'll keep digging into the array. |
|
404 | - if (! isset($array[$key]) || ! is_array($array[$key])) { |
|
405 | - $array[$key] = []; |
|
406 | - } |
|
407 | - |
|
408 | - $array = &$array[$key]; |
|
409 | - } |
|
410 | - |
|
411 | - $array[array_shift($keys)] = $value; |
|
412 | - |
|
413 | - return $array; |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Shuffle the given array and return the result. |
|
418 | - * |
|
419 | - * @param array $array |
|
420 | - * @return array |
|
421 | - */ |
|
422 | - public static function shuffle($array) |
|
423 | - { |
|
424 | - shuffle($array); |
|
425 | - |
|
426 | - return $array; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Recursively sort an array by keys and values. |
|
431 | - * |
|
432 | - * @param array $array |
|
433 | - * @return array |
|
434 | - */ |
|
435 | - public static function sortRecursive($array) |
|
436 | - { |
|
437 | - foreach ($array as &$value) { |
|
438 | - if (is_array($value)) { |
|
439 | - $value = static::sortRecursive($value); |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - if (static::isAssoc($array)) { |
|
444 | - ksort($array); |
|
445 | - } else { |
|
446 | - sort($array); |
|
447 | - } |
|
448 | - |
|
449 | - return $array; |
|
450 | - } |
|
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 | + * Divide an array into two arrays. One with keys and the other with values. |
|
43 | + * |
|
44 | + * @param array $array |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public static function divide($array) |
|
48 | + { |
|
49 | + return [array_keys($array), array_values($array)]; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Flatten a multi-dimensional associative array with dots. |
|
54 | + * |
|
55 | + * @param array $array |
|
56 | + * @param string $prepend |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public static function dot($array, $prepend = '') |
|
60 | + { |
|
61 | + $results = []; |
|
62 | + |
|
63 | + foreach ($array as $key => $value) { |
|
64 | + if (is_array($value) && ! empty($value)) { |
|
65 | + $results = array_merge($results, static::dot($value, $prepend.$key.'.')); |
|
66 | + } else { |
|
67 | + $results[$prepend.$key] = $value; |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + return $results; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Get all of the given array except for a specified array of items. |
|
76 | + * |
|
77 | + * @param array $array |
|
78 | + * @param array|string $keys |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public static function except($array, $keys) |
|
82 | + { |
|
83 | + static::forget($array, $keys); |
|
84 | + |
|
85 | + return $array; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Determine if the given key exists in the provided array. |
|
90 | + * |
|
91 | + * @param \ArrayAccess|array $array |
|
92 | + * @param string|int $key |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public static function exists($array, $key) |
|
96 | + { |
|
97 | + if ($array instanceof ArrayAccess) { |
|
98 | + return $array->offsetExists($key); |
|
99 | + } |
|
100 | + |
|
101 | + return array_key_exists($key, $array); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Return the first element in an array passing a given truth test. |
|
106 | + * |
|
107 | + * @param array $array |
|
108 | + * @param callable|null $callback |
|
109 | + * @param mixed $default |
|
110 | + * @return mixed |
|
111 | + */ |
|
112 | + public static function first($array, callable $callback = null, $default = null) |
|
113 | + { |
|
114 | + if (is_null($callback)) { |
|
115 | + if (empty($array)) { |
|
116 | + return $default; |
|
117 | + } |
|
118 | + |
|
119 | + foreach ($array as $item) { |
|
120 | + return $item; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + foreach ($array as $key => $value) { |
|
125 | + if (call_user_func($callback, $value, $key)) { |
|
126 | + return $value; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + return $default; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Return the last element in an array passing a given truth test. |
|
135 | + * |
|
136 | + * @param array $array |
|
137 | + * @param callable|null $callback |
|
138 | + * @param mixed $default |
|
139 | + * @return mixed |
|
140 | + */ |
|
141 | + public static function last($array, callable $callback = null, $default = null) |
|
142 | + { |
|
143 | + if (is_null($callback)) { |
|
144 | + return empty($array) ? $default : end($array); |
|
145 | + } |
|
146 | + |
|
147 | + return static::first(array_reverse($array, true), $callback, $default); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Remove one or many array items from a given array using "dot" notation. |
|
152 | + * |
|
153 | + * @param array $array |
|
154 | + * @param array|string $keys |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + public static function forget(&$array, $keys) |
|
158 | + { |
|
159 | + $original = &$array; |
|
160 | + |
|
161 | + $keys = (array) $keys; |
|
162 | + |
|
163 | + if (count($keys) === 0) { |
|
164 | + return; |
|
165 | + } |
|
166 | + |
|
167 | + foreach ($keys as $key) { |
|
168 | + // if the exact key exists in the top-level, remove it |
|
169 | + if (static::exists($array, $key)) { |
|
170 | + unset($array[$key]); |
|
171 | + |
|
172 | + continue; |
|
173 | + } |
|
174 | + |
|
175 | + $parts = explode('.', $key); |
|
176 | + |
|
177 | + // clean up before each pass |
|
178 | + $array = &$original; |
|
179 | + |
|
180 | + while (count($parts) > 1) { |
|
181 | + $part = array_shift($parts); |
|
182 | + |
|
183 | + if (isset($array[$part]) && is_array($array[$part])) { |
|
184 | + $array = &$array[$part]; |
|
185 | + } else { |
|
186 | + continue 2; |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + unset($array[array_shift($parts)]); |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get an item from an array using "dot" notation. |
|
196 | + * |
|
197 | + * @param \ArrayAccess|array $array |
|
198 | + * @param string $key |
|
199 | + * @param mixed $default |
|
200 | + * @return mixed |
|
201 | + */ |
|
202 | + public static function get($array, $key, $default = null) |
|
203 | + { |
|
204 | + if (! static::accessible($array)) { |
|
205 | + return $default; |
|
206 | + } |
|
207 | + |
|
208 | + if (is_null($key)) { |
|
209 | + return $array; |
|
210 | + } |
|
211 | + |
|
212 | + if (static::exists($array, $key)) { |
|
213 | + return $array[$key]; |
|
214 | + } |
|
215 | + |
|
216 | + foreach (explode('.', $key) as $segment) { |
|
217 | + if (static::accessible($array) && static::exists($array, $segment)) { |
|
218 | + $array = $array[$segment]; |
|
219 | + } else { |
|
220 | + return $default; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + return $array; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Check if an item or items exist in an array using "dot" notation. |
|
229 | + * |
|
230 | + * @param \ArrayAccess|array $array |
|
231 | + * @param string|array $keys |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | + public static function has($array, $keys) |
|
235 | + { |
|
236 | + if (is_null($keys)) { |
|
237 | + return false; |
|
238 | + } |
|
239 | + |
|
240 | + $keys = (array) $keys; |
|
241 | + |
|
242 | + if (! $array) { |
|
243 | + return false; |
|
244 | + } |
|
245 | + |
|
246 | + if ($keys === []) { |
|
247 | + return false; |
|
248 | + } |
|
249 | + |
|
250 | + foreach ($keys as $key) { |
|
251 | + $subKeyArray = $array; |
|
252 | + |
|
253 | + if (static::exists($array, $key)) { |
|
254 | + continue; |
|
255 | + } |
|
256 | + |
|
257 | + foreach (explode('.', $key) as $segment) { |
|
258 | + if (static::accessible($subKeyArray) && static::exists($subKeyArray, $segment)) { |
|
259 | + $subKeyArray = $subKeyArray[$segment]; |
|
260 | + } else { |
|
261 | + return false; |
|
262 | + } |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + return true; |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Determines if an array is associative. |
|
271 | + * |
|
272 | + * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. |
|
273 | + * |
|
274 | + * @param array $array |
|
275 | + * @return bool |
|
276 | + */ |
|
277 | + public static function isAssoc(array $array) |
|
278 | + { |
|
279 | + $keys = array_keys($array); |
|
280 | + |
|
281 | + return array_keys($keys) !== $keys; |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Get a subset of the items from the given array. |
|
286 | + * |
|
287 | + * @param array $array |
|
288 | + * @param array|string $keys |
|
289 | + * @return array |
|
290 | + */ |
|
291 | + public static function only($array, $keys) |
|
292 | + { |
|
293 | + return array_intersect_key($array, array_flip((array) $keys)); |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Pluck an array of values from an array. |
|
298 | + * |
|
299 | + * @param array $array |
|
300 | + * @param string|array $value |
|
301 | + * @param string|array|null $key |
|
302 | + * @return array |
|
303 | + */ |
|
304 | + public static function pluck($array, $value, $key = null) |
|
305 | + { |
|
306 | + $results = []; |
|
307 | + |
|
308 | + list($value, $key) = static::explodePluckParameters($value, $key); |
|
309 | + |
|
310 | + foreach ($array as $item) { |
|
311 | + $itemValue = data_get($item, $value); |
|
312 | + |
|
313 | + // If the key is "null", we will just append the value to the array and keep |
|
314 | + // looping. Otherwise we will key the array using the value of the key we |
|
315 | + // received from the developer. Then we'll return the final array form. |
|
316 | + if (is_null($key)) { |
|
317 | + $results[] = $itemValue; |
|
318 | + } else { |
|
319 | + $itemKey = data_get($item, $key); |
|
320 | + |
|
321 | + $results[$itemKey] = $itemValue; |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + return $results; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Explode the "value" and "key" arguments passed to "pluck". |
|
330 | + * |
|
331 | + * @param string|array $value |
|
332 | + * @param string|array|null $key |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected static function explodePluckParameters($value, $key) |
|
336 | + { |
|
337 | + $value = is_string($value) ? explode('.', $value) : $value; |
|
338 | + |
|
339 | + $key = is_null($key) || is_array($key) ? $key : explode('.', $key); |
|
340 | + |
|
341 | + return [$value, $key]; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Push an item onto the beginning of an array. |
|
346 | + * |
|
347 | + * @param array $array |
|
348 | + * @param mixed $value |
|
349 | + * @param mixed $key |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function prepend($array, $value, $key = null) |
|
353 | + { |
|
354 | + if (is_null($key)) { |
|
355 | + array_unshift($array, $value); |
|
356 | + } else { |
|
357 | + $array = [$key => $value] + $array; |
|
358 | + } |
|
359 | + |
|
360 | + return $array; |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Get a value from the array, and remove it. |
|
365 | + * |
|
366 | + * @param array $array |
|
367 | + * @param string $key |
|
368 | + * @param mixed $default |
|
369 | + * @return mixed |
|
370 | + */ |
|
371 | + public static function pull(&$array, $key, $default = null) |
|
372 | + { |
|
373 | + $value = static::get($array, $key, $default); |
|
374 | + |
|
375 | + static::forget($array, $key); |
|
376 | + |
|
377 | + return $value; |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Set an array item to a given value using "dot" notation. |
|
382 | + * |
|
383 | + * If no key is given to the method, the entire array will be replaced. |
|
384 | + * |
|
385 | + * @param array $array |
|
386 | + * @param string $key |
|
387 | + * @param mixed $value |
|
388 | + * @return array |
|
389 | + */ |
|
390 | + public static function set(&$array, $key, $value) |
|
391 | + { |
|
392 | + if (is_null($key)) { |
|
393 | + return $array = $value; |
|
394 | + } |
|
395 | + |
|
396 | + $keys = explode('.', $key); |
|
397 | + |
|
398 | + while (count($keys) > 1) { |
|
399 | + $key = array_shift($keys); |
|
400 | + |
|
401 | + // If the key doesn't exist at this depth, we will just create an empty array |
|
402 | + // to hold the next value, allowing us to create the arrays to hold final |
|
403 | + // values at the correct depth. Then we'll keep digging into the array. |
|
404 | + if (! isset($array[$key]) || ! is_array($array[$key])) { |
|
405 | + $array[$key] = []; |
|
406 | + } |
|
407 | + |
|
408 | + $array = &$array[$key]; |
|
409 | + } |
|
410 | + |
|
411 | + $array[array_shift($keys)] = $value; |
|
412 | + |
|
413 | + return $array; |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Shuffle the given array and return the result. |
|
418 | + * |
|
419 | + * @param array $array |
|
420 | + * @return array |
|
421 | + */ |
|
422 | + public static function shuffle($array) |
|
423 | + { |
|
424 | + shuffle($array); |
|
425 | + |
|
426 | + return $array; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Recursively sort an array by keys and values. |
|
431 | + * |
|
432 | + * @param array $array |
|
433 | + * @return array |
|
434 | + */ |
|
435 | + public static function sortRecursive($array) |
|
436 | + { |
|
437 | + foreach ($array as &$value) { |
|
438 | + if (is_array($value)) { |
|
439 | + $value = static::sortRecursive($value); |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + if (static::isAssoc($array)) { |
|
444 | + ksort($array); |
|
445 | + } else { |
|
446 | + sort($array); |
|
447 | + } |
|
448 | + |
|
449 | + return $array; |
|
450 | + } |
|
451 | 451 | } |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | |
63 | 63 | foreach ($array as $key => $value) { |
64 | 64 | if (is_array($value) && ! empty($value)) { |
65 | - $results = array_merge($results, static::dot($value, $prepend.$key.'.')); |
|
65 | + $results = array_merge($results, static::dot($value, $prepend . $key . '.')); |
|
66 | 66 | } else { |
67 | - $results[$prepend.$key] = $value; |
|
67 | + $results[$prepend . $key] = $value; |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public static function get($array, $key, $default = null) |
203 | 203 | { |
204 | - if (! static::accessible($array)) { |
|
204 | + if ( ! static::accessible($array)) { |
|
205 | 205 | return $default; |
206 | 206 | } |
207 | 207 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | |
240 | 240 | $keys = (array) $keys; |
241 | 241 | |
242 | - if (! $array) { |
|
242 | + if ( ! $array) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | // If the key doesn't exist at this depth, we will just create an empty array |
402 | 402 | // to hold the next value, allowing us to create the arrays to hold final |
403 | 403 | // values at the correct depth. Then we'll keep digging into the array. |
404 | - if (! isset($array[$key]) || ! is_array($array[$key])) { |
|
404 | + if ( ! isset($array[$key]) || ! is_array($array[$key])) { |
|
405 | 405 | $array[$key] = []; |
406 | 406 | } |
407 | 407 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @return array |
32 | 32 | */ |
33 | 33 | public static function all() { |
34 | - return Flash::peek( static::getFlashKey() ); |
|
34 | + return Flash::peek(static::getFlashKey()); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -40,9 +40,9 @@ discard block |
||
40 | 40 | * @see Arr::get() |
41 | 41 | */ |
42 | 42 | public static function get() { |
43 | - $arguments = array_merge( [ |
|
43 | + $arguments = array_merge([ |
|
44 | 44 | static::all(), |
45 | - ], func_get_args() ); |
|
46 | - return call_user_func_array( [Arr::class, 'get'], $arguments ); |
|
45 | + ], func_get_args()); |
|
46 | + return call_user_func_array([Arr::class, 'get'], $arguments); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | \ No newline at end of file |