@@ -16,561 +16,561 @@ |
||
16 | 16 | |
17 | 17 | class Filesystem |
18 | 18 | { |
19 | - use Macroable; |
|
20 | - |
|
21 | - /** |
|
22 | - * Determine if a file or directory exists. |
|
23 | - * |
|
24 | - * @param string $path |
|
25 | - * @return bool |
|
26 | - */ |
|
27 | - public function exists($path) |
|
28 | - { |
|
29 | - return file_exists($path); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Get the contents of a file. |
|
34 | - * |
|
35 | - * @param string $path |
|
36 | - * @param bool $lock |
|
37 | - * @return string |
|
38 | - * |
|
39 | - * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
|
40 | - */ |
|
41 | - public function get($path, $lock = false) |
|
42 | - { |
|
43 | - if ($this->isFile($path)) { |
|
44 | - return $lock ? $this->sharedGet($path) : file_get_contents($path); |
|
45 | - } |
|
46 | - |
|
47 | - throw new FileNotFoundException("File does not exist at path {$path}"); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Get contents of a file with shared access. |
|
52 | - * |
|
53 | - * @param string $path |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function sharedGet($path) |
|
57 | - { |
|
58 | - $contents = ''; |
|
59 | - |
|
60 | - $handle = fopen($path, 'rb'); |
|
61 | - |
|
62 | - if ($handle) { |
|
63 | - try { |
|
64 | - if (flock($handle, LOCK_SH)) { |
|
65 | - clearstatcache(true, $path); |
|
66 | - |
|
67 | - $contents = fread($handle, $this->size($path) ?: 1); |
|
68 | - |
|
69 | - flock($handle, LOCK_UN); |
|
70 | - } |
|
71 | - } finally { |
|
72 | - fclose($handle); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - return $contents; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Get the returned value of a file. |
|
81 | - * |
|
82 | - * @param string $path |
|
83 | - * @return mixed |
|
84 | - * |
|
85 | - * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
|
86 | - */ |
|
87 | - public function getRequire($path) |
|
88 | - { |
|
89 | - if ($this->isFile($path)) { |
|
90 | - return require $path; |
|
91 | - } |
|
92 | - |
|
93 | - throw new FileNotFoundException("File does not exist at path {$path}"); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Require the given file once. |
|
98 | - * |
|
99 | - * @param string $file |
|
100 | - * @return mixed |
|
101 | - */ |
|
102 | - public function requireOnce($file) |
|
103 | - { |
|
104 | - require_once $file; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get the MD5 hash of the file at the given path. |
|
109 | - * |
|
110 | - * @param string $path |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function hash($path) |
|
114 | - { |
|
115 | - return md5_file($path); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Write the contents of a file. |
|
120 | - * |
|
121 | - * @param string $path |
|
122 | - * @param string $contents |
|
123 | - * @param bool $lock |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - public function put($path, $contents, $lock = false) |
|
127 | - { |
|
128 | - return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Prepend to a file. |
|
133 | - * |
|
134 | - * @param string $path |
|
135 | - * @param string $data |
|
136 | - * @return int |
|
137 | - */ |
|
138 | - public function prepend($path, $data) |
|
139 | - { |
|
140 | - if ($this->exists($path)) { |
|
141 | - return $this->put($path, $data.$this->get($path)); |
|
142 | - } |
|
143 | - |
|
144 | - return $this->put($path, $data); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Append to a file. |
|
149 | - * |
|
150 | - * @param string $path |
|
151 | - * @param string $data |
|
152 | - * @return int |
|
153 | - */ |
|
154 | - public function append($path, $data) |
|
155 | - { |
|
156 | - return file_put_contents($path, $data, FILE_APPEND); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Get or set UNIX mode of a file or directory. |
|
161 | - * |
|
162 | - * @param string $path |
|
163 | - * @param int $mode |
|
164 | - * @return mixed |
|
165 | - */ |
|
166 | - public function chmod($path, $mode = null) |
|
167 | - { |
|
168 | - if ($mode) { |
|
169 | - return chmod($path, $mode); |
|
170 | - } |
|
171 | - |
|
172 | - return substr(sprintf('%o', fileperms($path)), -4); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Delete the file at a given path. |
|
177 | - * |
|
178 | - * @param string|array $paths |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function delete($paths) |
|
182 | - { |
|
183 | - $paths = is_array($paths) ? $paths : func_get_args(); |
|
184 | - |
|
185 | - $success = true; |
|
186 | - |
|
187 | - foreach ($paths as $path) { |
|
188 | - try { |
|
189 | - if (! @unlink($path)) { |
|
190 | - $success = false; |
|
191 | - } |
|
192 | - } catch (ErrorException $e) { |
|
193 | - $success = false; |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - return $success; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Move a file to a new location. |
|
202 | - * |
|
203 | - * @param string $path |
|
204 | - * @param string $target |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function move($path, $target) |
|
208 | - { |
|
209 | - return rename($path, $target); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Copy a file to a new location. |
|
214 | - * |
|
215 | - * @param string $path |
|
216 | - * @param string $target |
|
217 | - * @return bool |
|
218 | - */ |
|
219 | - public function copy($path, $target) |
|
220 | - { |
|
221 | - return copy($path, $target); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Create a hard link to the target file or directory. |
|
226 | - * |
|
227 | - * @param string $target |
|
228 | - * @param string $link |
|
229 | - * @return void |
|
230 | - */ |
|
231 | - public function link($target, $link) |
|
232 | - { |
|
233 | - if (! windows_os()) { |
|
234 | - return symlink($target, $link); |
|
235 | - } |
|
236 | - |
|
237 | - $mode = $this->isDirectory($target) ? 'J' : 'H'; |
|
238 | - |
|
239 | - exec("mklink /{$mode} \"{$link}\" \"{$target}\""); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Extract the file name from a file path. |
|
244 | - * |
|
245 | - * @param string $path |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function name($path) |
|
249 | - { |
|
250 | - return pathinfo($path, PATHINFO_FILENAME); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Extract the trailing name component from a file path. |
|
255 | - * |
|
256 | - * @param string $path |
|
257 | - * @return string |
|
258 | - */ |
|
259 | - public function basename($path) |
|
260 | - { |
|
261 | - return pathinfo($path, PATHINFO_BASENAME); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Extract the parent directory from a file path. |
|
266 | - * |
|
267 | - * @param string $path |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function dirname($path) |
|
271 | - { |
|
272 | - return pathinfo($path, PATHINFO_DIRNAME); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Extract the file extension from a file path. |
|
277 | - * |
|
278 | - * @param string $path |
|
279 | - * @return string |
|
280 | - */ |
|
281 | - public function extension($path) |
|
282 | - { |
|
283 | - return pathinfo($path, PATHINFO_EXTENSION); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Get the file type of a given file. |
|
288 | - * |
|
289 | - * @param string $path |
|
290 | - * @return string |
|
291 | - */ |
|
292 | - public function type($path) |
|
293 | - { |
|
294 | - return filetype($path); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get the mime-type of a given file. |
|
299 | - * |
|
300 | - * @param string $path |
|
301 | - * @return string|false |
|
302 | - */ |
|
303 | - public function mimeType($path) |
|
304 | - { |
|
305 | - return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get the file size of a given file. |
|
310 | - * |
|
311 | - * @param string $path |
|
312 | - * @return int |
|
313 | - */ |
|
314 | - public function size($path) |
|
315 | - { |
|
316 | - return filesize($path); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Get the file's last modification time. |
|
321 | - * |
|
322 | - * @param string $path |
|
323 | - * @return int |
|
324 | - */ |
|
325 | - public function lastModified($path) |
|
326 | - { |
|
327 | - return filemtime($path); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Determine if the given path is a directory. |
|
332 | - * |
|
333 | - * @param string $directory |
|
334 | - * @return bool |
|
335 | - */ |
|
336 | - public function isDirectory($directory) |
|
337 | - { |
|
338 | - return is_dir($directory); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Determine if the given path is readable. |
|
343 | - * |
|
344 | - * @param string $path |
|
345 | - * @return bool |
|
346 | - */ |
|
347 | - public function isReadable($path) |
|
348 | - { |
|
349 | - return is_readable($path); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Determine if the given path is writable. |
|
354 | - * |
|
355 | - * @param string $path |
|
356 | - * @return bool |
|
357 | - */ |
|
358 | - public function isWritable($path) |
|
359 | - { |
|
360 | - return is_writable($path); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Determine if the given path is a file. |
|
365 | - * |
|
366 | - * @param string $file |
|
367 | - * @return bool |
|
368 | - */ |
|
369 | - public function isFile($file) |
|
370 | - { |
|
371 | - return is_file($file); |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Find path names matching a given pattern. |
|
376 | - * |
|
377 | - * @param string $pattern |
|
378 | - * @param int $flags |
|
379 | - * @return array |
|
380 | - */ |
|
381 | - public function glob($pattern, $flags = 0) |
|
382 | - { |
|
383 | - return glob($pattern, $flags); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Get an array of all files in a directory. |
|
388 | - * |
|
389 | - * @param string $directory |
|
390 | - * @return array |
|
391 | - */ |
|
392 | - public function files($directory) |
|
393 | - { |
|
394 | - $glob = glob($directory.DIRECTORY_SEPARATOR.'*'); |
|
395 | - |
|
396 | - if ($glob === false) { |
|
397 | - return []; |
|
398 | - } |
|
399 | - |
|
400 | - // To get the appropriate files, we'll simply glob the directory and filter |
|
401 | - // out any "files" that are not truly files so we do not end up with any |
|
402 | - // directories in our list, but only true files within the directory. |
|
403 | - return array_filter($glob, function ($file) { |
|
404 | - return filetype($file) == 'file'; |
|
405 | - }); |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * Get all of the files from the given directory (recursive). |
|
410 | - * |
|
411 | - * @param string $directory |
|
412 | - * @param bool $hidden |
|
413 | - * @return array |
|
414 | - */ |
|
415 | - public function allFiles($directory, $hidden = false) |
|
416 | - { |
|
417 | - return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory), false); |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Get all of the directories within a given directory. |
|
422 | - * |
|
423 | - * @param string $directory |
|
424 | - * @return array |
|
425 | - */ |
|
426 | - public function directories($directory) |
|
427 | - { |
|
428 | - $directories = []; |
|
429 | - |
|
430 | - foreach (Finder::create()->in($directory)->directories()->depth(0) as $dir) { |
|
431 | - $directories[] = $dir->getPathname(); |
|
432 | - } |
|
433 | - |
|
434 | - return $directories; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Create a directory. |
|
439 | - * |
|
440 | - * @param string $path |
|
441 | - * @param int $mode |
|
442 | - * @param bool $recursive |
|
443 | - * @param bool $force |
|
444 | - * @return bool |
|
445 | - */ |
|
446 | - public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false) |
|
447 | - { |
|
448 | - if ($force) { |
|
449 | - return @mkdir($path, $mode, $recursive); |
|
450 | - } |
|
451 | - |
|
452 | - return mkdir($path, $mode, $recursive); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Move a directory. |
|
457 | - * |
|
458 | - * @param string $from |
|
459 | - * @param string $to |
|
460 | - * @param bool $overwrite |
|
461 | - * @return bool |
|
462 | - */ |
|
463 | - public function moveDirectory($from, $to, $overwrite = false) |
|
464 | - { |
|
465 | - if ($overwrite && $this->isDirectory($to)) { |
|
466 | - if (! $this->deleteDirectory($to)) { |
|
467 | - return false; |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - return @rename($from, $to) === true; |
|
472 | - } |
|
473 | - |
|
474 | - /** |
|
475 | - * Copy a directory from one location to another. |
|
476 | - * |
|
477 | - * @param string $directory |
|
478 | - * @param string $destination |
|
479 | - * @param int $options |
|
480 | - * @return bool |
|
481 | - */ |
|
482 | - public function copyDirectory($directory, $destination, $options = null) |
|
483 | - { |
|
484 | - if (! $this->isDirectory($directory)) { |
|
485 | - return false; |
|
486 | - } |
|
487 | - |
|
488 | - $options = $options ?: FilesystemIterator::SKIP_DOTS; |
|
489 | - |
|
490 | - // If the destination directory does not actually exist, we will go ahead and |
|
491 | - // create it recursively, which just gets the destination prepared to copy |
|
492 | - // the files over. Once we make the directory we'll proceed the copying. |
|
493 | - if (! $this->isDirectory($destination)) { |
|
494 | - $this->makeDirectory($destination, 0777, true); |
|
495 | - } |
|
496 | - |
|
497 | - $items = new FilesystemIterator($directory, $options); |
|
498 | - |
|
499 | - foreach ($items as $item) { |
|
500 | - // As we spin through items, we will check to see if the current file is actually |
|
501 | - // a directory or a file. When it is actually a directory we will need to call |
|
502 | - // back into this function recursively to keep copying these nested folders. |
|
503 | - $target = $destination.'/'.$item->getBasename(); |
|
504 | - |
|
505 | - if ($item->isDir()) { |
|
506 | - $path = $item->getPathname(); |
|
507 | - |
|
508 | - if (! $this->copyDirectory($path, $target, $options)) { |
|
509 | - return false; |
|
510 | - } |
|
511 | - } |
|
512 | - |
|
513 | - // If the current items is just a regular file, we will just copy this to the new |
|
514 | - // location and keep looping. If for some reason the copy fails we'll bail out |
|
515 | - // and return false, so the developer is aware that the copy process failed. |
|
516 | - else { |
|
517 | - if (! $this->copy($item->getPathname(), $target)) { |
|
518 | - return false; |
|
519 | - } |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - return true; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Recursively delete a directory. |
|
528 | - * |
|
529 | - * The directory itself may be optionally preserved. |
|
530 | - * |
|
531 | - * @param string $directory |
|
532 | - * @param bool $preserve |
|
533 | - * @return bool |
|
534 | - */ |
|
535 | - public function deleteDirectory($directory, $preserve = false) |
|
536 | - { |
|
537 | - if (! $this->isDirectory($directory)) { |
|
538 | - return false; |
|
539 | - } |
|
540 | - |
|
541 | - $items = new FilesystemIterator($directory); |
|
542 | - |
|
543 | - foreach ($items as $item) { |
|
544 | - // If the item is a directory, we can just recurse into the function and |
|
545 | - // delete that sub-directory otherwise we'll just delete the file and |
|
546 | - // keep iterating through each file until the directory is cleaned. |
|
547 | - if ($item->isDir() && ! $item->isLink()) { |
|
548 | - $this->deleteDirectory($item->getPathname()); |
|
549 | - } |
|
550 | - |
|
551 | - // If the item is just a file, we can go ahead and delete it since we're |
|
552 | - // just looping through and waxing all of the files in this directory |
|
553 | - // and calling directories recursively, so we delete the real path. |
|
554 | - else { |
|
555 | - $this->delete($item->getPathname()); |
|
556 | - } |
|
557 | - } |
|
558 | - |
|
559 | - if (! $preserve) { |
|
560 | - @rmdir($directory); |
|
561 | - } |
|
562 | - |
|
563 | - return true; |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Empty the specified directory of all files and folders. |
|
568 | - * |
|
569 | - * @param string $directory |
|
570 | - * @return bool |
|
571 | - */ |
|
572 | - public function cleanDirectory($directory) |
|
573 | - { |
|
574 | - return $this->deleteDirectory($directory, true); |
|
575 | - } |
|
19 | + use Macroable; |
|
20 | + |
|
21 | + /** |
|
22 | + * Determine if a file or directory exists. |
|
23 | + * |
|
24 | + * @param string $path |
|
25 | + * @return bool |
|
26 | + */ |
|
27 | + public function exists($path) |
|
28 | + { |
|
29 | + return file_exists($path); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Get the contents of a file. |
|
34 | + * |
|
35 | + * @param string $path |
|
36 | + * @param bool $lock |
|
37 | + * @return string |
|
38 | + * |
|
39 | + * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
|
40 | + */ |
|
41 | + public function get($path, $lock = false) |
|
42 | + { |
|
43 | + if ($this->isFile($path)) { |
|
44 | + return $lock ? $this->sharedGet($path) : file_get_contents($path); |
|
45 | + } |
|
46 | + |
|
47 | + throw new FileNotFoundException("File does not exist at path {$path}"); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Get contents of a file with shared access. |
|
52 | + * |
|
53 | + * @param string $path |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function sharedGet($path) |
|
57 | + { |
|
58 | + $contents = ''; |
|
59 | + |
|
60 | + $handle = fopen($path, 'rb'); |
|
61 | + |
|
62 | + if ($handle) { |
|
63 | + try { |
|
64 | + if (flock($handle, LOCK_SH)) { |
|
65 | + clearstatcache(true, $path); |
|
66 | + |
|
67 | + $contents = fread($handle, $this->size($path) ?: 1); |
|
68 | + |
|
69 | + flock($handle, LOCK_UN); |
|
70 | + } |
|
71 | + } finally { |
|
72 | + fclose($handle); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + return $contents; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Get the returned value of a file. |
|
81 | + * |
|
82 | + * @param string $path |
|
83 | + * @return mixed |
|
84 | + * |
|
85 | + * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
|
86 | + */ |
|
87 | + public function getRequire($path) |
|
88 | + { |
|
89 | + if ($this->isFile($path)) { |
|
90 | + return require $path; |
|
91 | + } |
|
92 | + |
|
93 | + throw new FileNotFoundException("File does not exist at path {$path}"); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Require the given file once. |
|
98 | + * |
|
99 | + * @param string $file |
|
100 | + * @return mixed |
|
101 | + */ |
|
102 | + public function requireOnce($file) |
|
103 | + { |
|
104 | + require_once $file; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get the MD5 hash of the file at the given path. |
|
109 | + * |
|
110 | + * @param string $path |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function hash($path) |
|
114 | + { |
|
115 | + return md5_file($path); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Write the contents of a file. |
|
120 | + * |
|
121 | + * @param string $path |
|
122 | + * @param string $contents |
|
123 | + * @param bool $lock |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + public function put($path, $contents, $lock = false) |
|
127 | + { |
|
128 | + return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Prepend to a file. |
|
133 | + * |
|
134 | + * @param string $path |
|
135 | + * @param string $data |
|
136 | + * @return int |
|
137 | + */ |
|
138 | + public function prepend($path, $data) |
|
139 | + { |
|
140 | + if ($this->exists($path)) { |
|
141 | + return $this->put($path, $data.$this->get($path)); |
|
142 | + } |
|
143 | + |
|
144 | + return $this->put($path, $data); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Append to a file. |
|
149 | + * |
|
150 | + * @param string $path |
|
151 | + * @param string $data |
|
152 | + * @return int |
|
153 | + */ |
|
154 | + public function append($path, $data) |
|
155 | + { |
|
156 | + return file_put_contents($path, $data, FILE_APPEND); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Get or set UNIX mode of a file or directory. |
|
161 | + * |
|
162 | + * @param string $path |
|
163 | + * @param int $mode |
|
164 | + * @return mixed |
|
165 | + */ |
|
166 | + public function chmod($path, $mode = null) |
|
167 | + { |
|
168 | + if ($mode) { |
|
169 | + return chmod($path, $mode); |
|
170 | + } |
|
171 | + |
|
172 | + return substr(sprintf('%o', fileperms($path)), -4); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Delete the file at a given path. |
|
177 | + * |
|
178 | + * @param string|array $paths |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function delete($paths) |
|
182 | + { |
|
183 | + $paths = is_array($paths) ? $paths : func_get_args(); |
|
184 | + |
|
185 | + $success = true; |
|
186 | + |
|
187 | + foreach ($paths as $path) { |
|
188 | + try { |
|
189 | + if (! @unlink($path)) { |
|
190 | + $success = false; |
|
191 | + } |
|
192 | + } catch (ErrorException $e) { |
|
193 | + $success = false; |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + return $success; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Move a file to a new location. |
|
202 | + * |
|
203 | + * @param string $path |
|
204 | + * @param string $target |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function move($path, $target) |
|
208 | + { |
|
209 | + return rename($path, $target); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Copy a file to a new location. |
|
214 | + * |
|
215 | + * @param string $path |
|
216 | + * @param string $target |
|
217 | + * @return bool |
|
218 | + */ |
|
219 | + public function copy($path, $target) |
|
220 | + { |
|
221 | + return copy($path, $target); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Create a hard link to the target file or directory. |
|
226 | + * |
|
227 | + * @param string $target |
|
228 | + * @param string $link |
|
229 | + * @return void |
|
230 | + */ |
|
231 | + public function link($target, $link) |
|
232 | + { |
|
233 | + if (! windows_os()) { |
|
234 | + return symlink($target, $link); |
|
235 | + } |
|
236 | + |
|
237 | + $mode = $this->isDirectory($target) ? 'J' : 'H'; |
|
238 | + |
|
239 | + exec("mklink /{$mode} \"{$link}\" \"{$target}\""); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Extract the file name from a file path. |
|
244 | + * |
|
245 | + * @param string $path |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function name($path) |
|
249 | + { |
|
250 | + return pathinfo($path, PATHINFO_FILENAME); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Extract the trailing name component from a file path. |
|
255 | + * |
|
256 | + * @param string $path |
|
257 | + * @return string |
|
258 | + */ |
|
259 | + public function basename($path) |
|
260 | + { |
|
261 | + return pathinfo($path, PATHINFO_BASENAME); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Extract the parent directory from a file path. |
|
266 | + * |
|
267 | + * @param string $path |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function dirname($path) |
|
271 | + { |
|
272 | + return pathinfo($path, PATHINFO_DIRNAME); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Extract the file extension from a file path. |
|
277 | + * |
|
278 | + * @param string $path |
|
279 | + * @return string |
|
280 | + */ |
|
281 | + public function extension($path) |
|
282 | + { |
|
283 | + return pathinfo($path, PATHINFO_EXTENSION); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Get the file type of a given file. |
|
288 | + * |
|
289 | + * @param string $path |
|
290 | + * @return string |
|
291 | + */ |
|
292 | + public function type($path) |
|
293 | + { |
|
294 | + return filetype($path); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get the mime-type of a given file. |
|
299 | + * |
|
300 | + * @param string $path |
|
301 | + * @return string|false |
|
302 | + */ |
|
303 | + public function mimeType($path) |
|
304 | + { |
|
305 | + return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get the file size of a given file. |
|
310 | + * |
|
311 | + * @param string $path |
|
312 | + * @return int |
|
313 | + */ |
|
314 | + public function size($path) |
|
315 | + { |
|
316 | + return filesize($path); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Get the file's last modification time. |
|
321 | + * |
|
322 | + * @param string $path |
|
323 | + * @return int |
|
324 | + */ |
|
325 | + public function lastModified($path) |
|
326 | + { |
|
327 | + return filemtime($path); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Determine if the given path is a directory. |
|
332 | + * |
|
333 | + * @param string $directory |
|
334 | + * @return bool |
|
335 | + */ |
|
336 | + public function isDirectory($directory) |
|
337 | + { |
|
338 | + return is_dir($directory); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Determine if the given path is readable. |
|
343 | + * |
|
344 | + * @param string $path |
|
345 | + * @return bool |
|
346 | + */ |
|
347 | + public function isReadable($path) |
|
348 | + { |
|
349 | + return is_readable($path); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Determine if the given path is writable. |
|
354 | + * |
|
355 | + * @param string $path |
|
356 | + * @return bool |
|
357 | + */ |
|
358 | + public function isWritable($path) |
|
359 | + { |
|
360 | + return is_writable($path); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Determine if the given path is a file. |
|
365 | + * |
|
366 | + * @param string $file |
|
367 | + * @return bool |
|
368 | + */ |
|
369 | + public function isFile($file) |
|
370 | + { |
|
371 | + return is_file($file); |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Find path names matching a given pattern. |
|
376 | + * |
|
377 | + * @param string $pattern |
|
378 | + * @param int $flags |
|
379 | + * @return array |
|
380 | + */ |
|
381 | + public function glob($pattern, $flags = 0) |
|
382 | + { |
|
383 | + return glob($pattern, $flags); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Get an array of all files in a directory. |
|
388 | + * |
|
389 | + * @param string $directory |
|
390 | + * @return array |
|
391 | + */ |
|
392 | + public function files($directory) |
|
393 | + { |
|
394 | + $glob = glob($directory.DIRECTORY_SEPARATOR.'*'); |
|
395 | + |
|
396 | + if ($glob === false) { |
|
397 | + return []; |
|
398 | + } |
|
399 | + |
|
400 | + // To get the appropriate files, we'll simply glob the directory and filter |
|
401 | + // out any "files" that are not truly files so we do not end up with any |
|
402 | + // directories in our list, but only true files within the directory. |
|
403 | + return array_filter($glob, function ($file) { |
|
404 | + return filetype($file) == 'file'; |
|
405 | + }); |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * Get all of the files from the given directory (recursive). |
|
410 | + * |
|
411 | + * @param string $directory |
|
412 | + * @param bool $hidden |
|
413 | + * @return array |
|
414 | + */ |
|
415 | + public function allFiles($directory, $hidden = false) |
|
416 | + { |
|
417 | + return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory), false); |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Get all of the directories within a given directory. |
|
422 | + * |
|
423 | + * @param string $directory |
|
424 | + * @return array |
|
425 | + */ |
|
426 | + public function directories($directory) |
|
427 | + { |
|
428 | + $directories = []; |
|
429 | + |
|
430 | + foreach (Finder::create()->in($directory)->directories()->depth(0) as $dir) { |
|
431 | + $directories[] = $dir->getPathname(); |
|
432 | + } |
|
433 | + |
|
434 | + return $directories; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Create a directory. |
|
439 | + * |
|
440 | + * @param string $path |
|
441 | + * @param int $mode |
|
442 | + * @param bool $recursive |
|
443 | + * @param bool $force |
|
444 | + * @return bool |
|
445 | + */ |
|
446 | + public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false) |
|
447 | + { |
|
448 | + if ($force) { |
|
449 | + return @mkdir($path, $mode, $recursive); |
|
450 | + } |
|
451 | + |
|
452 | + return mkdir($path, $mode, $recursive); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Move a directory. |
|
457 | + * |
|
458 | + * @param string $from |
|
459 | + * @param string $to |
|
460 | + * @param bool $overwrite |
|
461 | + * @return bool |
|
462 | + */ |
|
463 | + public function moveDirectory($from, $to, $overwrite = false) |
|
464 | + { |
|
465 | + if ($overwrite && $this->isDirectory($to)) { |
|
466 | + if (! $this->deleteDirectory($to)) { |
|
467 | + return false; |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + return @rename($from, $to) === true; |
|
472 | + } |
|
473 | + |
|
474 | + /** |
|
475 | + * Copy a directory from one location to another. |
|
476 | + * |
|
477 | + * @param string $directory |
|
478 | + * @param string $destination |
|
479 | + * @param int $options |
|
480 | + * @return bool |
|
481 | + */ |
|
482 | + public function copyDirectory($directory, $destination, $options = null) |
|
483 | + { |
|
484 | + if (! $this->isDirectory($directory)) { |
|
485 | + return false; |
|
486 | + } |
|
487 | + |
|
488 | + $options = $options ?: FilesystemIterator::SKIP_DOTS; |
|
489 | + |
|
490 | + // If the destination directory does not actually exist, we will go ahead and |
|
491 | + // create it recursively, which just gets the destination prepared to copy |
|
492 | + // the files over. Once we make the directory we'll proceed the copying. |
|
493 | + if (! $this->isDirectory($destination)) { |
|
494 | + $this->makeDirectory($destination, 0777, true); |
|
495 | + } |
|
496 | + |
|
497 | + $items = new FilesystemIterator($directory, $options); |
|
498 | + |
|
499 | + foreach ($items as $item) { |
|
500 | + // As we spin through items, we will check to see if the current file is actually |
|
501 | + // a directory or a file. When it is actually a directory we will need to call |
|
502 | + // back into this function recursively to keep copying these nested folders. |
|
503 | + $target = $destination.'/'.$item->getBasename(); |
|
504 | + |
|
505 | + if ($item->isDir()) { |
|
506 | + $path = $item->getPathname(); |
|
507 | + |
|
508 | + if (! $this->copyDirectory($path, $target, $options)) { |
|
509 | + return false; |
|
510 | + } |
|
511 | + } |
|
512 | + |
|
513 | + // If the current items is just a regular file, we will just copy this to the new |
|
514 | + // location and keep looping. If for some reason the copy fails we'll bail out |
|
515 | + // and return false, so the developer is aware that the copy process failed. |
|
516 | + else { |
|
517 | + if (! $this->copy($item->getPathname(), $target)) { |
|
518 | + return false; |
|
519 | + } |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + return true; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Recursively delete a directory. |
|
528 | + * |
|
529 | + * The directory itself may be optionally preserved. |
|
530 | + * |
|
531 | + * @param string $directory |
|
532 | + * @param bool $preserve |
|
533 | + * @return bool |
|
534 | + */ |
|
535 | + public function deleteDirectory($directory, $preserve = false) |
|
536 | + { |
|
537 | + if (! $this->isDirectory($directory)) { |
|
538 | + return false; |
|
539 | + } |
|
540 | + |
|
541 | + $items = new FilesystemIterator($directory); |
|
542 | + |
|
543 | + foreach ($items as $item) { |
|
544 | + // If the item is a directory, we can just recurse into the function and |
|
545 | + // delete that sub-directory otherwise we'll just delete the file and |
|
546 | + // keep iterating through each file until the directory is cleaned. |
|
547 | + if ($item->isDir() && ! $item->isLink()) { |
|
548 | + $this->deleteDirectory($item->getPathname()); |
|
549 | + } |
|
550 | + |
|
551 | + // If the item is just a file, we can go ahead and delete it since we're |
|
552 | + // just looping through and waxing all of the files in this directory |
|
553 | + // and calling directories recursively, so we delete the real path. |
|
554 | + else { |
|
555 | + $this->delete($item->getPathname()); |
|
556 | + } |
|
557 | + } |
|
558 | + |
|
559 | + if (! $preserve) { |
|
560 | + @rmdir($directory); |
|
561 | + } |
|
562 | + |
|
563 | + return true; |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Empty the specified directory of all files and folders. |
|
568 | + * |
|
569 | + * @param string $directory |
|
570 | + * @return bool |
|
571 | + */ |
|
572 | + public function cleanDirectory($directory) |
|
573 | + { |
|
574 | + return $this->deleteDirectory($directory, true); |
|
575 | + } |
|
576 | 576 | } |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | * @param string $path |
25 | 25 | * @return bool |
26 | 26 | */ |
27 | - public function exists($path) |
|
27 | + public function exists( $path ) |
|
28 | 28 | { |
29 | - return file_exists($path); |
|
29 | + return file_exists( $path ); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
40 | 40 | */ |
41 | - public function get($path, $lock = false) |
|
41 | + public function get( $path, $lock = false ) |
|
42 | 42 | { |
43 | - if ($this->isFile($path)) { |
|
44 | - return $lock ? $this->sharedGet($path) : file_get_contents($path); |
|
43 | + if ( $this->isFile( $path ) ) { |
|
44 | + return $lock ? $this->sharedGet( $path ) : file_get_contents( $path ); |
|
45 | 45 | } |
46 | 46 | |
47 | - throw new FileNotFoundException("File does not exist at path {$path}"); |
|
47 | + throw new FileNotFoundException( "File does not exist at path {$path}" ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | * @param string $path |
54 | 54 | * @return string |
55 | 55 | */ |
56 | - public function sharedGet($path) |
|
56 | + public function sharedGet( $path ) |
|
57 | 57 | { |
58 | 58 | $contents = ''; |
59 | 59 | |
60 | - $handle = fopen($path, 'rb'); |
|
60 | + $handle = fopen( $path, 'rb' ); |
|
61 | 61 | |
62 | - if ($handle) { |
|
62 | + if ( $handle ) { |
|
63 | 63 | try { |
64 | - if (flock($handle, LOCK_SH)) { |
|
65 | - clearstatcache(true, $path); |
|
64 | + if ( flock( $handle, LOCK_SH ) ) { |
|
65 | + clearstatcache( true, $path ); |
|
66 | 66 | |
67 | - $contents = fread($handle, $this->size($path) ?: 1); |
|
67 | + $contents = fread( $handle, $this->size( $path ) ?: 1 ); |
|
68 | 68 | |
69 | - flock($handle, LOCK_UN); |
|
69 | + flock( $handle, LOCK_UN ); |
|
70 | 70 | } |
71 | 71 | } finally { |
72 | - fclose($handle); |
|
72 | + fclose( $handle ); |
|
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
86 | 86 | */ |
87 | - public function getRequire($path) |
|
87 | + public function getRequire( $path ) |
|
88 | 88 | { |
89 | - if ($this->isFile($path)) { |
|
89 | + if ( $this->isFile( $path ) ) { |
|
90 | 90 | return require $path; |
91 | 91 | } |
92 | 92 | |
93 | - throw new FileNotFoundException("File does not exist at path {$path}"); |
|
93 | + throw new FileNotFoundException( "File does not exist at path {$path}" ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param string $file |
100 | 100 | * @return mixed |
101 | 101 | */ |
102 | - public function requireOnce($file) |
|
102 | + public function requireOnce( $file ) |
|
103 | 103 | { |
104 | 104 | require_once $file; |
105 | 105 | } |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * @param string $path |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - public function hash($path) |
|
113 | + public function hash( $path ) |
|
114 | 114 | { |
115 | - return md5_file($path); |
|
115 | + return md5_file( $path ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | * @param bool $lock |
124 | 124 | * @return int |
125 | 125 | */ |
126 | - public function put($path, $contents, $lock = false) |
|
126 | + public function put( $path, $contents, $lock = false ) |
|
127 | 127 | { |
128 | - return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); |
|
128 | + return file_put_contents( $path, $contents, $lock ? LOCK_EX : 0 ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | * @param string $data |
136 | 136 | * @return int |
137 | 137 | */ |
138 | - public function prepend($path, $data) |
|
138 | + public function prepend( $path, $data ) |
|
139 | 139 | { |
140 | - if ($this->exists($path)) { |
|
141 | - return $this->put($path, $data.$this->get($path)); |
|
140 | + if ( $this->exists( $path ) ) { |
|
141 | + return $this->put( $path, $data . $this->get( $path ) ); |
|
142 | 142 | } |
143 | 143 | |
144 | - return $this->put($path, $data); |
|
144 | + return $this->put( $path, $data ); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -151,9 +151,9 @@ discard block |
||
151 | 151 | * @param string $data |
152 | 152 | * @return int |
153 | 153 | */ |
154 | - public function append($path, $data) |
|
154 | + public function append( $path, $data ) |
|
155 | 155 | { |
156 | - return file_put_contents($path, $data, FILE_APPEND); |
|
156 | + return file_put_contents( $path, $data, FILE_APPEND ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | * @param int $mode |
164 | 164 | * @return mixed |
165 | 165 | */ |
166 | - public function chmod($path, $mode = null) |
|
166 | + public function chmod( $path, $mode = null ) |
|
167 | 167 | { |
168 | - if ($mode) { |
|
169 | - return chmod($path, $mode); |
|
168 | + if ( $mode ) { |
|
169 | + return chmod( $path, $mode ); |
|
170 | 170 | } |
171 | 171 | |
172 | - return substr(sprintf('%o', fileperms($path)), -4); |
|
172 | + return substr( sprintf( '%o', fileperms( $path ) ), -4 ); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -178,18 +178,18 @@ discard block |
||
178 | 178 | * @param string|array $paths |
179 | 179 | * @return bool |
180 | 180 | */ |
181 | - public function delete($paths) |
|
181 | + public function delete( $paths ) |
|
182 | 182 | { |
183 | - $paths = is_array($paths) ? $paths : func_get_args(); |
|
183 | + $paths = is_array( $paths ) ? $paths : func_get_args(); |
|
184 | 184 | |
185 | 185 | $success = true; |
186 | 186 | |
187 | - foreach ($paths as $path) { |
|
187 | + foreach ( $paths as $path ) { |
|
188 | 188 | try { |
189 | - if (! @unlink($path)) { |
|
189 | + if ( ! @unlink( $path ) ) { |
|
190 | 190 | $success = false; |
191 | 191 | } |
192 | - } catch (ErrorException $e) { |
|
192 | + } catch ( ErrorException $e ) { |
|
193 | 193 | $success = false; |
194 | 194 | } |
195 | 195 | } |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * @param string $target |
205 | 205 | * @return bool |
206 | 206 | */ |
207 | - public function move($path, $target) |
|
207 | + public function move( $path, $target ) |
|
208 | 208 | { |
209 | - return rename($path, $target); |
|
209 | + return rename( $path, $target ); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * @param string $target |
217 | 217 | * @return bool |
218 | 218 | */ |
219 | - public function copy($path, $target) |
|
219 | + public function copy( $path, $target ) |
|
220 | 220 | { |
221 | - return copy($path, $target); |
|
221 | + return copy( $path, $target ); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -228,15 +228,15 @@ discard block |
||
228 | 228 | * @param string $link |
229 | 229 | * @return void |
230 | 230 | */ |
231 | - public function link($target, $link) |
|
231 | + public function link( $target, $link ) |
|
232 | 232 | { |
233 | - if (! windows_os()) { |
|
234 | - return symlink($target, $link); |
|
233 | + if ( ! windows_os() ) { |
|
234 | + return symlink( $target, $link ); |
|
235 | 235 | } |
236 | 236 | |
237 | - $mode = $this->isDirectory($target) ? 'J' : 'H'; |
|
237 | + $mode = $this->isDirectory( $target ) ? 'J' : 'H'; |
|
238 | 238 | |
239 | - exec("mklink /{$mode} \"{$link}\" \"{$target}\""); |
|
239 | + exec( "mklink /{$mode} \"{$link}\" \"{$target}\"" ); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | * @param string $path |
246 | 246 | * @return string |
247 | 247 | */ |
248 | - public function name($path) |
|
248 | + public function name( $path ) |
|
249 | 249 | { |
250 | - return pathinfo($path, PATHINFO_FILENAME); |
|
250 | + return pathinfo( $path, PATHINFO_FILENAME ); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | * @param string $path |
257 | 257 | * @return string |
258 | 258 | */ |
259 | - public function basename($path) |
|
259 | + public function basename( $path ) |
|
260 | 260 | { |
261 | - return pathinfo($path, PATHINFO_BASENAME); |
|
261 | + return pathinfo( $path, PATHINFO_BASENAME ); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | * @param string $path |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - public function dirname($path) |
|
270 | + public function dirname( $path ) |
|
271 | 271 | { |
272 | - return pathinfo($path, PATHINFO_DIRNAME); |
|
272 | + return pathinfo( $path, PATHINFO_DIRNAME ); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | * @param string $path |
279 | 279 | * @return string |
280 | 280 | */ |
281 | - public function extension($path) |
|
281 | + public function extension( $path ) |
|
282 | 282 | { |
283 | - return pathinfo($path, PATHINFO_EXTENSION); |
|
283 | + return pathinfo( $path, PATHINFO_EXTENSION ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -289,9 +289,9 @@ discard block |
||
289 | 289 | * @param string $path |
290 | 290 | * @return string |
291 | 291 | */ |
292 | - public function type($path) |
|
292 | + public function type( $path ) |
|
293 | 293 | { |
294 | - return filetype($path); |
|
294 | + return filetype( $path ); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -300,9 +300,9 @@ discard block |
||
300 | 300 | * @param string $path |
301 | 301 | * @return string|false |
302 | 302 | */ |
303 | - public function mimeType($path) |
|
303 | + public function mimeType( $path ) |
|
304 | 304 | { |
305 | - return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); |
|
305 | + return finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $path ); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -311,9 +311,9 @@ discard block |
||
311 | 311 | * @param string $path |
312 | 312 | * @return int |
313 | 313 | */ |
314 | - public function size($path) |
|
314 | + public function size( $path ) |
|
315 | 315 | { |
316 | - return filesize($path); |
|
316 | + return filesize( $path ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | * @param string $path |
323 | 323 | * @return int |
324 | 324 | */ |
325 | - public function lastModified($path) |
|
325 | + public function lastModified( $path ) |
|
326 | 326 | { |
327 | - return filemtime($path); |
|
327 | + return filemtime( $path ); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -333,9 +333,9 @@ discard block |
||
333 | 333 | * @param string $directory |
334 | 334 | * @return bool |
335 | 335 | */ |
336 | - public function isDirectory($directory) |
|
336 | + public function isDirectory( $directory ) |
|
337 | 337 | { |
338 | - return is_dir($directory); |
|
338 | + return is_dir( $directory ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | * @param string $path |
345 | 345 | * @return bool |
346 | 346 | */ |
347 | - public function isReadable($path) |
|
347 | + public function isReadable( $path ) |
|
348 | 348 | { |
349 | - return is_readable($path); |
|
349 | + return is_readable( $path ); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | * @param string $path |
356 | 356 | * @return bool |
357 | 357 | */ |
358 | - public function isWritable($path) |
|
358 | + public function isWritable( $path ) |
|
359 | 359 | { |
360 | - return is_writable($path); |
|
360 | + return is_writable( $path ); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -366,9 +366,9 @@ discard block |
||
366 | 366 | * @param string $file |
367 | 367 | * @return bool |
368 | 368 | */ |
369 | - public function isFile($file) |
|
369 | + public function isFile( $file ) |
|
370 | 370 | { |
371 | - return is_file($file); |
|
371 | + return is_file( $file ); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -378,9 +378,9 @@ discard block |
||
378 | 378 | * @param int $flags |
379 | 379 | * @return array |
380 | 380 | */ |
381 | - public function glob($pattern, $flags = 0) |
|
381 | + public function glob( $pattern, $flags = 0 ) |
|
382 | 382 | { |
383 | - return glob($pattern, $flags); |
|
383 | + return glob( $pattern, $flags ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -389,19 +389,19 @@ discard block |
||
389 | 389 | * @param string $directory |
390 | 390 | * @return array |
391 | 391 | */ |
392 | - public function files($directory) |
|
392 | + public function files( $directory ) |
|
393 | 393 | { |
394 | - $glob = glob($directory.DIRECTORY_SEPARATOR.'*'); |
|
394 | + $glob = glob( $directory . DIRECTORY_SEPARATOR . '*' ); |
|
395 | 395 | |
396 | - if ($glob === false) { |
|
397 | - return []; |
|
396 | + if ( $glob === false ) { |
|
397 | + return [ ]; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | // To get the appropriate files, we'll simply glob the directory and filter |
401 | 401 | // out any "files" that are not truly files so we do not end up with any |
402 | 402 | // directories in our list, but only true files within the directory. |
403 | - return array_filter($glob, function ($file) { |
|
404 | - return filetype($file) == 'file'; |
|
403 | + return array_filter( $glob, function( $file ) { |
|
404 | + return filetype( $file ) == 'file'; |
|
405 | 405 | }); |
406 | 406 | } |
407 | 407 | |
@@ -412,9 +412,9 @@ discard block |
||
412 | 412 | * @param bool $hidden |
413 | 413 | * @return array |
414 | 414 | */ |
415 | - public function allFiles($directory, $hidden = false) |
|
415 | + public function allFiles( $directory, $hidden = false ) |
|
416 | 416 | { |
417 | - return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory), false); |
|
417 | + return iterator_to_array( Finder::create()->files()->ignoreDotFiles( ! $hidden )->in( $directory ), false ); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
@@ -423,12 +423,12 @@ discard block |
||
423 | 423 | * @param string $directory |
424 | 424 | * @return array |
425 | 425 | */ |
426 | - public function directories($directory) |
|
426 | + public function directories( $directory ) |
|
427 | 427 | { |
428 | - $directories = []; |
|
428 | + $directories = [ ]; |
|
429 | 429 | |
430 | - foreach (Finder::create()->in($directory)->directories()->depth(0) as $dir) { |
|
431 | - $directories[] = $dir->getPathname(); |
|
430 | + foreach ( Finder::create()->in( $directory )->directories()->depth( 0 ) as $dir ) { |
|
431 | + $directories[ ] = $dir->getPathname(); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | return $directories; |
@@ -443,13 +443,13 @@ discard block |
||
443 | 443 | * @param bool $force |
444 | 444 | * @return bool |
445 | 445 | */ |
446 | - public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false) |
|
446 | + public function makeDirectory( $path, $mode = 0755, $recursive = false, $force = false ) |
|
447 | 447 | { |
448 | - if ($force) { |
|
449 | - return @mkdir($path, $mode, $recursive); |
|
448 | + if ( $force ) { |
|
449 | + return @mkdir( $path, $mode, $recursive ); |
|
450 | 450 | } |
451 | 451 | |
452 | - return mkdir($path, $mode, $recursive); |
|
452 | + return mkdir( $path, $mode, $recursive ); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -460,15 +460,15 @@ discard block |
||
460 | 460 | * @param bool $overwrite |
461 | 461 | * @return bool |
462 | 462 | */ |
463 | - public function moveDirectory($from, $to, $overwrite = false) |
|
463 | + public function moveDirectory( $from, $to, $overwrite = false ) |
|
464 | 464 | { |
465 | - if ($overwrite && $this->isDirectory($to)) { |
|
466 | - if (! $this->deleteDirectory($to)) { |
|
465 | + if ( $overwrite && $this->isDirectory( $to ) ) { |
|
466 | + if ( ! $this->deleteDirectory( $to ) ) { |
|
467 | 467 | return false; |
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
471 | - return @rename($from, $to) === true; |
|
471 | + return @rename( $from, $to ) === true; |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -479,9 +479,9 @@ discard block |
||
479 | 479 | * @param int $options |
480 | 480 | * @return bool |
481 | 481 | */ |
482 | - public function copyDirectory($directory, $destination, $options = null) |
|
482 | + public function copyDirectory( $directory, $destination, $options = null ) |
|
483 | 483 | { |
484 | - if (! $this->isDirectory($directory)) { |
|
484 | + if ( ! $this->isDirectory( $directory ) ) { |
|
485 | 485 | return false; |
486 | 486 | } |
487 | 487 | |
@@ -490,22 +490,22 @@ discard block |
||
490 | 490 | // If the destination directory does not actually exist, we will go ahead and |
491 | 491 | // create it recursively, which just gets the destination prepared to copy |
492 | 492 | // the files over. Once we make the directory we'll proceed the copying. |
493 | - if (! $this->isDirectory($destination)) { |
|
494 | - $this->makeDirectory($destination, 0777, true); |
|
493 | + if ( ! $this->isDirectory( $destination ) ) { |
|
494 | + $this->makeDirectory( $destination, 0777, true ); |
|
495 | 495 | } |
496 | 496 | |
497 | - $items = new FilesystemIterator($directory, $options); |
|
497 | + $items = new FilesystemIterator( $directory, $options ); |
|
498 | 498 | |
499 | - foreach ($items as $item) { |
|
499 | + foreach ( $items as $item ) { |
|
500 | 500 | // As we spin through items, we will check to see if the current file is actually |
501 | 501 | // a directory or a file. When it is actually a directory we will need to call |
502 | 502 | // back into this function recursively to keep copying these nested folders. |
503 | - $target = $destination.'/'.$item->getBasename(); |
|
503 | + $target = $destination . '/' . $item->getBasename(); |
|
504 | 504 | |
505 | - if ($item->isDir()) { |
|
505 | + if ( $item->isDir() ) { |
|
506 | 506 | $path = $item->getPathname(); |
507 | 507 | |
508 | - if (! $this->copyDirectory($path, $target, $options)) { |
|
508 | + if ( ! $this->copyDirectory( $path, $target, $options ) ) { |
|
509 | 509 | return false; |
510 | 510 | } |
511 | 511 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | // location and keep looping. If for some reason the copy fails we'll bail out |
515 | 515 | // and return false, so the developer is aware that the copy process failed. |
516 | 516 | else { |
517 | - if (! $this->copy($item->getPathname(), $target)) { |
|
517 | + if ( ! $this->copy( $item->getPathname(), $target ) ) { |
|
518 | 518 | return false; |
519 | 519 | } |
520 | 520 | } |
@@ -532,32 +532,32 @@ discard block |
||
532 | 532 | * @param bool $preserve |
533 | 533 | * @return bool |
534 | 534 | */ |
535 | - public function deleteDirectory($directory, $preserve = false) |
|
535 | + public function deleteDirectory( $directory, $preserve = false ) |
|
536 | 536 | { |
537 | - if (! $this->isDirectory($directory)) { |
|
537 | + if ( ! $this->isDirectory( $directory ) ) { |
|
538 | 538 | return false; |
539 | 539 | } |
540 | 540 | |
541 | - $items = new FilesystemIterator($directory); |
|
541 | + $items = new FilesystemIterator( $directory ); |
|
542 | 542 | |
543 | - foreach ($items as $item) { |
|
543 | + foreach ( $items as $item ) { |
|
544 | 544 | // If the item is a directory, we can just recurse into the function and |
545 | 545 | // delete that sub-directory otherwise we'll just delete the file and |
546 | 546 | // keep iterating through each file until the directory is cleaned. |
547 | - if ($item->isDir() && ! $item->isLink()) { |
|
548 | - $this->deleteDirectory($item->getPathname()); |
|
547 | + if ( $item->isDir() && ! $item->isLink() ) { |
|
548 | + $this->deleteDirectory( $item->getPathname() ); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | // If the item is just a file, we can go ahead and delete it since we're |
552 | 552 | // just looping through and waxing all of the files in this directory |
553 | 553 | // and calling directories recursively, so we delete the real path. |
554 | 554 | else { |
555 | - $this->delete($item->getPathname()); |
|
555 | + $this->delete( $item->getPathname() ); |
|
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
559 | - if (! $preserve) { |
|
560 | - @rmdir($directory); |
|
559 | + if ( ! $preserve ) { |
|
560 | + @rmdir( $directory ); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | return true; |
@@ -569,8 +569,8 @@ discard block |
||
569 | 569 | * @param string $directory |
570 | 570 | * @return bool |
571 | 571 | */ |
572 | - public function cleanDirectory($directory) |
|
572 | + public function cleanDirectory( $directory ) |
|
573 | 573 | { |
574 | - return $this->deleteDirectory($directory, true); |
|
574 | + return $this->deleteDirectory( $directory, true ); |
|
575 | 575 | } |
576 | 576 | } |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | use GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Support\Traits\Macroable; |
15 | 15 | use GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException; |
16 | 16 | |
17 | -class Filesystem |
|
18 | -{ |
|
17 | +class Filesystem { |
|
19 | 18 | use Macroable; |
20 | 19 | |
21 | 20 | /** |
@@ -24,8 +23,7 @@ discard block |
||
24 | 23 | * @param string $path |
25 | 24 | * @return bool |
26 | 25 | */ |
27 | - public function exists($path) |
|
28 | - { |
|
26 | + public function exists($path) { |
|
29 | 27 | return file_exists($path); |
30 | 28 | } |
31 | 29 | |
@@ -38,8 +36,7 @@ discard block |
||
38 | 36 | * |
39 | 37 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
40 | 38 | */ |
41 | - public function get($path, $lock = false) |
|
42 | - { |
|
39 | + public function get($path, $lock = false) { |
|
43 | 40 | if ($this->isFile($path)) { |
44 | 41 | return $lock ? $this->sharedGet($path) : file_get_contents($path); |
45 | 42 | } |
@@ -53,8 +50,7 @@ discard block |
||
53 | 50 | * @param string $path |
54 | 51 | * @return string |
55 | 52 | */ |
56 | - public function sharedGet($path) |
|
57 | - { |
|
53 | + public function sharedGet($path) { |
|
58 | 54 | $contents = ''; |
59 | 55 | |
60 | 56 | $handle = fopen($path, 'rb'); |
@@ -84,8 +80,7 @@ discard block |
||
84 | 80 | * |
85 | 81 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException |
86 | 82 | */ |
87 | - public function getRequire($path) |
|
88 | - { |
|
83 | + public function getRequire($path) { |
|
89 | 84 | if ($this->isFile($path)) { |
90 | 85 | return require $path; |
91 | 86 | } |
@@ -99,8 +94,7 @@ discard block |
||
99 | 94 | * @param string $file |
100 | 95 | * @return mixed |
101 | 96 | */ |
102 | - public function requireOnce($file) |
|
103 | - { |
|
97 | + public function requireOnce($file) { |
|
104 | 98 | require_once $file; |
105 | 99 | } |
106 | 100 | |
@@ -110,8 +104,7 @@ discard block |
||
110 | 104 | * @param string $path |
111 | 105 | * @return string |
112 | 106 | */ |
113 | - public function hash($path) |
|
114 | - { |
|
107 | + public function hash($path) { |
|
115 | 108 | return md5_file($path); |
116 | 109 | } |
117 | 110 | |
@@ -123,8 +116,7 @@ discard block |
||
123 | 116 | * @param bool $lock |
124 | 117 | * @return int |
125 | 118 | */ |
126 | - public function put($path, $contents, $lock = false) |
|
127 | - { |
|
119 | + public function put($path, $contents, $lock = false) { |
|
128 | 120 | return file_put_contents($path, $contents, $lock ? LOCK_EX : 0); |
129 | 121 | } |
130 | 122 | |
@@ -135,8 +127,7 @@ discard block |
||
135 | 127 | * @param string $data |
136 | 128 | * @return int |
137 | 129 | */ |
138 | - public function prepend($path, $data) |
|
139 | - { |
|
130 | + public function prepend($path, $data) { |
|
140 | 131 | if ($this->exists($path)) { |
141 | 132 | return $this->put($path, $data.$this->get($path)); |
142 | 133 | } |
@@ -151,8 +142,7 @@ discard block |
||
151 | 142 | * @param string $data |
152 | 143 | * @return int |
153 | 144 | */ |
154 | - public function append($path, $data) |
|
155 | - { |
|
145 | + public function append($path, $data) { |
|
156 | 146 | return file_put_contents($path, $data, FILE_APPEND); |
157 | 147 | } |
158 | 148 | |
@@ -163,8 +153,7 @@ discard block |
||
163 | 153 | * @param int $mode |
164 | 154 | * @return mixed |
165 | 155 | */ |
166 | - public function chmod($path, $mode = null) |
|
167 | - { |
|
156 | + public function chmod($path, $mode = null) { |
|
168 | 157 | if ($mode) { |
169 | 158 | return chmod($path, $mode); |
170 | 159 | } |
@@ -178,8 +167,7 @@ discard block |
||
178 | 167 | * @param string|array $paths |
179 | 168 | * @return bool |
180 | 169 | */ |
181 | - public function delete($paths) |
|
182 | - { |
|
170 | + public function delete($paths) { |
|
183 | 171 | $paths = is_array($paths) ? $paths : func_get_args(); |
184 | 172 | |
185 | 173 | $success = true; |
@@ -204,8 +192,7 @@ discard block |
||
204 | 192 | * @param string $target |
205 | 193 | * @return bool |
206 | 194 | */ |
207 | - public function move($path, $target) |
|
208 | - { |
|
195 | + public function move($path, $target) { |
|
209 | 196 | return rename($path, $target); |
210 | 197 | } |
211 | 198 | |
@@ -216,8 +203,7 @@ discard block |
||
216 | 203 | * @param string $target |
217 | 204 | * @return bool |
218 | 205 | */ |
219 | - public function copy($path, $target) |
|
220 | - { |
|
206 | + public function copy($path, $target) { |
|
221 | 207 | return copy($path, $target); |
222 | 208 | } |
223 | 209 | |
@@ -228,8 +214,7 @@ discard block |
||
228 | 214 | * @param string $link |
229 | 215 | * @return void |
230 | 216 | */ |
231 | - public function link($target, $link) |
|
232 | - { |
|
217 | + public function link($target, $link) { |
|
233 | 218 | if (! windows_os()) { |
234 | 219 | return symlink($target, $link); |
235 | 220 | } |
@@ -245,8 +230,7 @@ discard block |
||
245 | 230 | * @param string $path |
246 | 231 | * @return string |
247 | 232 | */ |
248 | - public function name($path) |
|
249 | - { |
|
233 | + public function name($path) { |
|
250 | 234 | return pathinfo($path, PATHINFO_FILENAME); |
251 | 235 | } |
252 | 236 | |
@@ -256,8 +240,7 @@ discard block |
||
256 | 240 | * @param string $path |
257 | 241 | * @return string |
258 | 242 | */ |
259 | - public function basename($path) |
|
260 | - { |
|
243 | + public function basename($path) { |
|
261 | 244 | return pathinfo($path, PATHINFO_BASENAME); |
262 | 245 | } |
263 | 246 | |
@@ -267,8 +250,7 @@ discard block |
||
267 | 250 | * @param string $path |
268 | 251 | * @return string |
269 | 252 | */ |
270 | - public function dirname($path) |
|
271 | - { |
|
253 | + public function dirname($path) { |
|
272 | 254 | return pathinfo($path, PATHINFO_DIRNAME); |
273 | 255 | } |
274 | 256 | |
@@ -278,8 +260,7 @@ discard block |
||
278 | 260 | * @param string $path |
279 | 261 | * @return string |
280 | 262 | */ |
281 | - public function extension($path) |
|
282 | - { |
|
263 | + public function extension($path) { |
|
283 | 264 | return pathinfo($path, PATHINFO_EXTENSION); |
284 | 265 | } |
285 | 266 | |
@@ -289,8 +270,7 @@ discard block |
||
289 | 270 | * @param string $path |
290 | 271 | * @return string |
291 | 272 | */ |
292 | - public function type($path) |
|
293 | - { |
|
273 | + public function type($path) { |
|
294 | 274 | return filetype($path); |
295 | 275 | } |
296 | 276 | |
@@ -300,8 +280,7 @@ discard block |
||
300 | 280 | * @param string $path |
301 | 281 | * @return string|false |
302 | 282 | */ |
303 | - public function mimeType($path) |
|
304 | - { |
|
283 | + public function mimeType($path) { |
|
305 | 284 | return finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); |
306 | 285 | } |
307 | 286 | |
@@ -311,8 +290,7 @@ discard block |
||
311 | 290 | * @param string $path |
312 | 291 | * @return int |
313 | 292 | */ |
314 | - public function size($path) |
|
315 | - { |
|
293 | + public function size($path) { |
|
316 | 294 | return filesize($path); |
317 | 295 | } |
318 | 296 | |
@@ -322,8 +300,7 @@ discard block |
||
322 | 300 | * @param string $path |
323 | 301 | * @return int |
324 | 302 | */ |
325 | - public function lastModified($path) |
|
326 | - { |
|
303 | + public function lastModified($path) { |
|
327 | 304 | return filemtime($path); |
328 | 305 | } |
329 | 306 | |
@@ -333,8 +310,7 @@ discard block |
||
333 | 310 | * @param string $directory |
334 | 311 | * @return bool |
335 | 312 | */ |
336 | - public function isDirectory($directory) |
|
337 | - { |
|
313 | + public function isDirectory($directory) { |
|
338 | 314 | return is_dir($directory); |
339 | 315 | } |
340 | 316 | |
@@ -344,8 +320,7 @@ discard block |
||
344 | 320 | * @param string $path |
345 | 321 | * @return bool |
346 | 322 | */ |
347 | - public function isReadable($path) |
|
348 | - { |
|
323 | + public function isReadable($path) { |
|
349 | 324 | return is_readable($path); |
350 | 325 | } |
351 | 326 | |
@@ -355,8 +330,7 @@ discard block |
||
355 | 330 | * @param string $path |
356 | 331 | * @return bool |
357 | 332 | */ |
358 | - public function isWritable($path) |
|
359 | - { |
|
333 | + public function isWritable($path) { |
|
360 | 334 | return is_writable($path); |
361 | 335 | } |
362 | 336 | |
@@ -366,8 +340,7 @@ discard block |
||
366 | 340 | * @param string $file |
367 | 341 | * @return bool |
368 | 342 | */ |
369 | - public function isFile($file) |
|
370 | - { |
|
343 | + public function isFile($file) { |
|
371 | 344 | return is_file($file); |
372 | 345 | } |
373 | 346 | |
@@ -378,8 +351,7 @@ discard block |
||
378 | 351 | * @param int $flags |
379 | 352 | * @return array |
380 | 353 | */ |
381 | - public function glob($pattern, $flags = 0) |
|
382 | - { |
|
354 | + public function glob($pattern, $flags = 0) { |
|
383 | 355 | return glob($pattern, $flags); |
384 | 356 | } |
385 | 357 | |
@@ -389,8 +361,7 @@ discard block |
||
389 | 361 | * @param string $directory |
390 | 362 | * @return array |
391 | 363 | */ |
392 | - public function files($directory) |
|
393 | - { |
|
364 | + public function files($directory) { |
|
394 | 365 | $glob = glob($directory.DIRECTORY_SEPARATOR.'*'); |
395 | 366 | |
396 | 367 | if ($glob === false) { |
@@ -412,8 +383,7 @@ discard block |
||
412 | 383 | * @param bool $hidden |
413 | 384 | * @return array |
414 | 385 | */ |
415 | - public function allFiles($directory, $hidden = false) |
|
416 | - { |
|
386 | + public function allFiles($directory, $hidden = false) { |
|
417 | 387 | return iterator_to_array(Finder::create()->files()->ignoreDotFiles(! $hidden)->in($directory), false); |
418 | 388 | } |
419 | 389 | |
@@ -423,8 +393,7 @@ discard block |
||
423 | 393 | * @param string $directory |
424 | 394 | * @return array |
425 | 395 | */ |
426 | - public function directories($directory) |
|
427 | - { |
|
396 | + public function directories($directory) { |
|
428 | 397 | $directories = []; |
429 | 398 | |
430 | 399 | foreach (Finder::create()->in($directory)->directories()->depth(0) as $dir) { |
@@ -443,8 +412,7 @@ discard block |
||
443 | 412 | * @param bool $force |
444 | 413 | * @return bool |
445 | 414 | */ |
446 | - public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false) |
|
447 | - { |
|
415 | + public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false) { |
|
448 | 416 | if ($force) { |
449 | 417 | return @mkdir($path, $mode, $recursive); |
450 | 418 | } |
@@ -460,8 +428,7 @@ discard block |
||
460 | 428 | * @param bool $overwrite |
461 | 429 | * @return bool |
462 | 430 | */ |
463 | - public function moveDirectory($from, $to, $overwrite = false) |
|
464 | - { |
|
431 | + public function moveDirectory($from, $to, $overwrite = false) { |
|
465 | 432 | if ($overwrite && $this->isDirectory($to)) { |
466 | 433 | if (! $this->deleteDirectory($to)) { |
467 | 434 | return false; |
@@ -479,8 +446,7 @@ discard block |
||
479 | 446 | * @param int $options |
480 | 447 | * @return bool |
481 | 448 | */ |
482 | - public function copyDirectory($directory, $destination, $options = null) |
|
483 | - { |
|
449 | + public function copyDirectory($directory, $destination, $options = null) { |
|
484 | 450 | if (! $this->isDirectory($directory)) { |
485 | 451 | return false; |
486 | 452 | } |
@@ -532,8 +498,7 @@ discard block |
||
532 | 498 | * @param bool $preserve |
533 | 499 | * @return bool |
534 | 500 | */ |
535 | - public function deleteDirectory($directory, $preserve = false) |
|
536 | - { |
|
501 | + public function deleteDirectory($directory, $preserve = false) { |
|
537 | 502 | if (! $this->isDirectory($directory)) { |
538 | 503 | return false; |
539 | 504 | } |
@@ -569,8 +534,7 @@ discard block |
||
569 | 534 | * @param string $directory |
570 | 535 | * @return bool |
571 | 536 | */ |
572 | - public function cleanDirectory($directory) |
|
573 | - { |
|
537 | + public function cleanDirectory($directory) { |
|
574 | 538 | return $this->deleteDirectory($directory, true); |
575 | 539 | } |
576 | 540 | } |
@@ -18,1211 +18,1211 @@ |
||
18 | 18 | |
19 | 19 | class Container implements ArrayAccess, ContainerContract |
20 | 20 | { |
21 | - /** |
|
22 | - * The current globally available container (if any). |
|
23 | - * |
|
24 | - * @var static |
|
25 | - */ |
|
26 | - protected static $instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * An array of the types that have been resolved. |
|
30 | - * |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $resolved = []; |
|
34 | - |
|
35 | - /** |
|
36 | - * The container's bindings. |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected $bindings = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * The container's method bindings. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $methodBindings = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * The container's shared instances. |
|
51 | - * |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $instances = []; |
|
55 | - |
|
56 | - /** |
|
57 | - * The registered type aliases. |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $aliases = []; |
|
62 | - |
|
63 | - /** |
|
64 | - * The registered aliases keyed by the abstract name. |
|
65 | - * |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $abstractAliases = []; |
|
69 | - |
|
70 | - /** |
|
71 | - * The extension closures for services. |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - protected $extenders = []; |
|
76 | - |
|
77 | - /** |
|
78 | - * All of the registered tags. |
|
79 | - * |
|
80 | - * @var array |
|
81 | - */ |
|
82 | - protected $tags = []; |
|
83 | - |
|
84 | - /** |
|
85 | - * The stack of concretions currently being built. |
|
86 | - * |
|
87 | - * @var array |
|
88 | - */ |
|
89 | - protected $buildStack = []; |
|
90 | - |
|
91 | - /** |
|
92 | - * The parameter override stack. |
|
93 | - * |
|
94 | - * @var array |
|
95 | - */ |
|
96 | - protected $with = []; |
|
97 | - |
|
98 | - /** |
|
99 | - * The contextual binding map. |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - public $contextual = []; |
|
104 | - |
|
105 | - /** |
|
106 | - * All of the registered rebound callbacks. |
|
107 | - * |
|
108 | - * @var array |
|
109 | - */ |
|
110 | - protected $reboundCallbacks = []; |
|
111 | - |
|
112 | - /** |
|
113 | - * All of the global resolving callbacks. |
|
114 | - * |
|
115 | - * @var array |
|
116 | - */ |
|
117 | - protected $globalResolvingCallbacks = []; |
|
118 | - |
|
119 | - /** |
|
120 | - * All of the global after resolving callbacks. |
|
121 | - * |
|
122 | - * @var array |
|
123 | - */ |
|
124 | - protected $globalAfterResolvingCallbacks = []; |
|
125 | - |
|
126 | - /** |
|
127 | - * All of the resolving callbacks by class type. |
|
128 | - * |
|
129 | - * @var array |
|
130 | - */ |
|
131 | - protected $resolvingCallbacks = []; |
|
132 | - |
|
133 | - /** |
|
134 | - * All of the after resolving callbacks by class type. |
|
135 | - * |
|
136 | - * @var array |
|
137 | - */ |
|
138 | - protected $afterResolvingCallbacks = []; |
|
139 | - |
|
140 | - /** |
|
141 | - * Define a contextual binding. |
|
142 | - * |
|
143 | - * @param string $concrete |
|
144 | - * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\ContextualBindingBuilder |
|
145 | - */ |
|
146 | - public function when($concrete) |
|
147 | - { |
|
148 | - return new ContextualBindingBuilder($this, $this->getAlias($concrete)); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Determine if the given abstract type has been bound. |
|
153 | - * |
|
154 | - * @param string $abstract |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function bound($abstract) |
|
158 | - { |
|
159 | - return isset($this->bindings[$abstract]) || |
|
160 | - isset($this->instances[$abstract]) || |
|
161 | - $this->isAlias($abstract); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Determine if the given abstract type has been resolved. |
|
166 | - * |
|
167 | - * @param string $abstract |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - public function resolved($abstract) |
|
171 | - { |
|
172 | - if ($this->isAlias($abstract)) { |
|
173 | - $abstract = $this->getAlias($abstract); |
|
174 | - } |
|
175 | - |
|
176 | - return isset($this->resolved[$abstract]) || |
|
177 | - isset($this->instances[$abstract]); |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Determine if a given type is shared. |
|
182 | - * |
|
183 | - * @param string $abstract |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function isShared($abstract) |
|
187 | - { |
|
188 | - return isset($this->instances[$abstract]) || |
|
189 | - (isset($this->bindings[$abstract]['shared']) && |
|
190 | - $this->bindings[$abstract]['shared'] === true); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Determine if a given string is an alias. |
|
195 | - * |
|
196 | - * @param string $name |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function isAlias($name) |
|
200 | - { |
|
201 | - return isset($this->aliases[$name]); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Register a binding with the container. |
|
206 | - * |
|
207 | - * @param string|array $abstract |
|
208 | - * @param \Closure|string|null $concrete |
|
209 | - * @param bool $shared |
|
210 | - * @return void |
|
211 | - */ |
|
212 | - public function bind($abstract, $concrete = null, $shared = false) |
|
213 | - { |
|
214 | - // If no concrete type was given, we will simply set the concrete type to the |
|
215 | - // abstract type. After that, the concrete type to be registered as shared |
|
216 | - // without being forced to state their classes in both of the parameters. |
|
217 | - $this->dropStaleInstances($abstract); |
|
218 | - |
|
219 | - if (is_null($concrete)) { |
|
220 | - $concrete = $abstract; |
|
221 | - } |
|
222 | - |
|
223 | - // If the factory is not a Closure, it means it is just a class name which is |
|
224 | - // bound into this container to the abstract type and we will just wrap it |
|
225 | - // up inside its own Closure to give us more convenience when extending. |
|
226 | - if (! $concrete instanceof Closure) { |
|
227 | - $concrete = $this->getClosure($abstract, $concrete); |
|
228 | - } |
|
229 | - |
|
230 | - $this->bindings[$abstract] = compact('concrete', 'shared'); |
|
231 | - |
|
232 | - // If the abstract type was already resolved in this container we'll fire the |
|
233 | - // rebound listener so that any objects which have already gotten resolved |
|
234 | - // can have their copy of the object updated via the listener callbacks. |
|
235 | - if ($this->resolved($abstract)) { |
|
236 | - $this->rebound($abstract); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Get the Closure to be used when building a type. |
|
242 | - * |
|
243 | - * @param string $abstract |
|
244 | - * @param string $concrete |
|
245 | - * @return \Closure |
|
246 | - */ |
|
247 | - protected function getClosure($abstract, $concrete) |
|
248 | - { |
|
249 | - return function ($container, $parameters = []) use ($abstract, $concrete) { |
|
250 | - if ($abstract == $concrete) { |
|
251 | - return $container->build($concrete); |
|
252 | - } |
|
253 | - |
|
254 | - return $container->makeWith($concrete, $parameters); |
|
255 | - }; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Determine if the container has a method binding. |
|
260 | - * |
|
261 | - * @param string $method |
|
262 | - * @return bool |
|
263 | - */ |
|
264 | - public function hasMethodBinding($method) |
|
265 | - { |
|
266 | - return isset($this->methodBindings[$method]); |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Bind a callback to resolve with Container::call. |
|
271 | - * |
|
272 | - * @param string $method |
|
273 | - * @param \Closure $callback |
|
274 | - * @return void |
|
275 | - */ |
|
276 | - public function bindMethod($method, $callback) |
|
277 | - { |
|
278 | - $this->methodBindings[$method] = $callback; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Get the method binding for the given method. |
|
283 | - * |
|
284 | - * @param string $method |
|
285 | - * @param mixed $instance |
|
286 | - * @return mixed |
|
287 | - */ |
|
288 | - public function callMethodBinding($method, $instance) |
|
289 | - { |
|
290 | - return call_user_func($this->methodBindings[$method], $instance, $this); |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Add a contextual binding to the container. |
|
295 | - * |
|
296 | - * @param string $concrete |
|
297 | - * @param string $abstract |
|
298 | - * @param \Closure|string $implementation |
|
299 | - * @return void |
|
300 | - */ |
|
301 | - public function addContextualBinding($concrete, $abstract, $implementation) |
|
302 | - { |
|
303 | - $this->contextual[$concrete][$this->getAlias($abstract)] = $implementation; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Register a binding if it hasn't already been registered. |
|
308 | - * |
|
309 | - * @param string $abstract |
|
310 | - * @param \Closure|string|null $concrete |
|
311 | - * @param bool $shared |
|
312 | - * @return void |
|
313 | - */ |
|
314 | - public function bindIf($abstract, $concrete = null, $shared = false) |
|
315 | - { |
|
316 | - if (! $this->bound($abstract)) { |
|
317 | - $this->bind($abstract, $concrete, $shared); |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Register a shared binding in the container. |
|
323 | - * |
|
324 | - * @param string|array $abstract |
|
325 | - * @param \Closure|string|null $concrete |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - public function singleton($abstract, $concrete = null) |
|
329 | - { |
|
330 | - $this->bind($abstract, $concrete, true); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * "Extend" an abstract type in the container. |
|
335 | - * |
|
336 | - * @param string $abstract |
|
337 | - * @param \Closure $closure |
|
338 | - * @return void |
|
339 | - * |
|
340 | - * @throws \InvalidArgumentException |
|
341 | - */ |
|
342 | - public function extend($abstract, Closure $closure) |
|
343 | - { |
|
344 | - $abstract = $this->getAlias($abstract); |
|
345 | - |
|
346 | - if (isset($this->instances[$abstract])) { |
|
347 | - $this->instances[$abstract] = $closure($this->instances[$abstract], $this); |
|
348 | - |
|
349 | - $this->rebound($abstract); |
|
350 | - } else { |
|
351 | - $this->extenders[$abstract][] = $closure; |
|
352 | - |
|
353 | - if ($this->resolved($abstract)) { |
|
354 | - $this->rebound($abstract); |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Register an existing instance as shared in the container. |
|
361 | - * |
|
362 | - * @param string $abstract |
|
363 | - * @param mixed $instance |
|
364 | - * @return void |
|
365 | - */ |
|
366 | - public function instance($abstract, $instance) |
|
367 | - { |
|
368 | - $this->removeAbstractAlias($abstract); |
|
369 | - |
|
370 | - $isBound = $this->bound($abstract); |
|
371 | - |
|
372 | - unset($this->aliases[$abstract]); |
|
373 | - |
|
374 | - // We'll check to determine if this type has been bound before, and if it has |
|
375 | - // we will fire the rebound callbacks registered with the container and it |
|
376 | - // can be updated with consuming classes that have gotten resolved here. |
|
377 | - $this->instances[$abstract] = $instance; |
|
378 | - |
|
379 | - if ($isBound) { |
|
380 | - $this->rebound($abstract); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Remove an alias from the contextual binding alias cache. |
|
386 | - * |
|
387 | - * @param string $searched |
|
388 | - * @return void |
|
389 | - */ |
|
390 | - protected function removeAbstractAlias($searched) |
|
391 | - { |
|
392 | - if (! isset($this->aliases[$searched])) { |
|
393 | - return; |
|
394 | - } |
|
395 | - |
|
396 | - foreach ($this->abstractAliases as $abstract => $aliases) { |
|
397 | - foreach ($aliases as $index => $alias) { |
|
398 | - if ($alias == $searched) { |
|
399 | - unset($this->abstractAliases[$abstract][$index]); |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Assign a set of tags to a given binding. |
|
407 | - * |
|
408 | - * @param array|string $abstracts |
|
409 | - * @param array|mixed ...$tags |
|
410 | - * @return void |
|
411 | - */ |
|
412 | - public function tag($abstracts, $tags) |
|
413 | - { |
|
414 | - $tags = is_array($tags) ? $tags : array_slice(func_get_args(), 1); |
|
415 | - |
|
416 | - foreach ($tags as $tag) { |
|
417 | - if (! isset($this->tags[$tag])) { |
|
418 | - $this->tags[$tag] = []; |
|
419 | - } |
|
420 | - |
|
421 | - foreach ((array) $abstracts as $abstract) { |
|
422 | - $this->tags[$tag][] = $abstract; |
|
423 | - } |
|
424 | - } |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Resolve all of the bindings for a given tag. |
|
429 | - * |
|
430 | - * @param string $tag |
|
431 | - * @return array |
|
432 | - */ |
|
433 | - public function tagged($tag) |
|
434 | - { |
|
435 | - $results = []; |
|
436 | - |
|
437 | - if (isset($this->tags[$tag])) { |
|
438 | - foreach ($this->tags[$tag] as $abstract) { |
|
439 | - $results[] = $this->make($abstract); |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - return $results; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Alias a type to a different name. |
|
448 | - * |
|
449 | - * @param string $abstract |
|
450 | - * @param string $alias |
|
451 | - * @return void |
|
452 | - */ |
|
453 | - public function alias($abstract, $alias) |
|
454 | - { |
|
455 | - $this->aliases[$alias] = $abstract; |
|
456 | - |
|
457 | - $this->abstractAliases[$abstract][] = $alias; |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Bind a new callback to an abstract's rebind event. |
|
462 | - * |
|
463 | - * @param string $abstract |
|
464 | - * @param \Closure $callback |
|
465 | - * @return mixed |
|
466 | - */ |
|
467 | - public function rebinding($abstract, Closure $callback) |
|
468 | - { |
|
469 | - $this->reboundCallbacks[$abstract = $this->getAlias($abstract)][] = $callback; |
|
470 | - |
|
471 | - if ($this->bound($abstract)) { |
|
472 | - return $this->make($abstract); |
|
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - /** |
|
477 | - * Refresh an instance on the given target and method. |
|
478 | - * |
|
479 | - * @param string $abstract |
|
480 | - * @param mixed $target |
|
481 | - * @param string $method |
|
482 | - * @return mixed |
|
483 | - */ |
|
484 | - public function refresh($abstract, $target, $method) |
|
485 | - { |
|
486 | - return $this->rebinding($abstract, function ($app, $instance) use ($target, $method) { |
|
487 | - $target->{$method}($instance); |
|
488 | - }); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Fire the "rebound" callbacks for the given abstract type. |
|
493 | - * |
|
494 | - * @param string $abstract |
|
495 | - * @return void |
|
496 | - */ |
|
497 | - protected function rebound($abstract) |
|
498 | - { |
|
499 | - $instance = $this->make($abstract); |
|
500 | - |
|
501 | - foreach ($this->getReboundCallbacks($abstract) as $callback) { |
|
502 | - call_user_func($callback, $this, $instance); |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Get the rebound callbacks for a given type. |
|
508 | - * |
|
509 | - * @param string $abstract |
|
510 | - * @return array |
|
511 | - */ |
|
512 | - protected function getReboundCallbacks($abstract) |
|
513 | - { |
|
514 | - if (isset($this->reboundCallbacks[$abstract])) { |
|
515 | - return $this->reboundCallbacks[$abstract]; |
|
516 | - } |
|
517 | - |
|
518 | - return []; |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * Wrap the given closure such that its dependencies will be injected when executed. |
|
523 | - * |
|
524 | - * @param \Closure $callback |
|
525 | - * @param array $parameters |
|
526 | - * @return \Closure |
|
527 | - */ |
|
528 | - public function wrap(Closure $callback, array $parameters = []) |
|
529 | - { |
|
530 | - return function () use ($callback, $parameters) { |
|
531 | - return $this->call($callback, $parameters); |
|
532 | - }; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Call the given Closure / class@method and inject its dependencies. |
|
537 | - * |
|
538 | - * @param callable|string $callback |
|
539 | - * @param array $parameters |
|
540 | - * @param string|null $defaultMethod |
|
541 | - * @return mixed |
|
542 | - */ |
|
543 | - public function call($callback, array $parameters = [], $defaultMethod = null) |
|
544 | - { |
|
545 | - return BoundMethod::call($this, $callback, $parameters, $defaultMethod); |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Get a closure to resolve the given type from the container. |
|
550 | - * |
|
551 | - * @param string $abstract |
|
552 | - * @return \Closure |
|
553 | - */ |
|
554 | - public function factory($abstract) |
|
555 | - { |
|
556 | - return function () use ($abstract) { |
|
557 | - return $this->make($abstract); |
|
558 | - }; |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Resolve the given type with the given parameter overrides. |
|
563 | - * |
|
564 | - * @param string $abstract |
|
565 | - * @param array $parameters |
|
566 | - * @return mixed |
|
567 | - */ |
|
568 | - public function makeWith($abstract, array $parameters) |
|
569 | - { |
|
570 | - return $this->resolve($abstract, $parameters); |
|
571 | - } |
|
572 | - |
|
573 | - /** |
|
574 | - * Resolve the given type from the container. |
|
575 | - * |
|
576 | - * @param string $abstract |
|
577 | - * @return mixed |
|
578 | - */ |
|
579 | - public function make($abstract) |
|
580 | - { |
|
581 | - return $this->resolve($abstract); |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Resolve the given type from the container. |
|
586 | - * |
|
587 | - * @param string $abstract |
|
588 | - * @param array $parameters |
|
589 | - * @return mixed |
|
590 | - */ |
|
591 | - protected function resolve($abstract, $parameters = []) |
|
592 | - { |
|
593 | - $abstract = $this->getAlias($abstract); |
|
594 | - |
|
595 | - $needsContextualBuild = ! empty($parameters) || ! is_null( |
|
596 | - $this->getContextualConcrete($abstract) |
|
597 | - ); |
|
598 | - |
|
599 | - // If an instance of the type is currently being managed as a singleton we'll |
|
600 | - // just return an existing instance instead of instantiating new instances |
|
601 | - // so the developer can keep using the same objects instance every time. |
|
602 | - if (isset($this->instances[$abstract]) && ! $needsContextualBuild) { |
|
603 | - return $this->instances[$abstract]; |
|
604 | - } |
|
605 | - |
|
606 | - $this->with[] = $parameters; |
|
607 | - |
|
608 | - $concrete = $this->getConcrete($abstract); |
|
609 | - |
|
610 | - // We're ready to instantiate an instance of the concrete type registered for |
|
611 | - // the binding. This will instantiate the types, as well as resolve any of |
|
612 | - // its "nested" dependencies recursively until all have gotten resolved. |
|
613 | - if ($this->isBuildable($concrete, $abstract)) { |
|
614 | - $object = $this->build($concrete); |
|
615 | - } else { |
|
616 | - $object = $this->make($concrete); |
|
617 | - } |
|
618 | - |
|
619 | - // If we defined any extenders for this type, we'll need to spin through them |
|
620 | - // and apply them to the object being built. This allows for the extension |
|
621 | - // of services, such as changing configuration or decorating the object. |
|
622 | - foreach ($this->getExtenders($abstract) as $extender) { |
|
623 | - $object = $extender($object, $this); |
|
624 | - } |
|
625 | - |
|
626 | - // If the requested type is registered as a singleton we'll want to cache off |
|
627 | - // the instances in "memory" so we can return it later without creating an |
|
628 | - // entirely new instance of an object on each subsequent request for it. |
|
629 | - if ($this->isShared($abstract) && ! $needsContextualBuild) { |
|
630 | - $this->instances[$abstract] = $object; |
|
631 | - } |
|
632 | - |
|
633 | - $this->fireResolvingCallbacks($abstract, $object); |
|
634 | - |
|
635 | - // Before returning, we will also set the resolved flag to "true" and pop off |
|
636 | - // the parameter overrides for this build. After those two things are done |
|
637 | - // we will be ready to return back the fully constructed class instance. |
|
638 | - $this->resolved[$abstract] = true; |
|
639 | - |
|
640 | - array_pop($this->with); |
|
641 | - |
|
642 | - return $object; |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Get the concrete type for a given abstract. |
|
647 | - * |
|
648 | - * @param string $abstract |
|
649 | - * @return mixed $concrete |
|
650 | - */ |
|
651 | - protected function getConcrete($abstract) |
|
652 | - { |
|
653 | - if (! is_null($concrete = $this->getContextualConcrete($abstract))) { |
|
654 | - return $concrete; |
|
655 | - } |
|
656 | - |
|
657 | - // If we don't have a registered resolver or concrete for the type, we'll just |
|
658 | - // assume each type is a concrete name and will attempt to resolve it as is |
|
659 | - // since the container should be able to resolve concretes automatically. |
|
660 | - if (isset($this->bindings[$abstract])) { |
|
661 | - return $this->bindings[$abstract]['concrete']; |
|
662 | - } |
|
663 | - |
|
664 | - return $abstract; |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Get the contextual concrete binding for the given abstract. |
|
669 | - * |
|
670 | - * @param string $abstract |
|
671 | - * @return string|null |
|
672 | - */ |
|
673 | - protected function getContextualConcrete($abstract) |
|
674 | - { |
|
675 | - if (! is_null($binding = $this->findInContextualBindings($abstract))) { |
|
676 | - return $binding; |
|
677 | - } |
|
678 | - |
|
679 | - // Next we need to see if a contextual binding might be bound under an alias of the |
|
680 | - // given abstract type. So, we will need to check if any aliases exist with this |
|
681 | - // type and then spin through them and check for contextual bindings on these. |
|
682 | - if (empty($this->abstractAliases[$abstract])) { |
|
683 | - return; |
|
684 | - } |
|
685 | - |
|
686 | - foreach ($this->abstractAliases[$abstract] as $alias) { |
|
687 | - if (! is_null($binding = $this->findInContextualBindings($alias))) { |
|
688 | - return $binding; |
|
689 | - } |
|
690 | - } |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Find the concrete binding for the given abstract in the contextual binding array. |
|
695 | - * |
|
696 | - * @param string $abstract |
|
697 | - * @return string|null |
|
698 | - */ |
|
699 | - protected function findInContextualBindings($abstract) |
|
700 | - { |
|
701 | - if (isset($this->contextual[end($this->buildStack)][$abstract])) { |
|
702 | - return $this->contextual[end($this->buildStack)][$abstract]; |
|
703 | - } |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * Determine if the given concrete is buildable. |
|
708 | - * |
|
709 | - * @param mixed $concrete |
|
710 | - * @param string $abstract |
|
711 | - * @return bool |
|
712 | - */ |
|
713 | - protected function isBuildable($concrete, $abstract) |
|
714 | - { |
|
715 | - return $concrete === $abstract || $concrete instanceof Closure; |
|
716 | - } |
|
717 | - |
|
718 | - /** |
|
719 | - * Instantiate a concrete instance of the given type. |
|
720 | - * |
|
721 | - * @param string $concrete |
|
722 | - * @return mixed |
|
723 | - * |
|
724 | - * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
725 | - */ |
|
726 | - public function build($concrete) |
|
727 | - { |
|
728 | - // If the concrete type is actually a Closure, we will just execute it and |
|
729 | - // hand back the results of the functions, which allows functions to be |
|
730 | - // used as resolvers for more fine-tuned resolution of these objects. |
|
731 | - if ($concrete instanceof Closure) { |
|
732 | - return $concrete($this, $this->getLastParameterOverride()); |
|
733 | - } |
|
734 | - |
|
735 | - $reflector = new ReflectionClass($concrete); |
|
736 | - |
|
737 | - // If the type is not instantiable, the developer is attempting to resolve |
|
738 | - // an abstract type such as an Interface of Abstract Class and there is |
|
739 | - // no binding registered for the abstractions so we need to bail out. |
|
740 | - if (! $reflector->isInstantiable()) { |
|
741 | - return $this->notInstantiable($concrete); |
|
742 | - } |
|
743 | - |
|
744 | - $this->buildStack[] = $concrete; |
|
745 | - |
|
746 | - $constructor = $reflector->getConstructor(); |
|
747 | - |
|
748 | - // If there are no constructors, that means there are no dependencies then |
|
749 | - // we can just resolve the instances of the objects right away, without |
|
750 | - // resolving any other types or dependencies out of these containers. |
|
751 | - if (is_null($constructor)) { |
|
752 | - array_pop($this->buildStack); |
|
753 | - |
|
754 | - return new $concrete; |
|
755 | - } |
|
756 | - |
|
757 | - $dependencies = $constructor->getParameters(); |
|
758 | - |
|
759 | - // Once we have all the constructor's parameters we can create each of the |
|
760 | - // dependency instances and then use the reflection instances to make a |
|
761 | - // new instance of this class, injecting the created dependencies in. |
|
762 | - $instances = $this->resolveDependencies( |
|
763 | - $dependencies |
|
764 | - ); |
|
765 | - |
|
766 | - array_pop($this->buildStack); |
|
767 | - |
|
768 | - return $reflector->newInstanceArgs($instances); |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * Resolve all of the dependencies from the ReflectionParameters. |
|
773 | - * |
|
774 | - * @param array $dependencies |
|
775 | - * @return array |
|
776 | - */ |
|
777 | - protected function resolveDependencies(array $dependencies) |
|
778 | - { |
|
779 | - $results = []; |
|
780 | - |
|
781 | - foreach ($dependencies as $dependency) { |
|
782 | - // If this dependency has a override for this particular build we will use |
|
783 | - // that instead as the value. Otherwise, we will continue with this run |
|
784 | - // of resolutions and let reflection attempt to determine the result. |
|
785 | - if ($this->hasParameterOverride($dependency)) { |
|
786 | - $results[] = $this->getParameterOverride($dependency); |
|
787 | - |
|
788 | - continue; |
|
789 | - } |
|
790 | - |
|
791 | - // If the class is null, it means the dependency is a string or some other |
|
792 | - // primitive type which we can not resolve since it is not a class and |
|
793 | - // we will just bomb out with an error since we have no-where to go. |
|
794 | - $results[] = is_null($class = $dependency->getClass()) |
|
795 | - ? $this->resolvePrimitive($dependency) |
|
796 | - : $this->resolveClass($dependency); |
|
797 | - } |
|
798 | - |
|
799 | - return $results; |
|
800 | - } |
|
801 | - |
|
802 | - /** |
|
803 | - * Determine if the given dependency has a parameter override from makeWith. |
|
804 | - * |
|
805 | - * @param \ReflectionParameter $dependency |
|
806 | - * @return bool |
|
807 | - */ |
|
808 | - protected function hasParameterOverride($dependency) |
|
809 | - { |
|
810 | - return array_key_exists( |
|
811 | - $dependency->name, $this->getLastParameterOverride() |
|
812 | - ); |
|
813 | - } |
|
814 | - |
|
815 | - /** |
|
816 | - * Get a parameter override for a dependency. |
|
817 | - * |
|
818 | - * @param \ReflectionParameter $dependency |
|
819 | - * @return mixed |
|
820 | - */ |
|
821 | - protected function getParameterOverride($dependency) |
|
822 | - { |
|
823 | - return $this->getLastParameterOverride()[$dependency->name]; |
|
824 | - } |
|
825 | - |
|
826 | - /** |
|
827 | - * Get the last parameter override. |
|
828 | - * |
|
829 | - * @return array |
|
830 | - */ |
|
831 | - protected function getLastParameterOverride() |
|
832 | - { |
|
833 | - return count($this->with) ? end($this->with) : []; |
|
834 | - } |
|
835 | - |
|
836 | - /** |
|
837 | - * Resolve a non-class hinted primitive dependency. |
|
838 | - * |
|
839 | - * @param \ReflectionParameter $parameter |
|
840 | - * @return mixed |
|
841 | - * |
|
842 | - * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
843 | - */ |
|
844 | - protected function resolvePrimitive(ReflectionParameter $parameter) |
|
845 | - { |
|
846 | - if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->name))) { |
|
847 | - return $concrete instanceof Closure ? $concrete($this) : $concrete; |
|
848 | - } |
|
849 | - |
|
850 | - if ($parameter->isDefaultValueAvailable()) { |
|
851 | - return $parameter->getDefaultValue(); |
|
852 | - } |
|
853 | - |
|
854 | - $this->unresolvablePrimitive($parameter); |
|
855 | - } |
|
856 | - |
|
857 | - /** |
|
858 | - * Resolve a class based dependency from the container. |
|
859 | - * |
|
860 | - * @param \ReflectionParameter $parameter |
|
861 | - * @return mixed |
|
862 | - * |
|
863 | - * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
864 | - */ |
|
865 | - protected function resolveClass(ReflectionParameter $parameter) |
|
866 | - { |
|
867 | - try { |
|
868 | - return $this->make($parameter->getClass()->name); |
|
869 | - } |
|
870 | - |
|
871 | - // If we can not resolve the class instance, we will check to see if the value |
|
872 | - // is optional, and if it is we will return the optional parameter value as |
|
873 | - // the value of the dependency, similarly to how we do this with scalars. |
|
874 | - catch (BindingResolutionException $e) { |
|
875 | - if ($parameter->isOptional()) { |
|
876 | - return $parameter->getDefaultValue(); |
|
877 | - } |
|
878 | - |
|
879 | - throw $e; |
|
880 | - } |
|
881 | - } |
|
882 | - |
|
883 | - /** |
|
884 | - * Throw an exception that the concrete is not instantiable. |
|
885 | - * |
|
886 | - * @param string $concrete |
|
887 | - * @return void |
|
888 | - * |
|
889 | - * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
890 | - */ |
|
891 | - protected function notInstantiable($concrete) |
|
892 | - { |
|
893 | - if (! empty($this->buildStack)) { |
|
894 | - $previous = implode(', ', $this->buildStack); |
|
895 | - |
|
896 | - $message = "Target [$concrete] is not instantiable while building [$previous]."; |
|
897 | - } else { |
|
898 | - $message = "Target [$concrete] is not instantiable."; |
|
899 | - } |
|
900 | - |
|
901 | - throw new BindingResolutionException($message); |
|
902 | - } |
|
903 | - |
|
904 | - /** |
|
905 | - * Throw an exception for an unresolvable primitive. |
|
906 | - * |
|
907 | - * @param \ReflectionParameter $parameter |
|
908 | - * @return void |
|
909 | - * |
|
910 | - * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
911 | - */ |
|
912 | - protected function unresolvablePrimitive(ReflectionParameter $parameter) |
|
913 | - { |
|
914 | - $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}"; |
|
915 | - |
|
916 | - throw new BindingResolutionException($message); |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * Register a new resolving callback. |
|
921 | - * |
|
922 | - * @param string $abstract |
|
923 | - * @param \Closure|null $callback |
|
924 | - * @return void |
|
925 | - */ |
|
926 | - public function resolving($abstract, Closure $callback = null) |
|
927 | - { |
|
928 | - if (is_string($abstract)) { |
|
929 | - $abstract = $this->getAlias($abstract); |
|
930 | - } |
|
931 | - |
|
932 | - if (is_null($callback) && $abstract instanceof Closure) { |
|
933 | - $this->globalResolvingCallbacks[] = $abstract; |
|
934 | - } else { |
|
935 | - $this->resolvingCallbacks[$abstract][] = $callback; |
|
936 | - } |
|
937 | - } |
|
938 | - |
|
939 | - /** |
|
940 | - * Register a new after resolving callback for all types. |
|
941 | - * |
|
942 | - * @param string $abstract |
|
943 | - * @param \Closure|null $callback |
|
944 | - * @return void |
|
945 | - */ |
|
946 | - public function afterResolving($abstract, Closure $callback = null) |
|
947 | - { |
|
948 | - if (is_string($abstract)) { |
|
949 | - $abstract = $this->getAlias($abstract); |
|
950 | - } |
|
951 | - |
|
952 | - if ($abstract instanceof Closure && is_null($callback)) { |
|
953 | - $this->globalAfterResolvingCallbacks[] = $abstract; |
|
954 | - } else { |
|
955 | - $this->afterResolvingCallbacks[$abstract][] = $callback; |
|
956 | - } |
|
957 | - } |
|
958 | - |
|
959 | - /** |
|
960 | - * Fire all of the resolving callbacks. |
|
961 | - * |
|
962 | - * @param string $abstract |
|
963 | - * @param mixed $object |
|
964 | - * @return void |
|
965 | - */ |
|
966 | - protected function fireResolvingCallbacks($abstract, $object) |
|
967 | - { |
|
968 | - $this->fireCallbackArray($object, $this->globalResolvingCallbacks); |
|
969 | - |
|
970 | - $this->fireCallbackArray( |
|
971 | - $object, $this->getCallbacksForType($abstract, $object, $this->resolvingCallbacks) |
|
972 | - ); |
|
973 | - |
|
974 | - $this->fireAfterResolvingCallbacks($abstract, $object); |
|
975 | - } |
|
976 | - |
|
977 | - /** |
|
978 | - * Fire all of the after resolving callbacks. |
|
979 | - * |
|
980 | - * @param string $abstract |
|
981 | - * @param mixed $object |
|
982 | - * @return void |
|
983 | - */ |
|
984 | - protected function fireAfterResolvingCallbacks($abstract, $object) |
|
985 | - { |
|
986 | - $this->fireCallbackArray($object, $this->globalAfterResolvingCallbacks); |
|
987 | - |
|
988 | - $this->fireCallbackArray( |
|
989 | - $object, $this->getCallbacksForType($abstract, $object, $this->afterResolvingCallbacks) |
|
990 | - ); |
|
991 | - } |
|
992 | - |
|
993 | - /** |
|
994 | - * Get all callbacks for a given type. |
|
995 | - * |
|
996 | - * @param string $abstract |
|
997 | - * @param object $object |
|
998 | - * @param array $callbacksPerType |
|
999 | - * |
|
1000 | - * @return array |
|
1001 | - */ |
|
1002 | - protected function getCallbacksForType($abstract, $object, array $callbacksPerType) |
|
1003 | - { |
|
1004 | - $results = []; |
|
1005 | - |
|
1006 | - foreach ($callbacksPerType as $type => $callbacks) { |
|
1007 | - if ($type === $abstract || $object instanceof $type) { |
|
1008 | - $results = array_merge($results, $callbacks); |
|
1009 | - } |
|
1010 | - } |
|
1011 | - |
|
1012 | - return $results; |
|
1013 | - } |
|
1014 | - |
|
1015 | - /** |
|
1016 | - * Fire an array of callbacks with an object. |
|
1017 | - * |
|
1018 | - * @param mixed $object |
|
1019 | - * @param array $callbacks |
|
1020 | - * @return void |
|
1021 | - */ |
|
1022 | - protected function fireCallbackArray($object, array $callbacks) |
|
1023 | - { |
|
1024 | - foreach ($callbacks as $callback) { |
|
1025 | - $callback($object, $this); |
|
1026 | - } |
|
1027 | - } |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * Get the container's bindings. |
|
1031 | - * |
|
1032 | - * @return array |
|
1033 | - */ |
|
1034 | - public function getBindings() |
|
1035 | - { |
|
1036 | - return $this->bindings; |
|
1037 | - } |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * Get the alias for an abstract if available. |
|
1041 | - * |
|
1042 | - * @param string $abstract |
|
1043 | - * @return string |
|
1044 | - * |
|
1045 | - * @throws \LogicException |
|
1046 | - */ |
|
1047 | - public function getAlias($abstract) |
|
1048 | - { |
|
1049 | - if (! isset($this->aliases[$abstract])) { |
|
1050 | - return $abstract; |
|
1051 | - } |
|
1052 | - |
|
1053 | - if ($this->aliases[$abstract] === $abstract) { |
|
1054 | - throw new LogicException("[{$abstract}] is aliased to itself."); |
|
1055 | - } |
|
1056 | - |
|
1057 | - return $this->getAlias($this->aliases[$abstract]); |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Get the extender callbacks for a given type. |
|
1062 | - * |
|
1063 | - * @param string $abstract |
|
1064 | - * @return array |
|
1065 | - */ |
|
1066 | - protected function getExtenders($abstract) |
|
1067 | - { |
|
1068 | - $abstract = $this->getAlias($abstract); |
|
1069 | - |
|
1070 | - if (isset($this->extenders[$abstract])) { |
|
1071 | - return $this->extenders[$abstract]; |
|
1072 | - } |
|
1073 | - |
|
1074 | - return []; |
|
1075 | - } |
|
1076 | - |
|
1077 | - /** |
|
1078 | - * Remove all of the extender callbacks for a given type. |
|
1079 | - * |
|
1080 | - * @param string $abstract |
|
1081 | - * @return void |
|
1082 | - */ |
|
1083 | - public function forgetExtenders($abstract) |
|
1084 | - { |
|
1085 | - unset($this->extenders[$this->getAlias($abstract)]); |
|
1086 | - } |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * Drop all of the stale instances and aliases. |
|
1090 | - * |
|
1091 | - * @param string $abstract |
|
1092 | - * @return void |
|
1093 | - */ |
|
1094 | - protected function dropStaleInstances($abstract) |
|
1095 | - { |
|
1096 | - unset($this->instances[$abstract], $this->aliases[$abstract]); |
|
1097 | - } |
|
1098 | - |
|
1099 | - /** |
|
1100 | - * Remove a resolved instance from the instance cache. |
|
1101 | - * |
|
1102 | - * @param string $abstract |
|
1103 | - * @return void |
|
1104 | - */ |
|
1105 | - public function forgetInstance($abstract) |
|
1106 | - { |
|
1107 | - unset($this->instances[$abstract]); |
|
1108 | - } |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * Clear all of the instances from the container. |
|
1112 | - * |
|
1113 | - * @return void |
|
1114 | - */ |
|
1115 | - public function forgetInstances() |
|
1116 | - { |
|
1117 | - $this->instances = []; |
|
1118 | - } |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * Flush the container of all bindings and resolved instances. |
|
1122 | - * |
|
1123 | - * @return void |
|
1124 | - */ |
|
1125 | - public function flush() |
|
1126 | - { |
|
1127 | - $this->aliases = []; |
|
1128 | - $this->resolved = []; |
|
1129 | - $this->bindings = []; |
|
1130 | - $this->instances = []; |
|
1131 | - $this->abstractAliases = []; |
|
1132 | - } |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * Set the globally available instance of the container. |
|
1136 | - * |
|
1137 | - * @return static |
|
1138 | - */ |
|
1139 | - public static function getInstance() |
|
1140 | - { |
|
1141 | - if (is_null(static::$instance)) { |
|
1142 | - static::$instance = new static; |
|
1143 | - } |
|
1144 | - |
|
1145 | - return static::$instance; |
|
1146 | - } |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Set the shared instance of the container. |
|
1150 | - * |
|
1151 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\Container|null $container |
|
1152 | - * @return static |
|
1153 | - */ |
|
1154 | - public static function setInstance(ContainerContract $container = null) |
|
1155 | - { |
|
1156 | - return static::$instance = $container; |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * Determine if a given offset exists. |
|
1161 | - * |
|
1162 | - * @param string $key |
|
1163 | - * @return bool |
|
1164 | - */ |
|
1165 | - public function offsetExists($key) |
|
1166 | - { |
|
1167 | - return $this->bound($key); |
|
1168 | - } |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * Get the value at a given offset. |
|
1172 | - * |
|
1173 | - * @param string $key |
|
1174 | - * @return mixed |
|
1175 | - */ |
|
1176 | - public function offsetGet($key) |
|
1177 | - { |
|
1178 | - return $this->make($key); |
|
1179 | - } |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Set the value at a given offset. |
|
1183 | - * |
|
1184 | - * @param string $key |
|
1185 | - * @param mixed $value |
|
1186 | - * @return void |
|
1187 | - */ |
|
1188 | - public function offsetSet($key, $value) |
|
1189 | - { |
|
1190 | - $this->bind($key, $value instanceof Closure ? $value : function () use ($value) { |
|
1191 | - return $value; |
|
1192 | - }); |
|
1193 | - } |
|
1194 | - |
|
1195 | - /** |
|
1196 | - * Unset the value at a given offset. |
|
1197 | - * |
|
1198 | - * @param string $key |
|
1199 | - * @return void |
|
1200 | - */ |
|
1201 | - public function offsetUnset($key) |
|
1202 | - { |
|
1203 | - unset($this->bindings[$key], $this->instances[$key], $this->resolved[$key]); |
|
1204 | - } |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * Dynamically access container services. |
|
1208 | - * |
|
1209 | - * @param string $key |
|
1210 | - * @return mixed |
|
1211 | - */ |
|
1212 | - public function __get($key) |
|
1213 | - { |
|
1214 | - return $this[$key]; |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * Dynamically set container services. |
|
1219 | - * |
|
1220 | - * @param string $key |
|
1221 | - * @param mixed $value |
|
1222 | - * @return void |
|
1223 | - */ |
|
1224 | - public function __set($key, $value) |
|
1225 | - { |
|
1226 | - $this[$key] = $value; |
|
1227 | - } |
|
21 | + /** |
|
22 | + * The current globally available container (if any). |
|
23 | + * |
|
24 | + * @var static |
|
25 | + */ |
|
26 | + protected static $instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * An array of the types that have been resolved. |
|
30 | + * |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $resolved = []; |
|
34 | + |
|
35 | + /** |
|
36 | + * The container's bindings. |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected $bindings = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * The container's method bindings. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $methodBindings = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * The container's shared instances. |
|
51 | + * |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $instances = []; |
|
55 | + |
|
56 | + /** |
|
57 | + * The registered type aliases. |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $aliases = []; |
|
62 | + |
|
63 | + /** |
|
64 | + * The registered aliases keyed by the abstract name. |
|
65 | + * |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $abstractAliases = []; |
|
69 | + |
|
70 | + /** |
|
71 | + * The extension closures for services. |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + protected $extenders = []; |
|
76 | + |
|
77 | + /** |
|
78 | + * All of the registered tags. |
|
79 | + * |
|
80 | + * @var array |
|
81 | + */ |
|
82 | + protected $tags = []; |
|
83 | + |
|
84 | + /** |
|
85 | + * The stack of concretions currently being built. |
|
86 | + * |
|
87 | + * @var array |
|
88 | + */ |
|
89 | + protected $buildStack = []; |
|
90 | + |
|
91 | + /** |
|
92 | + * The parameter override stack. |
|
93 | + * |
|
94 | + * @var array |
|
95 | + */ |
|
96 | + protected $with = []; |
|
97 | + |
|
98 | + /** |
|
99 | + * The contextual binding map. |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + public $contextual = []; |
|
104 | + |
|
105 | + /** |
|
106 | + * All of the registered rebound callbacks. |
|
107 | + * |
|
108 | + * @var array |
|
109 | + */ |
|
110 | + protected $reboundCallbacks = []; |
|
111 | + |
|
112 | + /** |
|
113 | + * All of the global resolving callbacks. |
|
114 | + * |
|
115 | + * @var array |
|
116 | + */ |
|
117 | + protected $globalResolvingCallbacks = []; |
|
118 | + |
|
119 | + /** |
|
120 | + * All of the global after resolving callbacks. |
|
121 | + * |
|
122 | + * @var array |
|
123 | + */ |
|
124 | + protected $globalAfterResolvingCallbacks = []; |
|
125 | + |
|
126 | + /** |
|
127 | + * All of the resolving callbacks by class type. |
|
128 | + * |
|
129 | + * @var array |
|
130 | + */ |
|
131 | + protected $resolvingCallbacks = []; |
|
132 | + |
|
133 | + /** |
|
134 | + * All of the after resolving callbacks by class type. |
|
135 | + * |
|
136 | + * @var array |
|
137 | + */ |
|
138 | + protected $afterResolvingCallbacks = []; |
|
139 | + |
|
140 | + /** |
|
141 | + * Define a contextual binding. |
|
142 | + * |
|
143 | + * @param string $concrete |
|
144 | + * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\ContextualBindingBuilder |
|
145 | + */ |
|
146 | + public function when($concrete) |
|
147 | + { |
|
148 | + return new ContextualBindingBuilder($this, $this->getAlias($concrete)); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Determine if the given abstract type has been bound. |
|
153 | + * |
|
154 | + * @param string $abstract |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function bound($abstract) |
|
158 | + { |
|
159 | + return isset($this->bindings[$abstract]) || |
|
160 | + isset($this->instances[$abstract]) || |
|
161 | + $this->isAlias($abstract); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Determine if the given abstract type has been resolved. |
|
166 | + * |
|
167 | + * @param string $abstract |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | + public function resolved($abstract) |
|
171 | + { |
|
172 | + if ($this->isAlias($abstract)) { |
|
173 | + $abstract = $this->getAlias($abstract); |
|
174 | + } |
|
175 | + |
|
176 | + return isset($this->resolved[$abstract]) || |
|
177 | + isset($this->instances[$abstract]); |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Determine if a given type is shared. |
|
182 | + * |
|
183 | + * @param string $abstract |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function isShared($abstract) |
|
187 | + { |
|
188 | + return isset($this->instances[$abstract]) || |
|
189 | + (isset($this->bindings[$abstract]['shared']) && |
|
190 | + $this->bindings[$abstract]['shared'] === true); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Determine if a given string is an alias. |
|
195 | + * |
|
196 | + * @param string $name |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function isAlias($name) |
|
200 | + { |
|
201 | + return isset($this->aliases[$name]); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Register a binding with the container. |
|
206 | + * |
|
207 | + * @param string|array $abstract |
|
208 | + * @param \Closure|string|null $concrete |
|
209 | + * @param bool $shared |
|
210 | + * @return void |
|
211 | + */ |
|
212 | + public function bind($abstract, $concrete = null, $shared = false) |
|
213 | + { |
|
214 | + // If no concrete type was given, we will simply set the concrete type to the |
|
215 | + // abstract type. After that, the concrete type to be registered as shared |
|
216 | + // without being forced to state their classes in both of the parameters. |
|
217 | + $this->dropStaleInstances($abstract); |
|
218 | + |
|
219 | + if (is_null($concrete)) { |
|
220 | + $concrete = $abstract; |
|
221 | + } |
|
222 | + |
|
223 | + // If the factory is not a Closure, it means it is just a class name which is |
|
224 | + // bound into this container to the abstract type and we will just wrap it |
|
225 | + // up inside its own Closure to give us more convenience when extending. |
|
226 | + if (! $concrete instanceof Closure) { |
|
227 | + $concrete = $this->getClosure($abstract, $concrete); |
|
228 | + } |
|
229 | + |
|
230 | + $this->bindings[$abstract] = compact('concrete', 'shared'); |
|
231 | + |
|
232 | + // If the abstract type was already resolved in this container we'll fire the |
|
233 | + // rebound listener so that any objects which have already gotten resolved |
|
234 | + // can have their copy of the object updated via the listener callbacks. |
|
235 | + if ($this->resolved($abstract)) { |
|
236 | + $this->rebound($abstract); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Get the Closure to be used when building a type. |
|
242 | + * |
|
243 | + * @param string $abstract |
|
244 | + * @param string $concrete |
|
245 | + * @return \Closure |
|
246 | + */ |
|
247 | + protected function getClosure($abstract, $concrete) |
|
248 | + { |
|
249 | + return function ($container, $parameters = []) use ($abstract, $concrete) { |
|
250 | + if ($abstract == $concrete) { |
|
251 | + return $container->build($concrete); |
|
252 | + } |
|
253 | + |
|
254 | + return $container->makeWith($concrete, $parameters); |
|
255 | + }; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Determine if the container has a method binding. |
|
260 | + * |
|
261 | + * @param string $method |
|
262 | + * @return bool |
|
263 | + */ |
|
264 | + public function hasMethodBinding($method) |
|
265 | + { |
|
266 | + return isset($this->methodBindings[$method]); |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Bind a callback to resolve with Container::call. |
|
271 | + * |
|
272 | + * @param string $method |
|
273 | + * @param \Closure $callback |
|
274 | + * @return void |
|
275 | + */ |
|
276 | + public function bindMethod($method, $callback) |
|
277 | + { |
|
278 | + $this->methodBindings[$method] = $callback; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Get the method binding for the given method. |
|
283 | + * |
|
284 | + * @param string $method |
|
285 | + * @param mixed $instance |
|
286 | + * @return mixed |
|
287 | + */ |
|
288 | + public function callMethodBinding($method, $instance) |
|
289 | + { |
|
290 | + return call_user_func($this->methodBindings[$method], $instance, $this); |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Add a contextual binding to the container. |
|
295 | + * |
|
296 | + * @param string $concrete |
|
297 | + * @param string $abstract |
|
298 | + * @param \Closure|string $implementation |
|
299 | + * @return void |
|
300 | + */ |
|
301 | + public function addContextualBinding($concrete, $abstract, $implementation) |
|
302 | + { |
|
303 | + $this->contextual[$concrete][$this->getAlias($abstract)] = $implementation; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Register a binding if it hasn't already been registered. |
|
308 | + * |
|
309 | + * @param string $abstract |
|
310 | + * @param \Closure|string|null $concrete |
|
311 | + * @param bool $shared |
|
312 | + * @return void |
|
313 | + */ |
|
314 | + public function bindIf($abstract, $concrete = null, $shared = false) |
|
315 | + { |
|
316 | + if (! $this->bound($abstract)) { |
|
317 | + $this->bind($abstract, $concrete, $shared); |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Register a shared binding in the container. |
|
323 | + * |
|
324 | + * @param string|array $abstract |
|
325 | + * @param \Closure|string|null $concrete |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + public function singleton($abstract, $concrete = null) |
|
329 | + { |
|
330 | + $this->bind($abstract, $concrete, true); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * "Extend" an abstract type in the container. |
|
335 | + * |
|
336 | + * @param string $abstract |
|
337 | + * @param \Closure $closure |
|
338 | + * @return void |
|
339 | + * |
|
340 | + * @throws \InvalidArgumentException |
|
341 | + */ |
|
342 | + public function extend($abstract, Closure $closure) |
|
343 | + { |
|
344 | + $abstract = $this->getAlias($abstract); |
|
345 | + |
|
346 | + if (isset($this->instances[$abstract])) { |
|
347 | + $this->instances[$abstract] = $closure($this->instances[$abstract], $this); |
|
348 | + |
|
349 | + $this->rebound($abstract); |
|
350 | + } else { |
|
351 | + $this->extenders[$abstract][] = $closure; |
|
352 | + |
|
353 | + if ($this->resolved($abstract)) { |
|
354 | + $this->rebound($abstract); |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Register an existing instance as shared in the container. |
|
361 | + * |
|
362 | + * @param string $abstract |
|
363 | + * @param mixed $instance |
|
364 | + * @return void |
|
365 | + */ |
|
366 | + public function instance($abstract, $instance) |
|
367 | + { |
|
368 | + $this->removeAbstractAlias($abstract); |
|
369 | + |
|
370 | + $isBound = $this->bound($abstract); |
|
371 | + |
|
372 | + unset($this->aliases[$abstract]); |
|
373 | + |
|
374 | + // We'll check to determine if this type has been bound before, and if it has |
|
375 | + // we will fire the rebound callbacks registered with the container and it |
|
376 | + // can be updated with consuming classes that have gotten resolved here. |
|
377 | + $this->instances[$abstract] = $instance; |
|
378 | + |
|
379 | + if ($isBound) { |
|
380 | + $this->rebound($abstract); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Remove an alias from the contextual binding alias cache. |
|
386 | + * |
|
387 | + * @param string $searched |
|
388 | + * @return void |
|
389 | + */ |
|
390 | + protected function removeAbstractAlias($searched) |
|
391 | + { |
|
392 | + if (! isset($this->aliases[$searched])) { |
|
393 | + return; |
|
394 | + } |
|
395 | + |
|
396 | + foreach ($this->abstractAliases as $abstract => $aliases) { |
|
397 | + foreach ($aliases as $index => $alias) { |
|
398 | + if ($alias == $searched) { |
|
399 | + unset($this->abstractAliases[$abstract][$index]); |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Assign a set of tags to a given binding. |
|
407 | + * |
|
408 | + * @param array|string $abstracts |
|
409 | + * @param array|mixed ...$tags |
|
410 | + * @return void |
|
411 | + */ |
|
412 | + public function tag($abstracts, $tags) |
|
413 | + { |
|
414 | + $tags = is_array($tags) ? $tags : array_slice(func_get_args(), 1); |
|
415 | + |
|
416 | + foreach ($tags as $tag) { |
|
417 | + if (! isset($this->tags[$tag])) { |
|
418 | + $this->tags[$tag] = []; |
|
419 | + } |
|
420 | + |
|
421 | + foreach ((array) $abstracts as $abstract) { |
|
422 | + $this->tags[$tag][] = $abstract; |
|
423 | + } |
|
424 | + } |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Resolve all of the bindings for a given tag. |
|
429 | + * |
|
430 | + * @param string $tag |
|
431 | + * @return array |
|
432 | + */ |
|
433 | + public function tagged($tag) |
|
434 | + { |
|
435 | + $results = []; |
|
436 | + |
|
437 | + if (isset($this->tags[$tag])) { |
|
438 | + foreach ($this->tags[$tag] as $abstract) { |
|
439 | + $results[] = $this->make($abstract); |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + return $results; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Alias a type to a different name. |
|
448 | + * |
|
449 | + * @param string $abstract |
|
450 | + * @param string $alias |
|
451 | + * @return void |
|
452 | + */ |
|
453 | + public function alias($abstract, $alias) |
|
454 | + { |
|
455 | + $this->aliases[$alias] = $abstract; |
|
456 | + |
|
457 | + $this->abstractAliases[$abstract][] = $alias; |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * Bind a new callback to an abstract's rebind event. |
|
462 | + * |
|
463 | + * @param string $abstract |
|
464 | + * @param \Closure $callback |
|
465 | + * @return mixed |
|
466 | + */ |
|
467 | + public function rebinding($abstract, Closure $callback) |
|
468 | + { |
|
469 | + $this->reboundCallbacks[$abstract = $this->getAlias($abstract)][] = $callback; |
|
470 | + |
|
471 | + if ($this->bound($abstract)) { |
|
472 | + return $this->make($abstract); |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + /** |
|
477 | + * Refresh an instance on the given target and method. |
|
478 | + * |
|
479 | + * @param string $abstract |
|
480 | + * @param mixed $target |
|
481 | + * @param string $method |
|
482 | + * @return mixed |
|
483 | + */ |
|
484 | + public function refresh($abstract, $target, $method) |
|
485 | + { |
|
486 | + return $this->rebinding($abstract, function ($app, $instance) use ($target, $method) { |
|
487 | + $target->{$method}($instance); |
|
488 | + }); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Fire the "rebound" callbacks for the given abstract type. |
|
493 | + * |
|
494 | + * @param string $abstract |
|
495 | + * @return void |
|
496 | + */ |
|
497 | + protected function rebound($abstract) |
|
498 | + { |
|
499 | + $instance = $this->make($abstract); |
|
500 | + |
|
501 | + foreach ($this->getReboundCallbacks($abstract) as $callback) { |
|
502 | + call_user_func($callback, $this, $instance); |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Get the rebound callbacks for a given type. |
|
508 | + * |
|
509 | + * @param string $abstract |
|
510 | + * @return array |
|
511 | + */ |
|
512 | + protected function getReboundCallbacks($abstract) |
|
513 | + { |
|
514 | + if (isset($this->reboundCallbacks[$abstract])) { |
|
515 | + return $this->reboundCallbacks[$abstract]; |
|
516 | + } |
|
517 | + |
|
518 | + return []; |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * Wrap the given closure such that its dependencies will be injected when executed. |
|
523 | + * |
|
524 | + * @param \Closure $callback |
|
525 | + * @param array $parameters |
|
526 | + * @return \Closure |
|
527 | + */ |
|
528 | + public function wrap(Closure $callback, array $parameters = []) |
|
529 | + { |
|
530 | + return function () use ($callback, $parameters) { |
|
531 | + return $this->call($callback, $parameters); |
|
532 | + }; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Call the given Closure / class@method and inject its dependencies. |
|
537 | + * |
|
538 | + * @param callable|string $callback |
|
539 | + * @param array $parameters |
|
540 | + * @param string|null $defaultMethod |
|
541 | + * @return mixed |
|
542 | + */ |
|
543 | + public function call($callback, array $parameters = [], $defaultMethod = null) |
|
544 | + { |
|
545 | + return BoundMethod::call($this, $callback, $parameters, $defaultMethod); |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Get a closure to resolve the given type from the container. |
|
550 | + * |
|
551 | + * @param string $abstract |
|
552 | + * @return \Closure |
|
553 | + */ |
|
554 | + public function factory($abstract) |
|
555 | + { |
|
556 | + return function () use ($abstract) { |
|
557 | + return $this->make($abstract); |
|
558 | + }; |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Resolve the given type with the given parameter overrides. |
|
563 | + * |
|
564 | + * @param string $abstract |
|
565 | + * @param array $parameters |
|
566 | + * @return mixed |
|
567 | + */ |
|
568 | + public function makeWith($abstract, array $parameters) |
|
569 | + { |
|
570 | + return $this->resolve($abstract, $parameters); |
|
571 | + } |
|
572 | + |
|
573 | + /** |
|
574 | + * Resolve the given type from the container. |
|
575 | + * |
|
576 | + * @param string $abstract |
|
577 | + * @return mixed |
|
578 | + */ |
|
579 | + public function make($abstract) |
|
580 | + { |
|
581 | + return $this->resolve($abstract); |
|
582 | + } |
|
583 | + |
|
584 | + /** |
|
585 | + * Resolve the given type from the container. |
|
586 | + * |
|
587 | + * @param string $abstract |
|
588 | + * @param array $parameters |
|
589 | + * @return mixed |
|
590 | + */ |
|
591 | + protected function resolve($abstract, $parameters = []) |
|
592 | + { |
|
593 | + $abstract = $this->getAlias($abstract); |
|
594 | + |
|
595 | + $needsContextualBuild = ! empty($parameters) || ! is_null( |
|
596 | + $this->getContextualConcrete($abstract) |
|
597 | + ); |
|
598 | + |
|
599 | + // If an instance of the type is currently being managed as a singleton we'll |
|
600 | + // just return an existing instance instead of instantiating new instances |
|
601 | + // so the developer can keep using the same objects instance every time. |
|
602 | + if (isset($this->instances[$abstract]) && ! $needsContextualBuild) { |
|
603 | + return $this->instances[$abstract]; |
|
604 | + } |
|
605 | + |
|
606 | + $this->with[] = $parameters; |
|
607 | + |
|
608 | + $concrete = $this->getConcrete($abstract); |
|
609 | + |
|
610 | + // We're ready to instantiate an instance of the concrete type registered for |
|
611 | + // the binding. This will instantiate the types, as well as resolve any of |
|
612 | + // its "nested" dependencies recursively until all have gotten resolved. |
|
613 | + if ($this->isBuildable($concrete, $abstract)) { |
|
614 | + $object = $this->build($concrete); |
|
615 | + } else { |
|
616 | + $object = $this->make($concrete); |
|
617 | + } |
|
618 | + |
|
619 | + // If we defined any extenders for this type, we'll need to spin through them |
|
620 | + // and apply them to the object being built. This allows for the extension |
|
621 | + // of services, such as changing configuration or decorating the object. |
|
622 | + foreach ($this->getExtenders($abstract) as $extender) { |
|
623 | + $object = $extender($object, $this); |
|
624 | + } |
|
625 | + |
|
626 | + // If the requested type is registered as a singleton we'll want to cache off |
|
627 | + // the instances in "memory" so we can return it later without creating an |
|
628 | + // entirely new instance of an object on each subsequent request for it. |
|
629 | + if ($this->isShared($abstract) && ! $needsContextualBuild) { |
|
630 | + $this->instances[$abstract] = $object; |
|
631 | + } |
|
632 | + |
|
633 | + $this->fireResolvingCallbacks($abstract, $object); |
|
634 | + |
|
635 | + // Before returning, we will also set the resolved flag to "true" and pop off |
|
636 | + // the parameter overrides for this build. After those two things are done |
|
637 | + // we will be ready to return back the fully constructed class instance. |
|
638 | + $this->resolved[$abstract] = true; |
|
639 | + |
|
640 | + array_pop($this->with); |
|
641 | + |
|
642 | + return $object; |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Get the concrete type for a given abstract. |
|
647 | + * |
|
648 | + * @param string $abstract |
|
649 | + * @return mixed $concrete |
|
650 | + */ |
|
651 | + protected function getConcrete($abstract) |
|
652 | + { |
|
653 | + if (! is_null($concrete = $this->getContextualConcrete($abstract))) { |
|
654 | + return $concrete; |
|
655 | + } |
|
656 | + |
|
657 | + // If we don't have a registered resolver or concrete for the type, we'll just |
|
658 | + // assume each type is a concrete name and will attempt to resolve it as is |
|
659 | + // since the container should be able to resolve concretes automatically. |
|
660 | + if (isset($this->bindings[$abstract])) { |
|
661 | + return $this->bindings[$abstract]['concrete']; |
|
662 | + } |
|
663 | + |
|
664 | + return $abstract; |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Get the contextual concrete binding for the given abstract. |
|
669 | + * |
|
670 | + * @param string $abstract |
|
671 | + * @return string|null |
|
672 | + */ |
|
673 | + protected function getContextualConcrete($abstract) |
|
674 | + { |
|
675 | + if (! is_null($binding = $this->findInContextualBindings($abstract))) { |
|
676 | + return $binding; |
|
677 | + } |
|
678 | + |
|
679 | + // Next we need to see if a contextual binding might be bound under an alias of the |
|
680 | + // given abstract type. So, we will need to check if any aliases exist with this |
|
681 | + // type and then spin through them and check for contextual bindings on these. |
|
682 | + if (empty($this->abstractAliases[$abstract])) { |
|
683 | + return; |
|
684 | + } |
|
685 | + |
|
686 | + foreach ($this->abstractAliases[$abstract] as $alias) { |
|
687 | + if (! is_null($binding = $this->findInContextualBindings($alias))) { |
|
688 | + return $binding; |
|
689 | + } |
|
690 | + } |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Find the concrete binding for the given abstract in the contextual binding array. |
|
695 | + * |
|
696 | + * @param string $abstract |
|
697 | + * @return string|null |
|
698 | + */ |
|
699 | + protected function findInContextualBindings($abstract) |
|
700 | + { |
|
701 | + if (isset($this->contextual[end($this->buildStack)][$abstract])) { |
|
702 | + return $this->contextual[end($this->buildStack)][$abstract]; |
|
703 | + } |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * Determine if the given concrete is buildable. |
|
708 | + * |
|
709 | + * @param mixed $concrete |
|
710 | + * @param string $abstract |
|
711 | + * @return bool |
|
712 | + */ |
|
713 | + protected function isBuildable($concrete, $abstract) |
|
714 | + { |
|
715 | + return $concrete === $abstract || $concrete instanceof Closure; |
|
716 | + } |
|
717 | + |
|
718 | + /** |
|
719 | + * Instantiate a concrete instance of the given type. |
|
720 | + * |
|
721 | + * @param string $concrete |
|
722 | + * @return mixed |
|
723 | + * |
|
724 | + * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
725 | + */ |
|
726 | + public function build($concrete) |
|
727 | + { |
|
728 | + // If the concrete type is actually a Closure, we will just execute it and |
|
729 | + // hand back the results of the functions, which allows functions to be |
|
730 | + // used as resolvers for more fine-tuned resolution of these objects. |
|
731 | + if ($concrete instanceof Closure) { |
|
732 | + return $concrete($this, $this->getLastParameterOverride()); |
|
733 | + } |
|
734 | + |
|
735 | + $reflector = new ReflectionClass($concrete); |
|
736 | + |
|
737 | + // If the type is not instantiable, the developer is attempting to resolve |
|
738 | + // an abstract type such as an Interface of Abstract Class and there is |
|
739 | + // no binding registered for the abstractions so we need to bail out. |
|
740 | + if (! $reflector->isInstantiable()) { |
|
741 | + return $this->notInstantiable($concrete); |
|
742 | + } |
|
743 | + |
|
744 | + $this->buildStack[] = $concrete; |
|
745 | + |
|
746 | + $constructor = $reflector->getConstructor(); |
|
747 | + |
|
748 | + // If there are no constructors, that means there are no dependencies then |
|
749 | + // we can just resolve the instances of the objects right away, without |
|
750 | + // resolving any other types or dependencies out of these containers. |
|
751 | + if (is_null($constructor)) { |
|
752 | + array_pop($this->buildStack); |
|
753 | + |
|
754 | + return new $concrete; |
|
755 | + } |
|
756 | + |
|
757 | + $dependencies = $constructor->getParameters(); |
|
758 | + |
|
759 | + // Once we have all the constructor's parameters we can create each of the |
|
760 | + // dependency instances and then use the reflection instances to make a |
|
761 | + // new instance of this class, injecting the created dependencies in. |
|
762 | + $instances = $this->resolveDependencies( |
|
763 | + $dependencies |
|
764 | + ); |
|
765 | + |
|
766 | + array_pop($this->buildStack); |
|
767 | + |
|
768 | + return $reflector->newInstanceArgs($instances); |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * Resolve all of the dependencies from the ReflectionParameters. |
|
773 | + * |
|
774 | + * @param array $dependencies |
|
775 | + * @return array |
|
776 | + */ |
|
777 | + protected function resolveDependencies(array $dependencies) |
|
778 | + { |
|
779 | + $results = []; |
|
780 | + |
|
781 | + foreach ($dependencies as $dependency) { |
|
782 | + // If this dependency has a override for this particular build we will use |
|
783 | + // that instead as the value. Otherwise, we will continue with this run |
|
784 | + // of resolutions and let reflection attempt to determine the result. |
|
785 | + if ($this->hasParameterOverride($dependency)) { |
|
786 | + $results[] = $this->getParameterOverride($dependency); |
|
787 | + |
|
788 | + continue; |
|
789 | + } |
|
790 | + |
|
791 | + // If the class is null, it means the dependency is a string or some other |
|
792 | + // primitive type which we can not resolve since it is not a class and |
|
793 | + // we will just bomb out with an error since we have no-where to go. |
|
794 | + $results[] = is_null($class = $dependency->getClass()) |
|
795 | + ? $this->resolvePrimitive($dependency) |
|
796 | + : $this->resolveClass($dependency); |
|
797 | + } |
|
798 | + |
|
799 | + return $results; |
|
800 | + } |
|
801 | + |
|
802 | + /** |
|
803 | + * Determine if the given dependency has a parameter override from makeWith. |
|
804 | + * |
|
805 | + * @param \ReflectionParameter $dependency |
|
806 | + * @return bool |
|
807 | + */ |
|
808 | + protected function hasParameterOverride($dependency) |
|
809 | + { |
|
810 | + return array_key_exists( |
|
811 | + $dependency->name, $this->getLastParameterOverride() |
|
812 | + ); |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Get a parameter override for a dependency. |
|
817 | + * |
|
818 | + * @param \ReflectionParameter $dependency |
|
819 | + * @return mixed |
|
820 | + */ |
|
821 | + protected function getParameterOverride($dependency) |
|
822 | + { |
|
823 | + return $this->getLastParameterOverride()[$dependency->name]; |
|
824 | + } |
|
825 | + |
|
826 | + /** |
|
827 | + * Get the last parameter override. |
|
828 | + * |
|
829 | + * @return array |
|
830 | + */ |
|
831 | + protected function getLastParameterOverride() |
|
832 | + { |
|
833 | + return count($this->with) ? end($this->with) : []; |
|
834 | + } |
|
835 | + |
|
836 | + /** |
|
837 | + * Resolve a non-class hinted primitive dependency. |
|
838 | + * |
|
839 | + * @param \ReflectionParameter $parameter |
|
840 | + * @return mixed |
|
841 | + * |
|
842 | + * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
843 | + */ |
|
844 | + protected function resolvePrimitive(ReflectionParameter $parameter) |
|
845 | + { |
|
846 | + if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->name))) { |
|
847 | + return $concrete instanceof Closure ? $concrete($this) : $concrete; |
|
848 | + } |
|
849 | + |
|
850 | + if ($parameter->isDefaultValueAvailable()) { |
|
851 | + return $parameter->getDefaultValue(); |
|
852 | + } |
|
853 | + |
|
854 | + $this->unresolvablePrimitive($parameter); |
|
855 | + } |
|
856 | + |
|
857 | + /** |
|
858 | + * Resolve a class based dependency from the container. |
|
859 | + * |
|
860 | + * @param \ReflectionParameter $parameter |
|
861 | + * @return mixed |
|
862 | + * |
|
863 | + * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
864 | + */ |
|
865 | + protected function resolveClass(ReflectionParameter $parameter) |
|
866 | + { |
|
867 | + try { |
|
868 | + return $this->make($parameter->getClass()->name); |
|
869 | + } |
|
870 | + |
|
871 | + // If we can not resolve the class instance, we will check to see if the value |
|
872 | + // is optional, and if it is we will return the optional parameter value as |
|
873 | + // the value of the dependency, similarly to how we do this with scalars. |
|
874 | + catch (BindingResolutionException $e) { |
|
875 | + if ($parameter->isOptional()) { |
|
876 | + return $parameter->getDefaultValue(); |
|
877 | + } |
|
878 | + |
|
879 | + throw $e; |
|
880 | + } |
|
881 | + } |
|
882 | + |
|
883 | + /** |
|
884 | + * Throw an exception that the concrete is not instantiable. |
|
885 | + * |
|
886 | + * @param string $concrete |
|
887 | + * @return void |
|
888 | + * |
|
889 | + * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
890 | + */ |
|
891 | + protected function notInstantiable($concrete) |
|
892 | + { |
|
893 | + if (! empty($this->buildStack)) { |
|
894 | + $previous = implode(', ', $this->buildStack); |
|
895 | + |
|
896 | + $message = "Target [$concrete] is not instantiable while building [$previous]."; |
|
897 | + } else { |
|
898 | + $message = "Target [$concrete] is not instantiable."; |
|
899 | + } |
|
900 | + |
|
901 | + throw new BindingResolutionException($message); |
|
902 | + } |
|
903 | + |
|
904 | + /** |
|
905 | + * Throw an exception for an unresolvable primitive. |
|
906 | + * |
|
907 | + * @param \ReflectionParameter $parameter |
|
908 | + * @return void |
|
909 | + * |
|
910 | + * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
|
911 | + */ |
|
912 | + protected function unresolvablePrimitive(ReflectionParameter $parameter) |
|
913 | + { |
|
914 | + $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}"; |
|
915 | + |
|
916 | + throw new BindingResolutionException($message); |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * Register a new resolving callback. |
|
921 | + * |
|
922 | + * @param string $abstract |
|
923 | + * @param \Closure|null $callback |
|
924 | + * @return void |
|
925 | + */ |
|
926 | + public function resolving($abstract, Closure $callback = null) |
|
927 | + { |
|
928 | + if (is_string($abstract)) { |
|
929 | + $abstract = $this->getAlias($abstract); |
|
930 | + } |
|
931 | + |
|
932 | + if (is_null($callback) && $abstract instanceof Closure) { |
|
933 | + $this->globalResolvingCallbacks[] = $abstract; |
|
934 | + } else { |
|
935 | + $this->resolvingCallbacks[$abstract][] = $callback; |
|
936 | + } |
|
937 | + } |
|
938 | + |
|
939 | + /** |
|
940 | + * Register a new after resolving callback for all types. |
|
941 | + * |
|
942 | + * @param string $abstract |
|
943 | + * @param \Closure|null $callback |
|
944 | + * @return void |
|
945 | + */ |
|
946 | + public function afterResolving($abstract, Closure $callback = null) |
|
947 | + { |
|
948 | + if (is_string($abstract)) { |
|
949 | + $abstract = $this->getAlias($abstract); |
|
950 | + } |
|
951 | + |
|
952 | + if ($abstract instanceof Closure && is_null($callback)) { |
|
953 | + $this->globalAfterResolvingCallbacks[] = $abstract; |
|
954 | + } else { |
|
955 | + $this->afterResolvingCallbacks[$abstract][] = $callback; |
|
956 | + } |
|
957 | + } |
|
958 | + |
|
959 | + /** |
|
960 | + * Fire all of the resolving callbacks. |
|
961 | + * |
|
962 | + * @param string $abstract |
|
963 | + * @param mixed $object |
|
964 | + * @return void |
|
965 | + */ |
|
966 | + protected function fireResolvingCallbacks($abstract, $object) |
|
967 | + { |
|
968 | + $this->fireCallbackArray($object, $this->globalResolvingCallbacks); |
|
969 | + |
|
970 | + $this->fireCallbackArray( |
|
971 | + $object, $this->getCallbacksForType($abstract, $object, $this->resolvingCallbacks) |
|
972 | + ); |
|
973 | + |
|
974 | + $this->fireAfterResolvingCallbacks($abstract, $object); |
|
975 | + } |
|
976 | + |
|
977 | + /** |
|
978 | + * Fire all of the after resolving callbacks. |
|
979 | + * |
|
980 | + * @param string $abstract |
|
981 | + * @param mixed $object |
|
982 | + * @return void |
|
983 | + */ |
|
984 | + protected function fireAfterResolvingCallbacks($abstract, $object) |
|
985 | + { |
|
986 | + $this->fireCallbackArray($object, $this->globalAfterResolvingCallbacks); |
|
987 | + |
|
988 | + $this->fireCallbackArray( |
|
989 | + $object, $this->getCallbacksForType($abstract, $object, $this->afterResolvingCallbacks) |
|
990 | + ); |
|
991 | + } |
|
992 | + |
|
993 | + /** |
|
994 | + * Get all callbacks for a given type. |
|
995 | + * |
|
996 | + * @param string $abstract |
|
997 | + * @param object $object |
|
998 | + * @param array $callbacksPerType |
|
999 | + * |
|
1000 | + * @return array |
|
1001 | + */ |
|
1002 | + protected function getCallbacksForType($abstract, $object, array $callbacksPerType) |
|
1003 | + { |
|
1004 | + $results = []; |
|
1005 | + |
|
1006 | + foreach ($callbacksPerType as $type => $callbacks) { |
|
1007 | + if ($type === $abstract || $object instanceof $type) { |
|
1008 | + $results = array_merge($results, $callbacks); |
|
1009 | + } |
|
1010 | + } |
|
1011 | + |
|
1012 | + return $results; |
|
1013 | + } |
|
1014 | + |
|
1015 | + /** |
|
1016 | + * Fire an array of callbacks with an object. |
|
1017 | + * |
|
1018 | + * @param mixed $object |
|
1019 | + * @param array $callbacks |
|
1020 | + * @return void |
|
1021 | + */ |
|
1022 | + protected function fireCallbackArray($object, array $callbacks) |
|
1023 | + { |
|
1024 | + foreach ($callbacks as $callback) { |
|
1025 | + $callback($object, $this); |
|
1026 | + } |
|
1027 | + } |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * Get the container's bindings. |
|
1031 | + * |
|
1032 | + * @return array |
|
1033 | + */ |
|
1034 | + public function getBindings() |
|
1035 | + { |
|
1036 | + return $this->bindings; |
|
1037 | + } |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * Get the alias for an abstract if available. |
|
1041 | + * |
|
1042 | + * @param string $abstract |
|
1043 | + * @return string |
|
1044 | + * |
|
1045 | + * @throws \LogicException |
|
1046 | + */ |
|
1047 | + public function getAlias($abstract) |
|
1048 | + { |
|
1049 | + if (! isset($this->aliases[$abstract])) { |
|
1050 | + return $abstract; |
|
1051 | + } |
|
1052 | + |
|
1053 | + if ($this->aliases[$abstract] === $abstract) { |
|
1054 | + throw new LogicException("[{$abstract}] is aliased to itself."); |
|
1055 | + } |
|
1056 | + |
|
1057 | + return $this->getAlias($this->aliases[$abstract]); |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Get the extender callbacks for a given type. |
|
1062 | + * |
|
1063 | + * @param string $abstract |
|
1064 | + * @return array |
|
1065 | + */ |
|
1066 | + protected function getExtenders($abstract) |
|
1067 | + { |
|
1068 | + $abstract = $this->getAlias($abstract); |
|
1069 | + |
|
1070 | + if (isset($this->extenders[$abstract])) { |
|
1071 | + return $this->extenders[$abstract]; |
|
1072 | + } |
|
1073 | + |
|
1074 | + return []; |
|
1075 | + } |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * Remove all of the extender callbacks for a given type. |
|
1079 | + * |
|
1080 | + * @param string $abstract |
|
1081 | + * @return void |
|
1082 | + */ |
|
1083 | + public function forgetExtenders($abstract) |
|
1084 | + { |
|
1085 | + unset($this->extenders[$this->getAlias($abstract)]); |
|
1086 | + } |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * Drop all of the stale instances and aliases. |
|
1090 | + * |
|
1091 | + * @param string $abstract |
|
1092 | + * @return void |
|
1093 | + */ |
|
1094 | + protected function dropStaleInstances($abstract) |
|
1095 | + { |
|
1096 | + unset($this->instances[$abstract], $this->aliases[$abstract]); |
|
1097 | + } |
|
1098 | + |
|
1099 | + /** |
|
1100 | + * Remove a resolved instance from the instance cache. |
|
1101 | + * |
|
1102 | + * @param string $abstract |
|
1103 | + * @return void |
|
1104 | + */ |
|
1105 | + public function forgetInstance($abstract) |
|
1106 | + { |
|
1107 | + unset($this->instances[$abstract]); |
|
1108 | + } |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * Clear all of the instances from the container. |
|
1112 | + * |
|
1113 | + * @return void |
|
1114 | + */ |
|
1115 | + public function forgetInstances() |
|
1116 | + { |
|
1117 | + $this->instances = []; |
|
1118 | + } |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * Flush the container of all bindings and resolved instances. |
|
1122 | + * |
|
1123 | + * @return void |
|
1124 | + */ |
|
1125 | + public function flush() |
|
1126 | + { |
|
1127 | + $this->aliases = []; |
|
1128 | + $this->resolved = []; |
|
1129 | + $this->bindings = []; |
|
1130 | + $this->instances = []; |
|
1131 | + $this->abstractAliases = []; |
|
1132 | + } |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * Set the globally available instance of the container. |
|
1136 | + * |
|
1137 | + * @return static |
|
1138 | + */ |
|
1139 | + public static function getInstance() |
|
1140 | + { |
|
1141 | + if (is_null(static::$instance)) { |
|
1142 | + static::$instance = new static; |
|
1143 | + } |
|
1144 | + |
|
1145 | + return static::$instance; |
|
1146 | + } |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Set the shared instance of the container. |
|
1150 | + * |
|
1151 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\Container|null $container |
|
1152 | + * @return static |
|
1153 | + */ |
|
1154 | + public static function setInstance(ContainerContract $container = null) |
|
1155 | + { |
|
1156 | + return static::$instance = $container; |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * Determine if a given offset exists. |
|
1161 | + * |
|
1162 | + * @param string $key |
|
1163 | + * @return bool |
|
1164 | + */ |
|
1165 | + public function offsetExists($key) |
|
1166 | + { |
|
1167 | + return $this->bound($key); |
|
1168 | + } |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * Get the value at a given offset. |
|
1172 | + * |
|
1173 | + * @param string $key |
|
1174 | + * @return mixed |
|
1175 | + */ |
|
1176 | + public function offsetGet($key) |
|
1177 | + { |
|
1178 | + return $this->make($key); |
|
1179 | + } |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Set the value at a given offset. |
|
1183 | + * |
|
1184 | + * @param string $key |
|
1185 | + * @param mixed $value |
|
1186 | + * @return void |
|
1187 | + */ |
|
1188 | + public function offsetSet($key, $value) |
|
1189 | + { |
|
1190 | + $this->bind($key, $value instanceof Closure ? $value : function () use ($value) { |
|
1191 | + return $value; |
|
1192 | + }); |
|
1193 | + } |
|
1194 | + |
|
1195 | + /** |
|
1196 | + * Unset the value at a given offset. |
|
1197 | + * |
|
1198 | + * @param string $key |
|
1199 | + * @return void |
|
1200 | + */ |
|
1201 | + public function offsetUnset($key) |
|
1202 | + { |
|
1203 | + unset($this->bindings[$key], $this->instances[$key], $this->resolved[$key]); |
|
1204 | + } |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * Dynamically access container services. |
|
1208 | + * |
|
1209 | + * @param string $key |
|
1210 | + * @return mixed |
|
1211 | + */ |
|
1212 | + public function __get($key) |
|
1213 | + { |
|
1214 | + return $this[$key]; |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * Dynamically set container services. |
|
1219 | + * |
|
1220 | + * @param string $key |
|
1221 | + * @param mixed $value |
|
1222 | + * @return void |
|
1223 | + */ |
|
1224 | + public function __set($key, $value) |
|
1225 | + { |
|
1226 | + $this[$key] = $value; |
|
1227 | + } |
|
1228 | 1228 | } |
@@ -30,112 +30,112 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @var array |
32 | 32 | */ |
33 | - protected $resolved = []; |
|
33 | + protected $resolved = [ ]; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * The container's bindings. |
37 | 37 | * |
38 | 38 | * @var array |
39 | 39 | */ |
40 | - protected $bindings = []; |
|
40 | + protected $bindings = [ ]; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * The container's method bindings. |
44 | 44 | * |
45 | 45 | * @var array |
46 | 46 | */ |
47 | - protected $methodBindings = []; |
|
47 | + protected $methodBindings = [ ]; |
|
48 | 48 | |
49 | 49 | /** |
50 | 50 | * The container's shared instances. |
51 | 51 | * |
52 | 52 | * @var array |
53 | 53 | */ |
54 | - protected $instances = []; |
|
54 | + protected $instances = [ ]; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * The registered type aliases. |
58 | 58 | * |
59 | 59 | * @var array |
60 | 60 | */ |
61 | - protected $aliases = []; |
|
61 | + protected $aliases = [ ]; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * The registered aliases keyed by the abstract name. |
65 | 65 | * |
66 | 66 | * @var array |
67 | 67 | */ |
68 | - protected $abstractAliases = []; |
|
68 | + protected $abstractAliases = [ ]; |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * The extension closures for services. |
72 | 72 | * |
73 | 73 | * @var array |
74 | 74 | */ |
75 | - protected $extenders = []; |
|
75 | + protected $extenders = [ ]; |
|
76 | 76 | |
77 | 77 | /** |
78 | 78 | * All of the registered tags. |
79 | 79 | * |
80 | 80 | * @var array |
81 | 81 | */ |
82 | - protected $tags = []; |
|
82 | + protected $tags = [ ]; |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * The stack of concretions currently being built. |
86 | 86 | * |
87 | 87 | * @var array |
88 | 88 | */ |
89 | - protected $buildStack = []; |
|
89 | + protected $buildStack = [ ]; |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * The parameter override stack. |
93 | 93 | * |
94 | 94 | * @var array |
95 | 95 | */ |
96 | - protected $with = []; |
|
96 | + protected $with = [ ]; |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * The contextual binding map. |
100 | 100 | * |
101 | 101 | * @var array |
102 | 102 | */ |
103 | - public $contextual = []; |
|
103 | + public $contextual = [ ]; |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * All of the registered rebound callbacks. |
107 | 107 | * |
108 | 108 | * @var array |
109 | 109 | */ |
110 | - protected $reboundCallbacks = []; |
|
110 | + protected $reboundCallbacks = [ ]; |
|
111 | 111 | |
112 | 112 | /** |
113 | 113 | * All of the global resolving callbacks. |
114 | 114 | * |
115 | 115 | * @var array |
116 | 116 | */ |
117 | - protected $globalResolvingCallbacks = []; |
|
117 | + protected $globalResolvingCallbacks = [ ]; |
|
118 | 118 | |
119 | 119 | /** |
120 | 120 | * All of the global after resolving callbacks. |
121 | 121 | * |
122 | 122 | * @var array |
123 | 123 | */ |
124 | - protected $globalAfterResolvingCallbacks = []; |
|
124 | + protected $globalAfterResolvingCallbacks = [ ]; |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * All of the resolving callbacks by class type. |
128 | 128 | * |
129 | 129 | * @var array |
130 | 130 | */ |
131 | - protected $resolvingCallbacks = []; |
|
131 | + protected $resolvingCallbacks = [ ]; |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * All of the after resolving callbacks by class type. |
135 | 135 | * |
136 | 136 | * @var array |
137 | 137 | */ |
138 | - protected $afterResolvingCallbacks = []; |
|
138 | + protected $afterResolvingCallbacks = [ ]; |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Define a contextual binding. |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | * @param string $concrete |
144 | 144 | * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\ContextualBindingBuilder |
145 | 145 | */ |
146 | - public function when($concrete) |
|
146 | + public function when( $concrete ) |
|
147 | 147 | { |
148 | - return new ContextualBindingBuilder($this, $this->getAlias($concrete)); |
|
148 | + return new ContextualBindingBuilder( $this, $this->getAlias( $concrete ) ); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | * @param string $abstract |
155 | 155 | * @return bool |
156 | 156 | */ |
157 | - public function bound($abstract) |
|
157 | + public function bound( $abstract ) |
|
158 | 158 | { |
159 | - return isset($this->bindings[$abstract]) || |
|
160 | - isset($this->instances[$abstract]) || |
|
161 | - $this->isAlias($abstract); |
|
159 | + return isset( $this->bindings[ $abstract ] ) || |
|
160 | + isset( $this->instances[ $abstract ] ) || |
|
161 | + $this->isAlias( $abstract ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -167,14 +167,14 @@ discard block |
||
167 | 167 | * @param string $abstract |
168 | 168 | * @return bool |
169 | 169 | */ |
170 | - public function resolved($abstract) |
|
170 | + public function resolved( $abstract ) |
|
171 | 171 | { |
172 | - if ($this->isAlias($abstract)) { |
|
173 | - $abstract = $this->getAlias($abstract); |
|
172 | + if ( $this->isAlias( $abstract ) ) { |
|
173 | + $abstract = $this->getAlias( $abstract ); |
|
174 | 174 | } |
175 | 175 | |
176 | - return isset($this->resolved[$abstract]) || |
|
177 | - isset($this->instances[$abstract]); |
|
176 | + return isset( $this->resolved[ $abstract ] ) || |
|
177 | + isset( $this->instances[ $abstract ] ); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -183,11 +183,11 @@ discard block |
||
183 | 183 | * @param string $abstract |
184 | 184 | * @return bool |
185 | 185 | */ |
186 | - public function isShared($abstract) |
|
186 | + public function isShared( $abstract ) |
|
187 | 187 | { |
188 | - return isset($this->instances[$abstract]) || |
|
189 | - (isset($this->bindings[$abstract]['shared']) && |
|
190 | - $this->bindings[$abstract]['shared'] === true); |
|
188 | + return isset( $this->instances[ $abstract ] ) || |
|
189 | + ( isset( $this->bindings[ $abstract ][ 'shared' ] ) && |
|
190 | + $this->bindings[ $abstract ][ 'shared' ] === true ); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -196,9 +196,9 @@ discard block |
||
196 | 196 | * @param string $name |
197 | 197 | * @return bool |
198 | 198 | */ |
199 | - public function isAlias($name) |
|
199 | + public function isAlias( $name ) |
|
200 | 200 | { |
201 | - return isset($this->aliases[$name]); |
|
201 | + return isset( $this->aliases[ $name ] ); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -209,31 +209,31 @@ discard block |
||
209 | 209 | * @param bool $shared |
210 | 210 | * @return void |
211 | 211 | */ |
212 | - public function bind($abstract, $concrete = null, $shared = false) |
|
212 | + public function bind( $abstract, $concrete = null, $shared = false ) |
|
213 | 213 | { |
214 | 214 | // If no concrete type was given, we will simply set the concrete type to the |
215 | 215 | // abstract type. After that, the concrete type to be registered as shared |
216 | 216 | // without being forced to state their classes in both of the parameters. |
217 | - $this->dropStaleInstances($abstract); |
|
217 | + $this->dropStaleInstances( $abstract ); |
|
218 | 218 | |
219 | - if (is_null($concrete)) { |
|
219 | + if ( is_null( $concrete ) ) { |
|
220 | 220 | $concrete = $abstract; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // If the factory is not a Closure, it means it is just a class name which is |
224 | 224 | // bound into this container to the abstract type and we will just wrap it |
225 | 225 | // up inside its own Closure to give us more convenience when extending. |
226 | - if (! $concrete instanceof Closure) { |
|
227 | - $concrete = $this->getClosure($abstract, $concrete); |
|
226 | + if ( ! $concrete instanceof Closure ) { |
|
227 | + $concrete = $this->getClosure( $abstract, $concrete ); |
|
228 | 228 | } |
229 | 229 | |
230 | - $this->bindings[$abstract] = compact('concrete', 'shared'); |
|
230 | + $this->bindings[ $abstract ] = compact( 'concrete', 'shared' ); |
|
231 | 231 | |
232 | 232 | // If the abstract type was already resolved in this container we'll fire the |
233 | 233 | // rebound listener so that any objects which have already gotten resolved |
234 | 234 | // can have their copy of the object updated via the listener callbacks. |
235 | - if ($this->resolved($abstract)) { |
|
236 | - $this->rebound($abstract); |
|
235 | + if ( $this->resolved( $abstract ) ) { |
|
236 | + $this->rebound( $abstract ); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
@@ -244,14 +244,14 @@ discard block |
||
244 | 244 | * @param string $concrete |
245 | 245 | * @return \Closure |
246 | 246 | */ |
247 | - protected function getClosure($abstract, $concrete) |
|
247 | + protected function getClosure( $abstract, $concrete ) |
|
248 | 248 | { |
249 | - return function ($container, $parameters = []) use ($abstract, $concrete) { |
|
250 | - if ($abstract == $concrete) { |
|
251 | - return $container->build($concrete); |
|
249 | + return function( $container, $parameters = [ ] ) use ( $abstract, $concrete ) { |
|
250 | + if ( $abstract == $concrete ) { |
|
251 | + return $container->build( $concrete ); |
|
252 | 252 | } |
253 | 253 | |
254 | - return $container->makeWith($concrete, $parameters); |
|
254 | + return $container->makeWith( $concrete, $parameters ); |
|
255 | 255 | }; |
256 | 256 | } |
257 | 257 | |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * @param string $method |
262 | 262 | * @return bool |
263 | 263 | */ |
264 | - public function hasMethodBinding($method) |
|
264 | + public function hasMethodBinding( $method ) |
|
265 | 265 | { |
266 | - return isset($this->methodBindings[$method]); |
|
266 | + return isset( $this->methodBindings[ $method ] ); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -273,9 +273,9 @@ discard block |
||
273 | 273 | * @param \Closure $callback |
274 | 274 | * @return void |
275 | 275 | */ |
276 | - public function bindMethod($method, $callback) |
|
276 | + public function bindMethod( $method, $callback ) |
|
277 | 277 | { |
278 | - $this->methodBindings[$method] = $callback; |
|
278 | + $this->methodBindings[ $method ] = $callback; |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
@@ -285,9 +285,9 @@ discard block |
||
285 | 285 | * @param mixed $instance |
286 | 286 | * @return mixed |
287 | 287 | */ |
288 | - public function callMethodBinding($method, $instance) |
|
288 | + public function callMethodBinding( $method, $instance ) |
|
289 | 289 | { |
290 | - return call_user_func($this->methodBindings[$method], $instance, $this); |
|
290 | + return call_user_func( $this->methodBindings[ $method ], $instance, $this ); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -298,9 +298,9 @@ discard block |
||
298 | 298 | * @param \Closure|string $implementation |
299 | 299 | * @return void |
300 | 300 | */ |
301 | - public function addContextualBinding($concrete, $abstract, $implementation) |
|
301 | + public function addContextualBinding( $concrete, $abstract, $implementation ) |
|
302 | 302 | { |
303 | - $this->contextual[$concrete][$this->getAlias($abstract)] = $implementation; |
|
303 | + $this->contextual[ $concrete ][ $this->getAlias( $abstract ) ] = $implementation; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -311,10 +311,10 @@ discard block |
||
311 | 311 | * @param bool $shared |
312 | 312 | * @return void |
313 | 313 | */ |
314 | - public function bindIf($abstract, $concrete = null, $shared = false) |
|
314 | + public function bindIf( $abstract, $concrete = null, $shared = false ) |
|
315 | 315 | { |
316 | - if (! $this->bound($abstract)) { |
|
317 | - $this->bind($abstract, $concrete, $shared); |
|
316 | + if ( ! $this->bound( $abstract ) ) { |
|
317 | + $this->bind( $abstract, $concrete, $shared ); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | * @param \Closure|string|null $concrete |
326 | 326 | * @return void |
327 | 327 | */ |
328 | - public function singleton($abstract, $concrete = null) |
|
328 | + public function singleton( $abstract, $concrete = null ) |
|
329 | 329 | { |
330 | - $this->bind($abstract, $concrete, true); |
|
330 | + $this->bind( $abstract, $concrete, true ); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -339,19 +339,19 @@ discard block |
||
339 | 339 | * |
340 | 340 | * @throws \InvalidArgumentException |
341 | 341 | */ |
342 | - public function extend($abstract, Closure $closure) |
|
342 | + public function extend( $abstract, Closure $closure ) |
|
343 | 343 | { |
344 | - $abstract = $this->getAlias($abstract); |
|
344 | + $abstract = $this->getAlias( $abstract ); |
|
345 | 345 | |
346 | - if (isset($this->instances[$abstract])) { |
|
347 | - $this->instances[$abstract] = $closure($this->instances[$abstract], $this); |
|
346 | + if ( isset( $this->instances[ $abstract ] ) ) { |
|
347 | + $this->instances[ $abstract ] = $closure( $this->instances[ $abstract ], $this ); |
|
348 | 348 | |
349 | - $this->rebound($abstract); |
|
349 | + $this->rebound( $abstract ); |
|
350 | 350 | } else { |
351 | - $this->extenders[$abstract][] = $closure; |
|
351 | + $this->extenders[ $abstract ][ ] = $closure; |
|
352 | 352 | |
353 | - if ($this->resolved($abstract)) { |
|
354 | - $this->rebound($abstract); |
|
353 | + if ( $this->resolved( $abstract ) ) { |
|
354 | + $this->rebound( $abstract ); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | } |
@@ -363,21 +363,21 @@ discard block |
||
363 | 363 | * @param mixed $instance |
364 | 364 | * @return void |
365 | 365 | */ |
366 | - public function instance($abstract, $instance) |
|
366 | + public function instance( $abstract, $instance ) |
|
367 | 367 | { |
368 | - $this->removeAbstractAlias($abstract); |
|
368 | + $this->removeAbstractAlias( $abstract ); |
|
369 | 369 | |
370 | - $isBound = $this->bound($abstract); |
|
370 | + $isBound = $this->bound( $abstract ); |
|
371 | 371 | |
372 | - unset($this->aliases[$abstract]); |
|
372 | + unset( $this->aliases[ $abstract ] ); |
|
373 | 373 | |
374 | 374 | // We'll check to determine if this type has been bound before, and if it has |
375 | 375 | // we will fire the rebound callbacks registered with the container and it |
376 | 376 | // can be updated with consuming classes that have gotten resolved here. |
377 | - $this->instances[$abstract] = $instance; |
|
377 | + $this->instances[ $abstract ] = $instance; |
|
378 | 378 | |
379 | - if ($isBound) { |
|
380 | - $this->rebound($abstract); |
|
379 | + if ( $isBound ) { |
|
380 | + $this->rebound( $abstract ); |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 | |
@@ -387,16 +387,16 @@ discard block |
||
387 | 387 | * @param string $searched |
388 | 388 | * @return void |
389 | 389 | */ |
390 | - protected function removeAbstractAlias($searched) |
|
390 | + protected function removeAbstractAlias( $searched ) |
|
391 | 391 | { |
392 | - if (! isset($this->aliases[$searched])) { |
|
392 | + if ( ! isset( $this->aliases[ $searched ] ) ) { |
|
393 | 393 | return; |
394 | 394 | } |
395 | 395 | |
396 | - foreach ($this->abstractAliases as $abstract => $aliases) { |
|
397 | - foreach ($aliases as $index => $alias) { |
|
398 | - if ($alias == $searched) { |
|
399 | - unset($this->abstractAliases[$abstract][$index]); |
|
396 | + foreach ( $this->abstractAliases as $abstract => $aliases ) { |
|
397 | + foreach ( $aliases as $index => $alias ) { |
|
398 | + if ( $alias == $searched ) { |
|
399 | + unset( $this->abstractAliases[ $abstract ][ $index ] ); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | } |
@@ -409,17 +409,17 @@ discard block |
||
409 | 409 | * @param array|mixed ...$tags |
410 | 410 | * @return void |
411 | 411 | */ |
412 | - public function tag($abstracts, $tags) |
|
412 | + public function tag( $abstracts, $tags ) |
|
413 | 413 | { |
414 | - $tags = is_array($tags) ? $tags : array_slice(func_get_args(), 1); |
|
414 | + $tags = is_array( $tags ) ? $tags : array_slice( func_get_args(), 1 ); |
|
415 | 415 | |
416 | - foreach ($tags as $tag) { |
|
417 | - if (! isset($this->tags[$tag])) { |
|
418 | - $this->tags[$tag] = []; |
|
416 | + foreach ( $tags as $tag ) { |
|
417 | + if ( ! isset( $this->tags[ $tag ] ) ) { |
|
418 | + $this->tags[ $tag ] = [ ]; |
|
419 | 419 | } |
420 | 420 | |
421 | - foreach ((array) $abstracts as $abstract) { |
|
422 | - $this->tags[$tag][] = $abstract; |
|
421 | + foreach ( (array)$abstracts as $abstract ) { |
|
422 | + $this->tags[ $tag ][ ] = $abstract; |
|
423 | 423 | } |
424 | 424 | } |
425 | 425 | } |
@@ -430,13 +430,13 @@ discard block |
||
430 | 430 | * @param string $tag |
431 | 431 | * @return array |
432 | 432 | */ |
433 | - public function tagged($tag) |
|
433 | + public function tagged( $tag ) |
|
434 | 434 | { |
435 | - $results = []; |
|
435 | + $results = [ ]; |
|
436 | 436 | |
437 | - if (isset($this->tags[$tag])) { |
|
438 | - foreach ($this->tags[$tag] as $abstract) { |
|
439 | - $results[] = $this->make($abstract); |
|
437 | + if ( isset( $this->tags[ $tag ] ) ) { |
|
438 | + foreach ( $this->tags[ $tag ] as $abstract ) { |
|
439 | + $results[ ] = $this->make( $abstract ); |
|
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
@@ -450,11 +450,11 @@ discard block |
||
450 | 450 | * @param string $alias |
451 | 451 | * @return void |
452 | 452 | */ |
453 | - public function alias($abstract, $alias) |
|
453 | + public function alias( $abstract, $alias ) |
|
454 | 454 | { |
455 | - $this->aliases[$alias] = $abstract; |
|
455 | + $this->aliases[ $alias ] = $abstract; |
|
456 | 456 | |
457 | - $this->abstractAliases[$abstract][] = $alias; |
|
457 | + $this->abstractAliases[ $abstract ][ ] = $alias; |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -464,12 +464,12 @@ discard block |
||
464 | 464 | * @param \Closure $callback |
465 | 465 | * @return mixed |
466 | 466 | */ |
467 | - public function rebinding($abstract, Closure $callback) |
|
467 | + public function rebinding( $abstract, Closure $callback ) |
|
468 | 468 | { |
469 | - $this->reboundCallbacks[$abstract = $this->getAlias($abstract)][] = $callback; |
|
469 | + $this->reboundCallbacks[ $abstract = $this->getAlias( $abstract ) ][ ] = $callback; |
|
470 | 470 | |
471 | - if ($this->bound($abstract)) { |
|
472 | - return $this->make($abstract); |
|
471 | + if ( $this->bound( $abstract ) ) { |
|
472 | + return $this->make( $abstract ); |
|
473 | 473 | } |
474 | 474 | } |
475 | 475 | |
@@ -481,10 +481,10 @@ discard block |
||
481 | 481 | * @param string $method |
482 | 482 | * @return mixed |
483 | 483 | */ |
484 | - public function refresh($abstract, $target, $method) |
|
484 | + public function refresh( $abstract, $target, $method ) |
|
485 | 485 | { |
486 | - return $this->rebinding($abstract, function ($app, $instance) use ($target, $method) { |
|
487 | - $target->{$method}($instance); |
|
486 | + return $this->rebinding( $abstract, function( $app, $instance ) use ( $target, $method ) { |
|
487 | + $target->{$method}( $instance ); |
|
488 | 488 | }); |
489 | 489 | } |
490 | 490 | |
@@ -494,12 +494,12 @@ discard block |
||
494 | 494 | * @param string $abstract |
495 | 495 | * @return void |
496 | 496 | */ |
497 | - protected function rebound($abstract) |
|
497 | + protected function rebound( $abstract ) |
|
498 | 498 | { |
499 | - $instance = $this->make($abstract); |
|
499 | + $instance = $this->make( $abstract ); |
|
500 | 500 | |
501 | - foreach ($this->getReboundCallbacks($abstract) as $callback) { |
|
502 | - call_user_func($callback, $this, $instance); |
|
501 | + foreach ( $this->getReboundCallbacks( $abstract ) as $callback ) { |
|
502 | + call_user_func( $callback, $this, $instance ); |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | |
@@ -509,13 +509,13 @@ discard block |
||
509 | 509 | * @param string $abstract |
510 | 510 | * @return array |
511 | 511 | */ |
512 | - protected function getReboundCallbacks($abstract) |
|
512 | + protected function getReboundCallbacks( $abstract ) |
|
513 | 513 | { |
514 | - if (isset($this->reboundCallbacks[$abstract])) { |
|
515 | - return $this->reboundCallbacks[$abstract]; |
|
514 | + if ( isset( $this->reboundCallbacks[ $abstract ] ) ) { |
|
515 | + return $this->reboundCallbacks[ $abstract ]; |
|
516 | 516 | } |
517 | 517 | |
518 | - return []; |
|
518 | + return [ ]; |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -525,10 +525,10 @@ discard block |
||
525 | 525 | * @param array $parameters |
526 | 526 | * @return \Closure |
527 | 527 | */ |
528 | - public function wrap(Closure $callback, array $parameters = []) |
|
528 | + public function wrap( Closure $callback, array $parameters = [ ] ) |
|
529 | 529 | { |
530 | - return function () use ($callback, $parameters) { |
|
531 | - return $this->call($callback, $parameters); |
|
530 | + return function() use ( $callback, $parameters ) { |
|
531 | + return $this->call( $callback, $parameters ); |
|
532 | 532 | }; |
533 | 533 | } |
534 | 534 | |
@@ -540,9 +540,9 @@ discard block |
||
540 | 540 | * @param string|null $defaultMethod |
541 | 541 | * @return mixed |
542 | 542 | */ |
543 | - public function call($callback, array $parameters = [], $defaultMethod = null) |
|
543 | + public function call( $callback, array $parameters = [ ], $defaultMethod = null ) |
|
544 | 544 | { |
545 | - return BoundMethod::call($this, $callback, $parameters, $defaultMethod); |
|
545 | + return BoundMethod::call( $this, $callback, $parameters, $defaultMethod ); |
|
546 | 546 | } |
547 | 547 | |
548 | 548 | /** |
@@ -551,10 +551,10 @@ discard block |
||
551 | 551 | * @param string $abstract |
552 | 552 | * @return \Closure |
553 | 553 | */ |
554 | - public function factory($abstract) |
|
554 | + public function factory( $abstract ) |
|
555 | 555 | { |
556 | - return function () use ($abstract) { |
|
557 | - return $this->make($abstract); |
|
556 | + return function() use ( $abstract ) { |
|
557 | + return $this->make( $abstract ); |
|
558 | 558 | }; |
559 | 559 | } |
560 | 560 | |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | * @param array $parameters |
566 | 566 | * @return mixed |
567 | 567 | */ |
568 | - public function makeWith($abstract, array $parameters) |
|
568 | + public function makeWith( $abstract, array $parameters ) |
|
569 | 569 | { |
570 | - return $this->resolve($abstract, $parameters); |
|
570 | + return $this->resolve( $abstract, $parameters ); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | * @param string $abstract |
577 | 577 | * @return mixed |
578 | 578 | */ |
579 | - public function make($abstract) |
|
579 | + public function make( $abstract ) |
|
580 | 580 | { |
581 | - return $this->resolve($abstract); |
|
581 | + return $this->resolve( $abstract ); |
|
582 | 582 | } |
583 | 583 | |
584 | 584 | /** |
@@ -588,56 +588,56 @@ discard block |
||
588 | 588 | * @param array $parameters |
589 | 589 | * @return mixed |
590 | 590 | */ |
591 | - protected function resolve($abstract, $parameters = []) |
|
591 | + protected function resolve( $abstract, $parameters = [ ] ) |
|
592 | 592 | { |
593 | - $abstract = $this->getAlias($abstract); |
|
593 | + $abstract = $this->getAlias( $abstract ); |
|
594 | 594 | |
595 | - $needsContextualBuild = ! empty($parameters) || ! is_null( |
|
596 | - $this->getContextualConcrete($abstract) |
|
595 | + $needsContextualBuild = ! empty( $parameters ) || ! is_null( |
|
596 | + $this->getContextualConcrete( $abstract ) |
|
597 | 597 | ); |
598 | 598 | |
599 | 599 | // If an instance of the type is currently being managed as a singleton we'll |
600 | 600 | // just return an existing instance instead of instantiating new instances |
601 | 601 | // so the developer can keep using the same objects instance every time. |
602 | - if (isset($this->instances[$abstract]) && ! $needsContextualBuild) { |
|
603 | - return $this->instances[$abstract]; |
|
602 | + if ( isset( $this->instances[ $abstract ] ) && ! $needsContextualBuild ) { |
|
603 | + return $this->instances[ $abstract ]; |
|
604 | 604 | } |
605 | 605 | |
606 | - $this->with[] = $parameters; |
|
606 | + $this->with[ ] = $parameters; |
|
607 | 607 | |
608 | - $concrete = $this->getConcrete($abstract); |
|
608 | + $concrete = $this->getConcrete( $abstract ); |
|
609 | 609 | |
610 | 610 | // We're ready to instantiate an instance of the concrete type registered for |
611 | 611 | // the binding. This will instantiate the types, as well as resolve any of |
612 | 612 | // its "nested" dependencies recursively until all have gotten resolved. |
613 | - if ($this->isBuildable($concrete, $abstract)) { |
|
614 | - $object = $this->build($concrete); |
|
613 | + if ( $this->isBuildable( $concrete, $abstract ) ) { |
|
614 | + $object = $this->build( $concrete ); |
|
615 | 615 | } else { |
616 | - $object = $this->make($concrete); |
|
616 | + $object = $this->make( $concrete ); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | // If we defined any extenders for this type, we'll need to spin through them |
620 | 620 | // and apply them to the object being built. This allows for the extension |
621 | 621 | // of services, such as changing configuration or decorating the object. |
622 | - foreach ($this->getExtenders($abstract) as $extender) { |
|
623 | - $object = $extender($object, $this); |
|
622 | + foreach ( $this->getExtenders( $abstract ) as $extender ) { |
|
623 | + $object = $extender( $object, $this ); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | // If the requested type is registered as a singleton we'll want to cache off |
627 | 627 | // the instances in "memory" so we can return it later without creating an |
628 | 628 | // entirely new instance of an object on each subsequent request for it. |
629 | - if ($this->isShared($abstract) && ! $needsContextualBuild) { |
|
630 | - $this->instances[$abstract] = $object; |
|
629 | + if ( $this->isShared( $abstract ) && ! $needsContextualBuild ) { |
|
630 | + $this->instances[ $abstract ] = $object; |
|
631 | 631 | } |
632 | 632 | |
633 | - $this->fireResolvingCallbacks($abstract, $object); |
|
633 | + $this->fireResolvingCallbacks( $abstract, $object ); |
|
634 | 634 | |
635 | 635 | // Before returning, we will also set the resolved flag to "true" and pop off |
636 | 636 | // the parameter overrides for this build. After those two things are done |
637 | 637 | // we will be ready to return back the fully constructed class instance. |
638 | - $this->resolved[$abstract] = true; |
|
638 | + $this->resolved[ $abstract ] = true; |
|
639 | 639 | |
640 | - array_pop($this->with); |
|
640 | + array_pop( $this->with ); |
|
641 | 641 | |
642 | 642 | return $object; |
643 | 643 | } |
@@ -648,17 +648,17 @@ discard block |
||
648 | 648 | * @param string $abstract |
649 | 649 | * @return mixed $concrete |
650 | 650 | */ |
651 | - protected function getConcrete($abstract) |
|
651 | + protected function getConcrete( $abstract ) |
|
652 | 652 | { |
653 | - if (! is_null($concrete = $this->getContextualConcrete($abstract))) { |
|
653 | + if ( ! is_null( $concrete = $this->getContextualConcrete( $abstract ) ) ) { |
|
654 | 654 | return $concrete; |
655 | 655 | } |
656 | 656 | |
657 | 657 | // If we don't have a registered resolver or concrete for the type, we'll just |
658 | 658 | // assume each type is a concrete name and will attempt to resolve it as is |
659 | 659 | // since the container should be able to resolve concretes automatically. |
660 | - if (isset($this->bindings[$abstract])) { |
|
661 | - return $this->bindings[$abstract]['concrete']; |
|
660 | + if ( isset( $this->bindings[ $abstract ] ) ) { |
|
661 | + return $this->bindings[ $abstract ][ 'concrete' ]; |
|
662 | 662 | } |
663 | 663 | |
664 | 664 | return $abstract; |
@@ -670,21 +670,21 @@ discard block |
||
670 | 670 | * @param string $abstract |
671 | 671 | * @return string|null |
672 | 672 | */ |
673 | - protected function getContextualConcrete($abstract) |
|
673 | + protected function getContextualConcrete( $abstract ) |
|
674 | 674 | { |
675 | - if (! is_null($binding = $this->findInContextualBindings($abstract))) { |
|
675 | + if ( ! is_null( $binding = $this->findInContextualBindings( $abstract ) ) ) { |
|
676 | 676 | return $binding; |
677 | 677 | } |
678 | 678 | |
679 | 679 | // Next we need to see if a contextual binding might be bound under an alias of the |
680 | 680 | // given abstract type. So, we will need to check if any aliases exist with this |
681 | 681 | // type and then spin through them and check for contextual bindings on these. |
682 | - if (empty($this->abstractAliases[$abstract])) { |
|
682 | + if ( empty( $this->abstractAliases[ $abstract ] ) ) { |
|
683 | 683 | return; |
684 | 684 | } |
685 | 685 | |
686 | - foreach ($this->abstractAliases[$abstract] as $alias) { |
|
687 | - if (! is_null($binding = $this->findInContextualBindings($alias))) { |
|
686 | + foreach ( $this->abstractAliases[ $abstract ] as $alias ) { |
|
687 | + if ( ! is_null( $binding = $this->findInContextualBindings( $alias ) ) ) { |
|
688 | 688 | return $binding; |
689 | 689 | } |
690 | 690 | } |
@@ -696,10 +696,10 @@ discard block |
||
696 | 696 | * @param string $abstract |
697 | 697 | * @return string|null |
698 | 698 | */ |
699 | - protected function findInContextualBindings($abstract) |
|
699 | + protected function findInContextualBindings( $abstract ) |
|
700 | 700 | { |
701 | - if (isset($this->contextual[end($this->buildStack)][$abstract])) { |
|
702 | - return $this->contextual[end($this->buildStack)][$abstract]; |
|
701 | + if ( isset( $this->contextual[ end( $this->buildStack ) ][ $abstract ] ) ) { |
|
702 | + return $this->contextual[ end( $this->buildStack ) ][ $abstract ]; |
|
703 | 703 | } |
704 | 704 | } |
705 | 705 | |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | * @param string $abstract |
711 | 711 | * @return bool |
712 | 712 | */ |
713 | - protected function isBuildable($concrete, $abstract) |
|
713 | + protected function isBuildable( $concrete, $abstract ) |
|
714 | 714 | { |
715 | 715 | return $concrete === $abstract || $concrete instanceof Closure; |
716 | 716 | } |
@@ -723,33 +723,33 @@ discard block |
||
723 | 723 | * |
724 | 724 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
725 | 725 | */ |
726 | - public function build($concrete) |
|
726 | + public function build( $concrete ) |
|
727 | 727 | { |
728 | 728 | // If the concrete type is actually a Closure, we will just execute it and |
729 | 729 | // hand back the results of the functions, which allows functions to be |
730 | 730 | // used as resolvers for more fine-tuned resolution of these objects. |
731 | - if ($concrete instanceof Closure) { |
|
732 | - return $concrete($this, $this->getLastParameterOverride()); |
|
731 | + if ( $concrete instanceof Closure ) { |
|
732 | + return $concrete( $this, $this->getLastParameterOverride() ); |
|
733 | 733 | } |
734 | 734 | |
735 | - $reflector = new ReflectionClass($concrete); |
|
735 | + $reflector = new ReflectionClass( $concrete ); |
|
736 | 736 | |
737 | 737 | // If the type is not instantiable, the developer is attempting to resolve |
738 | 738 | // an abstract type such as an Interface of Abstract Class and there is |
739 | 739 | // no binding registered for the abstractions so we need to bail out. |
740 | - if (! $reflector->isInstantiable()) { |
|
741 | - return $this->notInstantiable($concrete); |
|
740 | + if ( ! $reflector->isInstantiable() ) { |
|
741 | + return $this->notInstantiable( $concrete ); |
|
742 | 742 | } |
743 | 743 | |
744 | - $this->buildStack[] = $concrete; |
|
744 | + $this->buildStack[ ] = $concrete; |
|
745 | 745 | |
746 | 746 | $constructor = $reflector->getConstructor(); |
747 | 747 | |
748 | 748 | // If there are no constructors, that means there are no dependencies then |
749 | 749 | // we can just resolve the instances of the objects right away, without |
750 | 750 | // resolving any other types or dependencies out of these containers. |
751 | - if (is_null($constructor)) { |
|
752 | - array_pop($this->buildStack); |
|
751 | + if ( is_null( $constructor ) ) { |
|
752 | + array_pop( $this->buildStack ); |
|
753 | 753 | |
754 | 754 | return new $concrete; |
755 | 755 | } |
@@ -763,9 +763,9 @@ discard block |
||
763 | 763 | $dependencies |
764 | 764 | ); |
765 | 765 | |
766 | - array_pop($this->buildStack); |
|
766 | + array_pop( $this->buildStack ); |
|
767 | 767 | |
768 | - return $reflector->newInstanceArgs($instances); |
|
768 | + return $reflector->newInstanceArgs( $instances ); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | /** |
@@ -774,16 +774,16 @@ discard block |
||
774 | 774 | * @param array $dependencies |
775 | 775 | * @return array |
776 | 776 | */ |
777 | - protected function resolveDependencies(array $dependencies) |
|
777 | + protected function resolveDependencies( array $dependencies ) |
|
778 | 778 | { |
779 | - $results = []; |
|
779 | + $results = [ ]; |
|
780 | 780 | |
781 | - foreach ($dependencies as $dependency) { |
|
781 | + foreach ( $dependencies as $dependency ) { |
|
782 | 782 | // If this dependency has a override for this particular build we will use |
783 | 783 | // that instead as the value. Otherwise, we will continue with this run |
784 | 784 | // of resolutions and let reflection attempt to determine the result. |
785 | - if ($this->hasParameterOverride($dependency)) { |
|
786 | - $results[] = $this->getParameterOverride($dependency); |
|
785 | + if ( $this->hasParameterOverride( $dependency ) ) { |
|
786 | + $results[ ] = $this->getParameterOverride( $dependency ); |
|
787 | 787 | |
788 | 788 | continue; |
789 | 789 | } |
@@ -791,9 +791,9 @@ discard block |
||
791 | 791 | // If the class is null, it means the dependency is a string or some other |
792 | 792 | // primitive type which we can not resolve since it is not a class and |
793 | 793 | // we will just bomb out with an error since we have no-where to go. |
794 | - $results[] = is_null($class = $dependency->getClass()) |
|
795 | - ? $this->resolvePrimitive($dependency) |
|
796 | - : $this->resolveClass($dependency); |
|
794 | + $results[ ] = is_null( $class = $dependency->getClass() ) |
|
795 | + ? $this->resolvePrimitive( $dependency ) |
|
796 | + : $this->resolveClass( $dependency ); |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | return $results; |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | * @param \ReflectionParameter $dependency |
806 | 806 | * @return bool |
807 | 807 | */ |
808 | - protected function hasParameterOverride($dependency) |
|
808 | + protected function hasParameterOverride( $dependency ) |
|
809 | 809 | { |
810 | 810 | return array_key_exists( |
811 | 811 | $dependency->name, $this->getLastParameterOverride() |
@@ -818,9 +818,9 @@ discard block |
||
818 | 818 | * @param \ReflectionParameter $dependency |
819 | 819 | * @return mixed |
820 | 820 | */ |
821 | - protected function getParameterOverride($dependency) |
|
821 | + protected function getParameterOverride( $dependency ) |
|
822 | 822 | { |
823 | - return $this->getLastParameterOverride()[$dependency->name]; |
|
823 | + return $this->getLastParameterOverride()[ $dependency->name ]; |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | */ |
831 | 831 | protected function getLastParameterOverride() |
832 | 832 | { |
833 | - return count($this->with) ? end($this->with) : []; |
|
833 | + return count( $this->with ) ? end( $this->with ) : [ ]; |
|
834 | 834 | } |
835 | 835 | |
836 | 836 | /** |
@@ -841,17 +841,17 @@ discard block |
||
841 | 841 | * |
842 | 842 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
843 | 843 | */ |
844 | - protected function resolvePrimitive(ReflectionParameter $parameter) |
|
844 | + protected function resolvePrimitive( ReflectionParameter $parameter ) |
|
845 | 845 | { |
846 | - if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->name))) { |
|
847 | - return $concrete instanceof Closure ? $concrete($this) : $concrete; |
|
846 | + if ( ! is_null( $concrete = $this->getContextualConcrete( '$' . $parameter->name ) ) ) { |
|
847 | + return $concrete instanceof Closure ? $concrete( $this ) : $concrete; |
|
848 | 848 | } |
849 | 849 | |
850 | - if ($parameter->isDefaultValueAvailable()) { |
|
850 | + if ( $parameter->isDefaultValueAvailable() ) { |
|
851 | 851 | return $parameter->getDefaultValue(); |
852 | 852 | } |
853 | 853 | |
854 | - $this->unresolvablePrimitive($parameter); |
|
854 | + $this->unresolvablePrimitive( $parameter ); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | /** |
@@ -862,17 +862,17 @@ discard block |
||
862 | 862 | * |
863 | 863 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
864 | 864 | */ |
865 | - protected function resolveClass(ReflectionParameter $parameter) |
|
865 | + protected function resolveClass( ReflectionParameter $parameter ) |
|
866 | 866 | { |
867 | 867 | try { |
868 | - return $this->make($parameter->getClass()->name); |
|
868 | + return $this->make( $parameter->getClass()->name ); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | // If we can not resolve the class instance, we will check to see if the value |
872 | 872 | // is optional, and if it is we will return the optional parameter value as |
873 | 873 | // the value of the dependency, similarly to how we do this with scalars. |
874 | - catch (BindingResolutionException $e) { |
|
875 | - if ($parameter->isOptional()) { |
|
874 | + catch ( BindingResolutionException $e ) { |
|
875 | + if ( $parameter->isOptional() ) { |
|
876 | 876 | return $parameter->getDefaultValue(); |
877 | 877 | } |
878 | 878 | |
@@ -888,17 +888,17 @@ discard block |
||
888 | 888 | * |
889 | 889 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
890 | 890 | */ |
891 | - protected function notInstantiable($concrete) |
|
891 | + protected function notInstantiable( $concrete ) |
|
892 | 892 | { |
893 | - if (! empty($this->buildStack)) { |
|
894 | - $previous = implode(', ', $this->buildStack); |
|
893 | + if ( ! empty( $this->buildStack ) ) { |
|
894 | + $previous = implode( ', ', $this->buildStack ); |
|
895 | 895 | |
896 | 896 | $message = "Target [$concrete] is not instantiable while building [$previous]."; |
897 | 897 | } else { |
898 | 898 | $message = "Target [$concrete] is not instantiable."; |
899 | 899 | } |
900 | 900 | |
901 | - throw new BindingResolutionException($message); |
|
901 | + throw new BindingResolutionException( $message ); |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | /** |
@@ -909,11 +909,11 @@ discard block |
||
909 | 909 | * |
910 | 910 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
911 | 911 | */ |
912 | - protected function unresolvablePrimitive(ReflectionParameter $parameter) |
|
912 | + protected function unresolvablePrimitive( ReflectionParameter $parameter ) |
|
913 | 913 | { |
914 | 914 | $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}"; |
915 | 915 | |
916 | - throw new BindingResolutionException($message); |
|
916 | + throw new BindingResolutionException( $message ); |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | /** |
@@ -923,16 +923,16 @@ discard block |
||
923 | 923 | * @param \Closure|null $callback |
924 | 924 | * @return void |
925 | 925 | */ |
926 | - public function resolving($abstract, Closure $callback = null) |
|
926 | + public function resolving( $abstract, Closure $callback = null ) |
|
927 | 927 | { |
928 | - if (is_string($abstract)) { |
|
929 | - $abstract = $this->getAlias($abstract); |
|
928 | + if ( is_string( $abstract ) ) { |
|
929 | + $abstract = $this->getAlias( $abstract ); |
|
930 | 930 | } |
931 | 931 | |
932 | - if (is_null($callback) && $abstract instanceof Closure) { |
|
933 | - $this->globalResolvingCallbacks[] = $abstract; |
|
932 | + if ( is_null( $callback ) && $abstract instanceof Closure ) { |
|
933 | + $this->globalResolvingCallbacks[ ] = $abstract; |
|
934 | 934 | } else { |
935 | - $this->resolvingCallbacks[$abstract][] = $callback; |
|
935 | + $this->resolvingCallbacks[ $abstract ][ ] = $callback; |
|
936 | 936 | } |
937 | 937 | } |
938 | 938 | |
@@ -943,16 +943,16 @@ discard block |
||
943 | 943 | * @param \Closure|null $callback |
944 | 944 | * @return void |
945 | 945 | */ |
946 | - public function afterResolving($abstract, Closure $callback = null) |
|
946 | + public function afterResolving( $abstract, Closure $callback = null ) |
|
947 | 947 | { |
948 | - if (is_string($abstract)) { |
|
949 | - $abstract = $this->getAlias($abstract); |
|
948 | + if ( is_string( $abstract ) ) { |
|
949 | + $abstract = $this->getAlias( $abstract ); |
|
950 | 950 | } |
951 | 951 | |
952 | - if ($abstract instanceof Closure && is_null($callback)) { |
|
953 | - $this->globalAfterResolvingCallbacks[] = $abstract; |
|
952 | + if ( $abstract instanceof Closure && is_null( $callback ) ) { |
|
953 | + $this->globalAfterResolvingCallbacks[ ] = $abstract; |
|
954 | 954 | } else { |
955 | - $this->afterResolvingCallbacks[$abstract][] = $callback; |
|
955 | + $this->afterResolvingCallbacks[ $abstract ][ ] = $callback; |
|
956 | 956 | } |
957 | 957 | } |
958 | 958 | |
@@ -963,15 +963,15 @@ discard block |
||
963 | 963 | * @param mixed $object |
964 | 964 | * @return void |
965 | 965 | */ |
966 | - protected function fireResolvingCallbacks($abstract, $object) |
|
966 | + protected function fireResolvingCallbacks( $abstract, $object ) |
|
967 | 967 | { |
968 | - $this->fireCallbackArray($object, $this->globalResolvingCallbacks); |
|
968 | + $this->fireCallbackArray( $object, $this->globalResolvingCallbacks ); |
|
969 | 969 | |
970 | 970 | $this->fireCallbackArray( |
971 | - $object, $this->getCallbacksForType($abstract, $object, $this->resolvingCallbacks) |
|
971 | + $object, $this->getCallbacksForType( $abstract, $object, $this->resolvingCallbacks ) |
|
972 | 972 | ); |
973 | 973 | |
974 | - $this->fireAfterResolvingCallbacks($abstract, $object); |
|
974 | + $this->fireAfterResolvingCallbacks( $abstract, $object ); |
|
975 | 975 | } |
976 | 976 | |
977 | 977 | /** |
@@ -981,12 +981,12 @@ discard block |
||
981 | 981 | * @param mixed $object |
982 | 982 | * @return void |
983 | 983 | */ |
984 | - protected function fireAfterResolvingCallbacks($abstract, $object) |
|
984 | + protected function fireAfterResolvingCallbacks( $abstract, $object ) |
|
985 | 985 | { |
986 | - $this->fireCallbackArray($object, $this->globalAfterResolvingCallbacks); |
|
986 | + $this->fireCallbackArray( $object, $this->globalAfterResolvingCallbacks ); |
|
987 | 987 | |
988 | 988 | $this->fireCallbackArray( |
989 | - $object, $this->getCallbacksForType($abstract, $object, $this->afterResolvingCallbacks) |
|
989 | + $object, $this->getCallbacksForType( $abstract, $object, $this->afterResolvingCallbacks ) |
|
990 | 990 | ); |
991 | 991 | } |
992 | 992 | |
@@ -999,13 +999,13 @@ discard block |
||
999 | 999 | * |
1000 | 1000 | * @return array |
1001 | 1001 | */ |
1002 | - protected function getCallbacksForType($abstract, $object, array $callbacksPerType) |
|
1002 | + protected function getCallbacksForType( $abstract, $object, array $callbacksPerType ) |
|
1003 | 1003 | { |
1004 | - $results = []; |
|
1004 | + $results = [ ]; |
|
1005 | 1005 | |
1006 | - foreach ($callbacksPerType as $type => $callbacks) { |
|
1007 | - if ($type === $abstract || $object instanceof $type) { |
|
1008 | - $results = array_merge($results, $callbacks); |
|
1006 | + foreach ( $callbacksPerType as $type => $callbacks ) { |
|
1007 | + if ( $type === $abstract || $object instanceof $type ) { |
|
1008 | + $results = array_merge( $results, $callbacks ); |
|
1009 | 1009 | } |
1010 | 1010 | } |
1011 | 1011 | |
@@ -1019,10 +1019,10 @@ discard block |
||
1019 | 1019 | * @param array $callbacks |
1020 | 1020 | * @return void |
1021 | 1021 | */ |
1022 | - protected function fireCallbackArray($object, array $callbacks) |
|
1022 | + protected function fireCallbackArray( $object, array $callbacks ) |
|
1023 | 1023 | { |
1024 | - foreach ($callbacks as $callback) { |
|
1025 | - $callback($object, $this); |
|
1024 | + foreach ( $callbacks as $callback ) { |
|
1025 | + $callback( $object, $this ); |
|
1026 | 1026 | } |
1027 | 1027 | } |
1028 | 1028 | |
@@ -1044,17 +1044,17 @@ discard block |
||
1044 | 1044 | * |
1045 | 1045 | * @throws \LogicException |
1046 | 1046 | */ |
1047 | - public function getAlias($abstract) |
|
1047 | + public function getAlias( $abstract ) |
|
1048 | 1048 | { |
1049 | - if (! isset($this->aliases[$abstract])) { |
|
1049 | + if ( ! isset( $this->aliases[ $abstract ] ) ) { |
|
1050 | 1050 | return $abstract; |
1051 | 1051 | } |
1052 | 1052 | |
1053 | - if ($this->aliases[$abstract] === $abstract) { |
|
1054 | - throw new LogicException("[{$abstract}] is aliased to itself."); |
|
1053 | + if ( $this->aliases[ $abstract ] === $abstract ) { |
|
1054 | + throw new LogicException( "[{$abstract}] is aliased to itself." ); |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | - return $this->getAlias($this->aliases[$abstract]); |
|
1057 | + return $this->getAlias( $this->aliases[ $abstract ] ); |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | /** |
@@ -1063,15 +1063,15 @@ discard block |
||
1063 | 1063 | * @param string $abstract |
1064 | 1064 | * @return array |
1065 | 1065 | */ |
1066 | - protected function getExtenders($abstract) |
|
1066 | + protected function getExtenders( $abstract ) |
|
1067 | 1067 | { |
1068 | - $abstract = $this->getAlias($abstract); |
|
1068 | + $abstract = $this->getAlias( $abstract ); |
|
1069 | 1069 | |
1070 | - if (isset($this->extenders[$abstract])) { |
|
1071 | - return $this->extenders[$abstract]; |
|
1070 | + if ( isset( $this->extenders[ $abstract ] ) ) { |
|
1071 | + return $this->extenders[ $abstract ]; |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | - return []; |
|
1074 | + return [ ]; |
|
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | /** |
@@ -1080,9 +1080,9 @@ discard block |
||
1080 | 1080 | * @param string $abstract |
1081 | 1081 | * @return void |
1082 | 1082 | */ |
1083 | - public function forgetExtenders($abstract) |
|
1083 | + public function forgetExtenders( $abstract ) |
|
1084 | 1084 | { |
1085 | - unset($this->extenders[$this->getAlias($abstract)]); |
|
1085 | + unset( $this->extenders[ $this->getAlias( $abstract ) ] ); |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | /** |
@@ -1091,9 +1091,9 @@ discard block |
||
1091 | 1091 | * @param string $abstract |
1092 | 1092 | * @return void |
1093 | 1093 | */ |
1094 | - protected function dropStaleInstances($abstract) |
|
1094 | + protected function dropStaleInstances( $abstract ) |
|
1095 | 1095 | { |
1096 | - unset($this->instances[$abstract], $this->aliases[$abstract]); |
|
1096 | + unset( $this->instances[ $abstract ], $this->aliases[ $abstract ] ); |
|
1097 | 1097 | } |
1098 | 1098 | |
1099 | 1099 | /** |
@@ -1102,9 +1102,9 @@ discard block |
||
1102 | 1102 | * @param string $abstract |
1103 | 1103 | * @return void |
1104 | 1104 | */ |
1105 | - public function forgetInstance($abstract) |
|
1105 | + public function forgetInstance( $abstract ) |
|
1106 | 1106 | { |
1107 | - unset($this->instances[$abstract]); |
|
1107 | + unset( $this->instances[ $abstract ] ); |
|
1108 | 1108 | } |
1109 | 1109 | |
1110 | 1110 | /** |
@@ -1114,7 +1114,7 @@ discard block |
||
1114 | 1114 | */ |
1115 | 1115 | public function forgetInstances() |
1116 | 1116 | { |
1117 | - $this->instances = []; |
|
1117 | + $this->instances = [ ]; |
|
1118 | 1118 | } |
1119 | 1119 | |
1120 | 1120 | /** |
@@ -1124,11 +1124,11 @@ discard block |
||
1124 | 1124 | */ |
1125 | 1125 | public function flush() |
1126 | 1126 | { |
1127 | - $this->aliases = []; |
|
1128 | - $this->resolved = []; |
|
1129 | - $this->bindings = []; |
|
1130 | - $this->instances = []; |
|
1131 | - $this->abstractAliases = []; |
|
1127 | + $this->aliases = [ ]; |
|
1128 | + $this->resolved = [ ]; |
|
1129 | + $this->bindings = [ ]; |
|
1130 | + $this->instances = [ ]; |
|
1131 | + $this->abstractAliases = [ ]; |
|
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | /** |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | */ |
1139 | 1139 | public static function getInstance() |
1140 | 1140 | { |
1141 | - if (is_null(static::$instance)) { |
|
1141 | + if ( is_null( static::$instance ) ) { |
|
1142 | 1142 | static::$instance = new static; |
1143 | 1143 | } |
1144 | 1144 | |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\Container|null $container |
1152 | 1152 | * @return static |
1153 | 1153 | */ |
1154 | - public static function setInstance(ContainerContract $container = null) |
|
1154 | + public static function setInstance( ContainerContract $container = null ) |
|
1155 | 1155 | { |
1156 | 1156 | return static::$instance = $container; |
1157 | 1157 | } |
@@ -1162,9 +1162,9 @@ discard block |
||
1162 | 1162 | * @param string $key |
1163 | 1163 | * @return bool |
1164 | 1164 | */ |
1165 | - public function offsetExists($key) |
|
1165 | + public function offsetExists( $key ) |
|
1166 | 1166 | { |
1167 | - return $this->bound($key); |
|
1167 | + return $this->bound( $key ); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
@@ -1173,9 +1173,9 @@ discard block |
||
1173 | 1173 | * @param string $key |
1174 | 1174 | * @return mixed |
1175 | 1175 | */ |
1176 | - public function offsetGet($key) |
|
1176 | + public function offsetGet( $key ) |
|
1177 | 1177 | { |
1178 | - return $this->make($key); |
|
1178 | + return $this->make( $key ); |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | /** |
@@ -1185,9 +1185,9 @@ discard block |
||
1185 | 1185 | * @param mixed $value |
1186 | 1186 | * @return void |
1187 | 1187 | */ |
1188 | - public function offsetSet($key, $value) |
|
1188 | + public function offsetSet( $key, $value ) |
|
1189 | 1189 | { |
1190 | - $this->bind($key, $value instanceof Closure ? $value : function () use ($value) { |
|
1190 | + $this->bind( $key, $value instanceof Closure ? $value : function() use ( $value ) { |
|
1191 | 1191 | return $value; |
1192 | 1192 | }); |
1193 | 1193 | } |
@@ -1198,9 +1198,9 @@ discard block |
||
1198 | 1198 | * @param string $key |
1199 | 1199 | * @return void |
1200 | 1200 | */ |
1201 | - public function offsetUnset($key) |
|
1201 | + public function offsetUnset( $key ) |
|
1202 | 1202 | { |
1203 | - unset($this->bindings[$key], $this->instances[$key], $this->resolved[$key]); |
|
1203 | + unset( $this->bindings[ $key ], $this->instances[ $key ], $this->resolved[ $key ] ); |
|
1204 | 1204 | } |
1205 | 1205 | |
1206 | 1206 | /** |
@@ -1209,9 +1209,9 @@ discard block |
||
1209 | 1209 | * @param string $key |
1210 | 1210 | * @return mixed |
1211 | 1211 | */ |
1212 | - public function __get($key) |
|
1212 | + public function __get( $key ) |
|
1213 | 1213 | { |
1214 | - return $this[$key]; |
|
1214 | + return $this[ $key ]; |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | /** |
@@ -1221,8 +1221,8 @@ discard block |
||
1221 | 1221 | * @param mixed $value |
1222 | 1222 | * @return void |
1223 | 1223 | */ |
1224 | - public function __set($key, $value) |
|
1224 | + public function __set( $key, $value ) |
|
1225 | 1225 | { |
1226 | - $this[$key] = $value; |
|
1226 | + $this[ $key ] = $value; |
|
1227 | 1227 | } |
1228 | 1228 | } |
@@ -143,8 +143,7 @@ discard block |
||
143 | 143 | * @param string $concrete |
144 | 144 | * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\ContextualBindingBuilder |
145 | 145 | */ |
146 | - public function when($concrete) |
|
147 | - { |
|
146 | + public function when($concrete) { |
|
148 | 147 | return new ContextualBindingBuilder($this, $this->getAlias($concrete)); |
149 | 148 | } |
150 | 149 | |
@@ -154,8 +153,7 @@ discard block |
||
154 | 153 | * @param string $abstract |
155 | 154 | * @return bool |
156 | 155 | */ |
157 | - public function bound($abstract) |
|
158 | - { |
|
156 | + public function bound($abstract) { |
|
159 | 157 | return isset($this->bindings[$abstract]) || |
160 | 158 | isset($this->instances[$abstract]) || |
161 | 159 | $this->isAlias($abstract); |
@@ -167,8 +165,7 @@ discard block |
||
167 | 165 | * @param string $abstract |
168 | 166 | * @return bool |
169 | 167 | */ |
170 | - public function resolved($abstract) |
|
171 | - { |
|
168 | + public function resolved($abstract) { |
|
172 | 169 | if ($this->isAlias($abstract)) { |
173 | 170 | $abstract = $this->getAlias($abstract); |
174 | 171 | } |
@@ -183,8 +180,7 @@ discard block |
||
183 | 180 | * @param string $abstract |
184 | 181 | * @return bool |
185 | 182 | */ |
186 | - public function isShared($abstract) |
|
187 | - { |
|
183 | + public function isShared($abstract) { |
|
188 | 184 | return isset($this->instances[$abstract]) || |
189 | 185 | (isset($this->bindings[$abstract]['shared']) && |
190 | 186 | $this->bindings[$abstract]['shared'] === true); |
@@ -196,8 +192,7 @@ discard block |
||
196 | 192 | * @param string $name |
197 | 193 | * @return bool |
198 | 194 | */ |
199 | - public function isAlias($name) |
|
200 | - { |
|
195 | + public function isAlias($name) { |
|
201 | 196 | return isset($this->aliases[$name]); |
202 | 197 | } |
203 | 198 | |
@@ -209,8 +204,7 @@ discard block |
||
209 | 204 | * @param bool $shared |
210 | 205 | * @return void |
211 | 206 | */ |
212 | - public function bind($abstract, $concrete = null, $shared = false) |
|
213 | - { |
|
207 | + public function bind($abstract, $concrete = null, $shared = false) { |
|
214 | 208 | // If no concrete type was given, we will simply set the concrete type to the |
215 | 209 | // abstract type. After that, the concrete type to be registered as shared |
216 | 210 | // without being forced to state their classes in both of the parameters. |
@@ -244,8 +238,7 @@ discard block |
||
244 | 238 | * @param string $concrete |
245 | 239 | * @return \Closure |
246 | 240 | */ |
247 | - protected function getClosure($abstract, $concrete) |
|
248 | - { |
|
241 | + protected function getClosure($abstract, $concrete) { |
|
249 | 242 | return function ($container, $parameters = []) use ($abstract, $concrete) { |
250 | 243 | if ($abstract == $concrete) { |
251 | 244 | return $container->build($concrete); |
@@ -261,8 +254,7 @@ discard block |
||
261 | 254 | * @param string $method |
262 | 255 | * @return bool |
263 | 256 | */ |
264 | - public function hasMethodBinding($method) |
|
265 | - { |
|
257 | + public function hasMethodBinding($method) { |
|
266 | 258 | return isset($this->methodBindings[$method]); |
267 | 259 | } |
268 | 260 | |
@@ -273,8 +265,7 @@ discard block |
||
273 | 265 | * @param \Closure $callback |
274 | 266 | * @return void |
275 | 267 | */ |
276 | - public function bindMethod($method, $callback) |
|
277 | - { |
|
268 | + public function bindMethod($method, $callback) { |
|
278 | 269 | $this->methodBindings[$method] = $callback; |
279 | 270 | } |
280 | 271 | |
@@ -285,8 +276,7 @@ discard block |
||
285 | 276 | * @param mixed $instance |
286 | 277 | * @return mixed |
287 | 278 | */ |
288 | - public function callMethodBinding($method, $instance) |
|
289 | - { |
|
279 | + public function callMethodBinding($method, $instance) { |
|
290 | 280 | return call_user_func($this->methodBindings[$method], $instance, $this); |
291 | 281 | } |
292 | 282 | |
@@ -298,8 +288,7 @@ discard block |
||
298 | 288 | * @param \Closure|string $implementation |
299 | 289 | * @return void |
300 | 290 | */ |
301 | - public function addContextualBinding($concrete, $abstract, $implementation) |
|
302 | - { |
|
291 | + public function addContextualBinding($concrete, $abstract, $implementation) { |
|
303 | 292 | $this->contextual[$concrete][$this->getAlias($abstract)] = $implementation; |
304 | 293 | } |
305 | 294 | |
@@ -311,8 +300,7 @@ discard block |
||
311 | 300 | * @param bool $shared |
312 | 301 | * @return void |
313 | 302 | */ |
314 | - public function bindIf($abstract, $concrete = null, $shared = false) |
|
315 | - { |
|
303 | + public function bindIf($abstract, $concrete = null, $shared = false) { |
|
316 | 304 | if (! $this->bound($abstract)) { |
317 | 305 | $this->bind($abstract, $concrete, $shared); |
318 | 306 | } |
@@ -325,8 +313,7 @@ discard block |
||
325 | 313 | * @param \Closure|string|null $concrete |
326 | 314 | * @return void |
327 | 315 | */ |
328 | - public function singleton($abstract, $concrete = null) |
|
329 | - { |
|
316 | + public function singleton($abstract, $concrete = null) { |
|
330 | 317 | $this->bind($abstract, $concrete, true); |
331 | 318 | } |
332 | 319 | |
@@ -339,8 +326,7 @@ discard block |
||
339 | 326 | * |
340 | 327 | * @throws \InvalidArgumentException |
341 | 328 | */ |
342 | - public function extend($abstract, Closure $closure) |
|
343 | - { |
|
329 | + public function extend($abstract, Closure $closure) { |
|
344 | 330 | $abstract = $this->getAlias($abstract); |
345 | 331 | |
346 | 332 | if (isset($this->instances[$abstract])) { |
@@ -363,8 +349,7 @@ discard block |
||
363 | 349 | * @param mixed $instance |
364 | 350 | * @return void |
365 | 351 | */ |
366 | - public function instance($abstract, $instance) |
|
367 | - { |
|
352 | + public function instance($abstract, $instance) { |
|
368 | 353 | $this->removeAbstractAlias($abstract); |
369 | 354 | |
370 | 355 | $isBound = $this->bound($abstract); |
@@ -387,8 +372,7 @@ discard block |
||
387 | 372 | * @param string $searched |
388 | 373 | * @return void |
389 | 374 | */ |
390 | - protected function removeAbstractAlias($searched) |
|
391 | - { |
|
375 | + protected function removeAbstractAlias($searched) { |
|
392 | 376 | if (! isset($this->aliases[$searched])) { |
393 | 377 | return; |
394 | 378 | } |
@@ -409,8 +393,7 @@ discard block |
||
409 | 393 | * @param array|mixed ...$tags |
410 | 394 | * @return void |
411 | 395 | */ |
412 | - public function tag($abstracts, $tags) |
|
413 | - { |
|
396 | + public function tag($abstracts, $tags) { |
|
414 | 397 | $tags = is_array($tags) ? $tags : array_slice(func_get_args(), 1); |
415 | 398 | |
416 | 399 | foreach ($tags as $tag) { |
@@ -430,8 +413,7 @@ discard block |
||
430 | 413 | * @param string $tag |
431 | 414 | * @return array |
432 | 415 | */ |
433 | - public function tagged($tag) |
|
434 | - { |
|
416 | + public function tagged($tag) { |
|
435 | 417 | $results = []; |
436 | 418 | |
437 | 419 | if (isset($this->tags[$tag])) { |
@@ -450,8 +432,7 @@ discard block |
||
450 | 432 | * @param string $alias |
451 | 433 | * @return void |
452 | 434 | */ |
453 | - public function alias($abstract, $alias) |
|
454 | - { |
|
435 | + public function alias($abstract, $alias) { |
|
455 | 436 | $this->aliases[$alias] = $abstract; |
456 | 437 | |
457 | 438 | $this->abstractAliases[$abstract][] = $alias; |
@@ -464,8 +445,7 @@ discard block |
||
464 | 445 | * @param \Closure $callback |
465 | 446 | * @return mixed |
466 | 447 | */ |
467 | - public function rebinding($abstract, Closure $callback) |
|
468 | - { |
|
448 | + public function rebinding($abstract, Closure $callback) { |
|
469 | 449 | $this->reboundCallbacks[$abstract = $this->getAlias($abstract)][] = $callback; |
470 | 450 | |
471 | 451 | if ($this->bound($abstract)) { |
@@ -481,8 +461,7 @@ discard block |
||
481 | 461 | * @param string $method |
482 | 462 | * @return mixed |
483 | 463 | */ |
484 | - public function refresh($abstract, $target, $method) |
|
485 | - { |
|
464 | + public function refresh($abstract, $target, $method) { |
|
486 | 465 | return $this->rebinding($abstract, function ($app, $instance) use ($target, $method) { |
487 | 466 | $target->{$method}($instance); |
488 | 467 | }); |
@@ -494,8 +473,7 @@ discard block |
||
494 | 473 | * @param string $abstract |
495 | 474 | * @return void |
496 | 475 | */ |
497 | - protected function rebound($abstract) |
|
498 | - { |
|
476 | + protected function rebound($abstract) { |
|
499 | 477 | $instance = $this->make($abstract); |
500 | 478 | |
501 | 479 | foreach ($this->getReboundCallbacks($abstract) as $callback) { |
@@ -509,8 +487,7 @@ discard block |
||
509 | 487 | * @param string $abstract |
510 | 488 | * @return array |
511 | 489 | */ |
512 | - protected function getReboundCallbacks($abstract) |
|
513 | - { |
|
490 | + protected function getReboundCallbacks($abstract) { |
|
514 | 491 | if (isset($this->reboundCallbacks[$abstract])) { |
515 | 492 | return $this->reboundCallbacks[$abstract]; |
516 | 493 | } |
@@ -525,8 +502,7 @@ discard block |
||
525 | 502 | * @param array $parameters |
526 | 503 | * @return \Closure |
527 | 504 | */ |
528 | - public function wrap(Closure $callback, array $parameters = []) |
|
529 | - { |
|
505 | + public function wrap(Closure $callback, array $parameters = []) { |
|
530 | 506 | return function () use ($callback, $parameters) { |
531 | 507 | return $this->call($callback, $parameters); |
532 | 508 | }; |
@@ -540,8 +516,7 @@ discard block |
||
540 | 516 | * @param string|null $defaultMethod |
541 | 517 | * @return mixed |
542 | 518 | */ |
543 | - public function call($callback, array $parameters = [], $defaultMethod = null) |
|
544 | - { |
|
519 | + public function call($callback, array $parameters = [], $defaultMethod = null) { |
|
545 | 520 | return BoundMethod::call($this, $callback, $parameters, $defaultMethod); |
546 | 521 | } |
547 | 522 | |
@@ -551,8 +526,7 @@ discard block |
||
551 | 526 | * @param string $abstract |
552 | 527 | * @return \Closure |
553 | 528 | */ |
554 | - public function factory($abstract) |
|
555 | - { |
|
529 | + public function factory($abstract) { |
|
556 | 530 | return function () use ($abstract) { |
557 | 531 | return $this->make($abstract); |
558 | 532 | }; |
@@ -565,8 +539,7 @@ discard block |
||
565 | 539 | * @param array $parameters |
566 | 540 | * @return mixed |
567 | 541 | */ |
568 | - public function makeWith($abstract, array $parameters) |
|
569 | - { |
|
542 | + public function makeWith($abstract, array $parameters) { |
|
570 | 543 | return $this->resolve($abstract, $parameters); |
571 | 544 | } |
572 | 545 | |
@@ -576,8 +549,7 @@ discard block |
||
576 | 549 | * @param string $abstract |
577 | 550 | * @return mixed |
578 | 551 | */ |
579 | - public function make($abstract) |
|
580 | - { |
|
552 | + public function make($abstract) { |
|
581 | 553 | return $this->resolve($abstract); |
582 | 554 | } |
583 | 555 | |
@@ -588,8 +560,7 @@ discard block |
||
588 | 560 | * @param array $parameters |
589 | 561 | * @return mixed |
590 | 562 | */ |
591 | - protected function resolve($abstract, $parameters = []) |
|
592 | - { |
|
563 | + protected function resolve($abstract, $parameters = []) { |
|
593 | 564 | $abstract = $this->getAlias($abstract); |
594 | 565 | |
595 | 566 | $needsContextualBuild = ! empty($parameters) || ! is_null( |
@@ -648,8 +619,7 @@ discard block |
||
648 | 619 | * @param string $abstract |
649 | 620 | * @return mixed $concrete |
650 | 621 | */ |
651 | - protected function getConcrete($abstract) |
|
652 | - { |
|
622 | + protected function getConcrete($abstract) { |
|
653 | 623 | if (! is_null($concrete = $this->getContextualConcrete($abstract))) { |
654 | 624 | return $concrete; |
655 | 625 | } |
@@ -670,8 +640,7 @@ discard block |
||
670 | 640 | * @param string $abstract |
671 | 641 | * @return string|null |
672 | 642 | */ |
673 | - protected function getContextualConcrete($abstract) |
|
674 | - { |
|
643 | + protected function getContextualConcrete($abstract) { |
|
675 | 644 | if (! is_null($binding = $this->findInContextualBindings($abstract))) { |
676 | 645 | return $binding; |
677 | 646 | } |
@@ -696,8 +665,7 @@ discard block |
||
696 | 665 | * @param string $abstract |
697 | 666 | * @return string|null |
698 | 667 | */ |
699 | - protected function findInContextualBindings($abstract) |
|
700 | - { |
|
668 | + protected function findInContextualBindings($abstract) { |
|
701 | 669 | if (isset($this->contextual[end($this->buildStack)][$abstract])) { |
702 | 670 | return $this->contextual[end($this->buildStack)][$abstract]; |
703 | 671 | } |
@@ -710,8 +678,7 @@ discard block |
||
710 | 678 | * @param string $abstract |
711 | 679 | * @return bool |
712 | 680 | */ |
713 | - protected function isBuildable($concrete, $abstract) |
|
714 | - { |
|
681 | + protected function isBuildable($concrete, $abstract) { |
|
715 | 682 | return $concrete === $abstract || $concrete instanceof Closure; |
716 | 683 | } |
717 | 684 | |
@@ -723,8 +690,7 @@ discard block |
||
723 | 690 | * |
724 | 691 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
725 | 692 | */ |
726 | - public function build($concrete) |
|
727 | - { |
|
693 | + public function build($concrete) { |
|
728 | 694 | // If the concrete type is actually a Closure, we will just execute it and |
729 | 695 | // hand back the results of the functions, which allows functions to be |
730 | 696 | // used as resolvers for more fine-tuned resolution of these objects. |
@@ -774,8 +740,7 @@ discard block |
||
774 | 740 | * @param array $dependencies |
775 | 741 | * @return array |
776 | 742 | */ |
777 | - protected function resolveDependencies(array $dependencies) |
|
778 | - { |
|
743 | + protected function resolveDependencies(array $dependencies) { |
|
779 | 744 | $results = []; |
780 | 745 | |
781 | 746 | foreach ($dependencies as $dependency) { |
@@ -805,8 +770,7 @@ discard block |
||
805 | 770 | * @param \ReflectionParameter $dependency |
806 | 771 | * @return bool |
807 | 772 | */ |
808 | - protected function hasParameterOverride($dependency) |
|
809 | - { |
|
773 | + protected function hasParameterOverride($dependency) { |
|
810 | 774 | return array_key_exists( |
811 | 775 | $dependency->name, $this->getLastParameterOverride() |
812 | 776 | ); |
@@ -818,8 +782,7 @@ discard block |
||
818 | 782 | * @param \ReflectionParameter $dependency |
819 | 783 | * @return mixed |
820 | 784 | */ |
821 | - protected function getParameterOverride($dependency) |
|
822 | - { |
|
785 | + protected function getParameterOverride($dependency) { |
|
823 | 786 | return $this->getLastParameterOverride()[$dependency->name]; |
824 | 787 | } |
825 | 788 | |
@@ -828,8 +791,7 @@ discard block |
||
828 | 791 | * |
829 | 792 | * @return array |
830 | 793 | */ |
831 | - protected function getLastParameterOverride() |
|
832 | - { |
|
794 | + protected function getLastParameterOverride() { |
|
833 | 795 | return count($this->with) ? end($this->with) : []; |
834 | 796 | } |
835 | 797 | |
@@ -841,8 +803,7 @@ discard block |
||
841 | 803 | * |
842 | 804 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
843 | 805 | */ |
844 | - protected function resolvePrimitive(ReflectionParameter $parameter) |
|
845 | - { |
|
806 | + protected function resolvePrimitive(ReflectionParameter $parameter) { |
|
846 | 807 | if (! is_null($concrete = $this->getContextualConcrete('$'.$parameter->name))) { |
847 | 808 | return $concrete instanceof Closure ? $concrete($this) : $concrete; |
848 | 809 | } |
@@ -862,8 +823,7 @@ discard block |
||
862 | 823 | * |
863 | 824 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
864 | 825 | */ |
865 | - protected function resolveClass(ReflectionParameter $parameter) |
|
866 | - { |
|
826 | + protected function resolveClass(ReflectionParameter $parameter) { |
|
867 | 827 | try { |
868 | 828 | return $this->make($parameter->getClass()->name); |
869 | 829 | } |
@@ -888,8 +848,7 @@ discard block |
||
888 | 848 | * |
889 | 849 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
890 | 850 | */ |
891 | - protected function notInstantiable($concrete) |
|
892 | - { |
|
851 | + protected function notInstantiable($concrete) { |
|
893 | 852 | if (! empty($this->buildStack)) { |
894 | 853 | $previous = implode(', ', $this->buildStack); |
895 | 854 | |
@@ -909,8 +868,7 @@ discard block |
||
909 | 868 | * |
910 | 869 | * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\BindingResolutionException |
911 | 870 | */ |
912 | - protected function unresolvablePrimitive(ReflectionParameter $parameter) |
|
913 | - { |
|
871 | + protected function unresolvablePrimitive(ReflectionParameter $parameter) { |
|
914 | 872 | $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}"; |
915 | 873 | |
916 | 874 | throw new BindingResolutionException($message); |
@@ -923,8 +881,7 @@ discard block |
||
923 | 881 | * @param \Closure|null $callback |
924 | 882 | * @return void |
925 | 883 | */ |
926 | - public function resolving($abstract, Closure $callback = null) |
|
927 | - { |
|
884 | + public function resolving($abstract, Closure $callback = null) { |
|
928 | 885 | if (is_string($abstract)) { |
929 | 886 | $abstract = $this->getAlias($abstract); |
930 | 887 | } |
@@ -943,8 +900,7 @@ discard block |
||
943 | 900 | * @param \Closure|null $callback |
944 | 901 | * @return void |
945 | 902 | */ |
946 | - public function afterResolving($abstract, Closure $callback = null) |
|
947 | - { |
|
903 | + public function afterResolving($abstract, Closure $callback = null) { |
|
948 | 904 | if (is_string($abstract)) { |
949 | 905 | $abstract = $this->getAlias($abstract); |
950 | 906 | } |
@@ -963,8 +919,7 @@ discard block |
||
963 | 919 | * @param mixed $object |
964 | 920 | * @return void |
965 | 921 | */ |
966 | - protected function fireResolvingCallbacks($abstract, $object) |
|
967 | - { |
|
922 | + protected function fireResolvingCallbacks($abstract, $object) { |
|
968 | 923 | $this->fireCallbackArray($object, $this->globalResolvingCallbacks); |
969 | 924 | |
970 | 925 | $this->fireCallbackArray( |
@@ -981,8 +936,7 @@ discard block |
||
981 | 936 | * @param mixed $object |
982 | 937 | * @return void |
983 | 938 | */ |
984 | - protected function fireAfterResolvingCallbacks($abstract, $object) |
|
985 | - { |
|
939 | + protected function fireAfterResolvingCallbacks($abstract, $object) { |
|
986 | 940 | $this->fireCallbackArray($object, $this->globalAfterResolvingCallbacks); |
987 | 941 | |
988 | 942 | $this->fireCallbackArray( |
@@ -999,8 +953,7 @@ discard block |
||
999 | 953 | * |
1000 | 954 | * @return array |
1001 | 955 | */ |
1002 | - protected function getCallbacksForType($abstract, $object, array $callbacksPerType) |
|
1003 | - { |
|
956 | + protected function getCallbacksForType($abstract, $object, array $callbacksPerType) { |
|
1004 | 957 | $results = []; |
1005 | 958 | |
1006 | 959 | foreach ($callbacksPerType as $type => $callbacks) { |
@@ -1019,8 +972,7 @@ discard block |
||
1019 | 972 | * @param array $callbacks |
1020 | 973 | * @return void |
1021 | 974 | */ |
1022 | - protected function fireCallbackArray($object, array $callbacks) |
|
1023 | - { |
|
975 | + protected function fireCallbackArray($object, array $callbacks) { |
|
1024 | 976 | foreach ($callbacks as $callback) { |
1025 | 977 | $callback($object, $this); |
1026 | 978 | } |
@@ -1031,8 +983,7 @@ discard block |
||
1031 | 983 | * |
1032 | 984 | * @return array |
1033 | 985 | */ |
1034 | - public function getBindings() |
|
1035 | - { |
|
986 | + public function getBindings() { |
|
1036 | 987 | return $this->bindings; |
1037 | 988 | } |
1038 | 989 | |
@@ -1044,8 +995,7 @@ discard block |
||
1044 | 995 | * |
1045 | 996 | * @throws \LogicException |
1046 | 997 | */ |
1047 | - public function getAlias($abstract) |
|
1048 | - { |
|
998 | + public function getAlias($abstract) { |
|
1049 | 999 | if (! isset($this->aliases[$abstract])) { |
1050 | 1000 | return $abstract; |
1051 | 1001 | } |
@@ -1063,8 +1013,7 @@ discard block |
||
1063 | 1013 | * @param string $abstract |
1064 | 1014 | * @return array |
1065 | 1015 | */ |
1066 | - protected function getExtenders($abstract) |
|
1067 | - { |
|
1016 | + protected function getExtenders($abstract) { |
|
1068 | 1017 | $abstract = $this->getAlias($abstract); |
1069 | 1018 | |
1070 | 1019 | if (isset($this->extenders[$abstract])) { |
@@ -1080,8 +1029,7 @@ discard block |
||
1080 | 1029 | * @param string $abstract |
1081 | 1030 | * @return void |
1082 | 1031 | */ |
1083 | - public function forgetExtenders($abstract) |
|
1084 | - { |
|
1032 | + public function forgetExtenders($abstract) { |
|
1085 | 1033 | unset($this->extenders[$this->getAlias($abstract)]); |
1086 | 1034 | } |
1087 | 1035 | |
@@ -1091,8 +1039,7 @@ discard block |
||
1091 | 1039 | * @param string $abstract |
1092 | 1040 | * @return void |
1093 | 1041 | */ |
1094 | - protected function dropStaleInstances($abstract) |
|
1095 | - { |
|
1042 | + protected function dropStaleInstances($abstract) { |
|
1096 | 1043 | unset($this->instances[$abstract], $this->aliases[$abstract]); |
1097 | 1044 | } |
1098 | 1045 | |
@@ -1102,8 +1049,7 @@ discard block |
||
1102 | 1049 | * @param string $abstract |
1103 | 1050 | * @return void |
1104 | 1051 | */ |
1105 | - public function forgetInstance($abstract) |
|
1106 | - { |
|
1052 | + public function forgetInstance($abstract) { |
|
1107 | 1053 | unset($this->instances[$abstract]); |
1108 | 1054 | } |
1109 | 1055 | |
@@ -1112,8 +1058,7 @@ discard block |
||
1112 | 1058 | * |
1113 | 1059 | * @return void |
1114 | 1060 | */ |
1115 | - public function forgetInstances() |
|
1116 | - { |
|
1061 | + public function forgetInstances() { |
|
1117 | 1062 | $this->instances = []; |
1118 | 1063 | } |
1119 | 1064 | |
@@ -1122,8 +1067,7 @@ discard block |
||
1122 | 1067 | * |
1123 | 1068 | * @return void |
1124 | 1069 | */ |
1125 | - public function flush() |
|
1126 | - { |
|
1070 | + public function flush() { |
|
1127 | 1071 | $this->aliases = []; |
1128 | 1072 | $this->resolved = []; |
1129 | 1073 | $this->bindings = []; |
@@ -1136,8 +1080,7 @@ discard block |
||
1136 | 1080 | * |
1137 | 1081 | * @return static |
1138 | 1082 | */ |
1139 | - public static function getInstance() |
|
1140 | - { |
|
1083 | + public static function getInstance() { |
|
1141 | 1084 | if (is_null(static::$instance)) { |
1142 | 1085 | static::$instance = new static; |
1143 | 1086 | } |
@@ -1151,8 +1094,7 @@ discard block |
||
1151 | 1094 | * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\Container|null $container |
1152 | 1095 | * @return static |
1153 | 1096 | */ |
1154 | - public static function setInstance(ContainerContract $container = null) |
|
1155 | - { |
|
1097 | + public static function setInstance(ContainerContract $container = null) { |
|
1156 | 1098 | return static::$instance = $container; |
1157 | 1099 | } |
1158 | 1100 | |
@@ -1162,8 +1104,7 @@ discard block |
||
1162 | 1104 | * @param string $key |
1163 | 1105 | * @return bool |
1164 | 1106 | */ |
1165 | - public function offsetExists($key) |
|
1166 | - { |
|
1107 | + public function offsetExists($key) { |
|
1167 | 1108 | return $this->bound($key); |
1168 | 1109 | } |
1169 | 1110 | |
@@ -1173,8 +1114,7 @@ discard block |
||
1173 | 1114 | * @param string $key |
1174 | 1115 | * @return mixed |
1175 | 1116 | */ |
1176 | - public function offsetGet($key) |
|
1177 | - { |
|
1117 | + public function offsetGet($key) { |
|
1178 | 1118 | return $this->make($key); |
1179 | 1119 | } |
1180 | 1120 | |
@@ -1185,8 +1125,7 @@ discard block |
||
1185 | 1125 | * @param mixed $value |
1186 | 1126 | * @return void |
1187 | 1127 | */ |
1188 | - public function offsetSet($key, $value) |
|
1189 | - { |
|
1128 | + public function offsetSet($key, $value) { |
|
1190 | 1129 | $this->bind($key, $value instanceof Closure ? $value : function () use ($value) { |
1191 | 1130 | return $value; |
1192 | 1131 | }); |
@@ -1198,8 +1137,7 @@ discard block |
||
1198 | 1137 | * @param string $key |
1199 | 1138 | * @return void |
1200 | 1139 | */ |
1201 | - public function offsetUnset($key) |
|
1202 | - { |
|
1140 | + public function offsetUnset($key) { |
|
1203 | 1141 | unset($this->bindings[$key], $this->instances[$key], $this->resolved[$key]); |
1204 | 1142 | } |
1205 | 1143 | |
@@ -1209,8 +1147,7 @@ discard block |
||
1209 | 1147 | * @param string $key |
1210 | 1148 | * @return mixed |
1211 | 1149 | */ |
1212 | - public function __get($key) |
|
1213 | - { |
|
1150 | + public function __get($key) { |
|
1214 | 1151 | return $this[$key]; |
1215 | 1152 | } |
1216 | 1153 | |
@@ -1221,8 +1158,7 @@ discard block |
||
1221 | 1158 | * @param mixed $value |
1222 | 1159 | * @return void |
1223 | 1160 | */ |
1224 | - public function __set($key, $value) |
|
1225 | - { |
|
1161 | + public function __set($key, $value) { |
|
1226 | 1162 | $this[$key] = $value; |
1227 | 1163 | } |
1228 | 1164 | } |
@@ -12,63 +12,63 @@ |
||
12 | 12 | |
13 | 13 | class ContextualBindingBuilder implements ContextualBindingBuilderContract |
14 | 14 | { |
15 | - /** |
|
16 | - * The underlying container instance. |
|
17 | - * |
|
18 | - * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container |
|
19 | - */ |
|
20 | - protected $container; |
|
15 | + /** |
|
16 | + * The underlying container instance. |
|
17 | + * |
|
18 | + * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container |
|
19 | + */ |
|
20 | + protected $container; |
|
21 | 21 | |
22 | - /** |
|
23 | - * The concrete instance. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $concrete; |
|
22 | + /** |
|
23 | + * The concrete instance. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $concrete; |
|
28 | 28 | |
29 | - /** |
|
30 | - * The abstract target. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - protected $needs; |
|
29 | + /** |
|
30 | + * The abstract target. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + protected $needs; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Create a new contextual binding builder. |
|
38 | - * |
|
39 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
40 | - * @param string $concrete |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function __construct(Container $container, $concrete) |
|
44 | - { |
|
45 | - $this->concrete = $concrete; |
|
46 | - $this->container = $container; |
|
47 | - } |
|
36 | + /** |
|
37 | + * Create a new contextual binding builder. |
|
38 | + * |
|
39 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
40 | + * @param string $concrete |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function __construct(Container $container, $concrete) |
|
44 | + { |
|
45 | + $this->concrete = $concrete; |
|
46 | + $this->container = $container; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Define the abstract target that depends on the context. |
|
51 | - * |
|
52 | - * @param string $abstract |
|
53 | - * @return $this |
|
54 | - */ |
|
55 | - public function needs($abstract) |
|
56 | - { |
|
57 | - $this->needs = $abstract; |
|
49 | + /** |
|
50 | + * Define the abstract target that depends on the context. |
|
51 | + * |
|
52 | + * @param string $abstract |
|
53 | + * @return $this |
|
54 | + */ |
|
55 | + public function needs($abstract) |
|
56 | + { |
|
57 | + $this->needs = $abstract; |
|
58 | 58 | |
59 | - return $this; |
|
60 | - } |
|
59 | + return $this; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Define the implementation for the contextual binding. |
|
64 | - * |
|
65 | - * @param \Closure|string $implementation |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public function give($implementation) |
|
69 | - { |
|
70 | - $this->container->addContextualBinding( |
|
71 | - $this->concrete, $this->needs, $implementation |
|
72 | - ); |
|
73 | - } |
|
62 | + /** |
|
63 | + * Define the implementation for the contextual binding. |
|
64 | + * |
|
65 | + * @param \Closure|string $implementation |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public function give($implementation) |
|
69 | + { |
|
70 | + $this->container->addContextualBinding( |
|
71 | + $this->concrete, $this->needs, $implementation |
|
72 | + ); |
|
73 | + } |
|
74 | 74 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @param string $concrete |
41 | 41 | * @return void |
42 | 42 | */ |
43 | - public function __construct(Container $container, $concrete) |
|
43 | + public function __construct( Container $container, $concrete ) |
|
44 | 44 | { |
45 | 45 | $this->concrete = $concrete; |
46 | 46 | $this->container = $container; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param string $abstract |
53 | 53 | * @return $this |
54 | 54 | */ |
55 | - public function needs($abstract) |
|
55 | + public function needs( $abstract ) |
|
56 | 56 | { |
57 | 57 | $this->needs = $abstract; |
58 | 58 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param \Closure|string $implementation |
66 | 66 | * @return void |
67 | 67 | */ |
68 | - public function give($implementation) |
|
68 | + public function give( $implementation ) |
|
69 | 69 | { |
70 | 70 | $this->container->addContextualBinding( |
71 | 71 | $this->concrete, $this->needs, $implementation |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | use GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Container\ContextualBindingBuilder as ContextualBindingBuilderContract; |
12 | 12 | |
13 | -class ContextualBindingBuilder implements ContextualBindingBuilderContract |
|
14 | -{ |
|
13 | +class ContextualBindingBuilder implements ContextualBindingBuilderContract { |
|
15 | 14 | /** |
16 | 15 | * The underlying container instance. |
17 | 16 | * |
@@ -40,8 +39,7 @@ discard block |
||
40 | 39 | * @param string $concrete |
41 | 40 | * @return void |
42 | 41 | */ |
43 | - public function __construct(Container $container, $concrete) |
|
44 | - { |
|
42 | + public function __construct(Container $container, $concrete) { |
|
45 | 43 | $this->concrete = $concrete; |
46 | 44 | $this->container = $container; |
47 | 45 | } |
@@ -52,8 +50,7 @@ discard block |
||
52 | 50 | * @param string $abstract |
53 | 51 | * @return $this |
54 | 52 | */ |
55 | - public function needs($abstract) |
|
56 | - { |
|
53 | + public function needs($abstract) { |
|
57 | 54 | $this->needs = $abstract; |
58 | 55 | |
59 | 56 | return $this; |
@@ -65,8 +62,7 @@ discard block |
||
65 | 62 | * @param \Closure|string $implementation |
66 | 63 | * @return void |
67 | 64 | */ |
68 | - public function give($implementation) |
|
69 | - { |
|
65 | + public function give($implementation) { |
|
70 | 66 | $this->container->addContextualBinding( |
71 | 67 | $this->concrete, $this->needs, $implementation |
72 | 68 | ); |
@@ -15,164 +15,164 @@ |
||
15 | 15 | |
16 | 16 | class BoundMethod |
17 | 17 | { |
18 | - /** |
|
19 | - * Call the given Closure / class@method and inject its dependencies. |
|
20 | - * |
|
21 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
22 | - * @param callable|string $callback |
|
23 | - * @param array $parameters |
|
24 | - * @param string|null $defaultMethod |
|
25 | - * @return mixed |
|
26 | - */ |
|
27 | - public static function call($container, $callback, array $parameters = [], $defaultMethod = null) |
|
28 | - { |
|
29 | - if (static::isCallableWithAtSign($callback) || $defaultMethod) { |
|
30 | - return static::callClass($container, $callback, $parameters, $defaultMethod); |
|
31 | - } |
|
32 | - |
|
33 | - return static::callBoundMethod($container, $callback, function () use ($container, $callback, $parameters) { |
|
34 | - return call_user_func_array( |
|
35 | - $callback, static::getMethodDependencies($container, $callback, $parameters) |
|
36 | - ); |
|
37 | - }); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Call a string reference to a class using Class@method syntax. |
|
42 | - * |
|
43 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
44 | - * @param string $target |
|
45 | - * @param array $parameters |
|
46 | - * @param string|null $defaultMethod |
|
47 | - * @return mixed |
|
48 | - * |
|
49 | - * @throws \InvalidArgumentException |
|
50 | - */ |
|
51 | - protected static function callClass($container, $target, array $parameters = [], $defaultMethod = null) |
|
52 | - { |
|
53 | - $segments = explode('@', $target); |
|
54 | - |
|
55 | - // We will assume an @ sign is used to delimit the class name from the method |
|
56 | - // name. We will split on this @ sign and then build a callable array that |
|
57 | - // we can pass right back into the "call" method for dependency binding. |
|
58 | - $method = count($segments) == 2 |
|
59 | - ? $segments[1] : $defaultMethod; |
|
60 | - |
|
61 | - if (is_null($method)) { |
|
62 | - throw new InvalidArgumentException('Method not provided.'); |
|
63 | - } |
|
64 | - |
|
65 | - return static::call( |
|
66 | - $container, [$container->make($segments[0]), $method], $parameters |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Call a method that has been bound to the container. |
|
72 | - * |
|
73 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
74 | - * @param callable $callback |
|
75 | - * @param mixed $default |
|
76 | - * @return mixed |
|
77 | - */ |
|
78 | - protected static function callBoundMethod($container, $callback, $default) |
|
79 | - { |
|
80 | - if (! is_array($callback)) { |
|
81 | - return $default instanceof Closure ? $default() : $default; |
|
82 | - } |
|
83 | - |
|
84 | - // Here we need to turn the array callable into a Class@method string we can use to |
|
85 | - // examine the container and see if there are any method bindings for this given |
|
86 | - // method. If there are, we can call this method binding callback immediately. |
|
87 | - $method = static::normalizeMethod($callback); |
|
88 | - |
|
89 | - if ($container->hasMethodBinding($method)) { |
|
90 | - return $container->callMethodBinding($method, $callback[0]); |
|
91 | - } |
|
92 | - |
|
93 | - return $default instanceof Closure ? $default() : $default; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Normalize the given callback into a Class@method string. |
|
98 | - * |
|
99 | - * @param callable $callback |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - protected static function normalizeMethod($callback) |
|
103 | - { |
|
104 | - $class = is_string($callback[0]) ? $callback[0] : get_class($callback[0]); |
|
105 | - |
|
106 | - return "{$class}@{$callback[1]}"; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get all dependencies for a given method. |
|
111 | - * |
|
112 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container |
|
113 | - * @param callable|string $callback |
|
114 | - * @param array $parameters |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - protected static function getMethodDependencies($container, $callback, array $parameters = []) |
|
118 | - { |
|
119 | - $dependencies = []; |
|
120 | - |
|
121 | - foreach (static::getCallReflector($callback)->getParameters() as $parameter) { |
|
122 | - static::addDependencyForCallParameter($container, $parameter, $parameters, $dependencies); |
|
123 | - } |
|
124 | - |
|
125 | - return array_merge($dependencies, $parameters); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Get the proper reflection instance for the given callback. |
|
130 | - * |
|
131 | - * @param callable|string $callback |
|
132 | - * @return \ReflectionFunctionAbstract |
|
133 | - */ |
|
134 | - protected static function getCallReflector($callback) |
|
135 | - { |
|
136 | - if (is_string($callback) && strpos($callback, '::') !== false) { |
|
137 | - $callback = explode('::', $callback); |
|
138 | - } |
|
139 | - |
|
140 | - return is_array($callback) |
|
141 | - ? new ReflectionMethod($callback[0], $callback[1]) |
|
142 | - : new ReflectionFunction($callback); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Get the dependency for the given call parameter. |
|
147 | - * |
|
148 | - * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
149 | - * @param \ReflectionParameter $parameter |
|
150 | - * @param array $parameters |
|
151 | - * @param array $dependencies |
|
152 | - * @return mixed |
|
153 | - */ |
|
154 | - protected static function addDependencyForCallParameter($container, $parameter, |
|
155 | - array &$parameters, &$dependencies) |
|
156 | - { |
|
157 | - if (array_key_exists($parameter->name, $parameters)) { |
|
158 | - $dependencies[] = $parameters[$parameter->name]; |
|
159 | - |
|
160 | - unset($parameters[$parameter->name]); |
|
161 | - } elseif ($parameter->getClass()) { |
|
162 | - $dependencies[] = $container->make($parameter->getClass()->name); |
|
163 | - } elseif ($parameter->isDefaultValueAvailable()) { |
|
164 | - $dependencies[] = $parameter->getDefaultValue(); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Determine if the given string is in Class@method syntax. |
|
170 | - * |
|
171 | - * @param mixed $callback |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - protected static function isCallableWithAtSign($callback) |
|
175 | - { |
|
176 | - return is_string($callback) && strpos($callback, '@') !== false; |
|
177 | - } |
|
18 | + /** |
|
19 | + * Call the given Closure / class@method and inject its dependencies. |
|
20 | + * |
|
21 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
22 | + * @param callable|string $callback |
|
23 | + * @param array $parameters |
|
24 | + * @param string|null $defaultMethod |
|
25 | + * @return mixed |
|
26 | + */ |
|
27 | + public static function call($container, $callback, array $parameters = [], $defaultMethod = null) |
|
28 | + { |
|
29 | + if (static::isCallableWithAtSign($callback) || $defaultMethod) { |
|
30 | + return static::callClass($container, $callback, $parameters, $defaultMethod); |
|
31 | + } |
|
32 | + |
|
33 | + return static::callBoundMethod($container, $callback, function () use ($container, $callback, $parameters) { |
|
34 | + return call_user_func_array( |
|
35 | + $callback, static::getMethodDependencies($container, $callback, $parameters) |
|
36 | + ); |
|
37 | + }); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Call a string reference to a class using Class@method syntax. |
|
42 | + * |
|
43 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
44 | + * @param string $target |
|
45 | + * @param array $parameters |
|
46 | + * @param string|null $defaultMethod |
|
47 | + * @return mixed |
|
48 | + * |
|
49 | + * @throws \InvalidArgumentException |
|
50 | + */ |
|
51 | + protected static function callClass($container, $target, array $parameters = [], $defaultMethod = null) |
|
52 | + { |
|
53 | + $segments = explode('@', $target); |
|
54 | + |
|
55 | + // We will assume an @ sign is used to delimit the class name from the method |
|
56 | + // name. We will split on this @ sign and then build a callable array that |
|
57 | + // we can pass right back into the "call" method for dependency binding. |
|
58 | + $method = count($segments) == 2 |
|
59 | + ? $segments[1] : $defaultMethod; |
|
60 | + |
|
61 | + if (is_null($method)) { |
|
62 | + throw new InvalidArgumentException('Method not provided.'); |
|
63 | + } |
|
64 | + |
|
65 | + return static::call( |
|
66 | + $container, [$container->make($segments[0]), $method], $parameters |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Call a method that has been bound to the container. |
|
72 | + * |
|
73 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
74 | + * @param callable $callback |
|
75 | + * @param mixed $default |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | + protected static function callBoundMethod($container, $callback, $default) |
|
79 | + { |
|
80 | + if (! is_array($callback)) { |
|
81 | + return $default instanceof Closure ? $default() : $default; |
|
82 | + } |
|
83 | + |
|
84 | + // Here we need to turn the array callable into a Class@method string we can use to |
|
85 | + // examine the container and see if there are any method bindings for this given |
|
86 | + // method. If there are, we can call this method binding callback immediately. |
|
87 | + $method = static::normalizeMethod($callback); |
|
88 | + |
|
89 | + if ($container->hasMethodBinding($method)) { |
|
90 | + return $container->callMethodBinding($method, $callback[0]); |
|
91 | + } |
|
92 | + |
|
93 | + return $default instanceof Closure ? $default() : $default; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Normalize the given callback into a Class@method string. |
|
98 | + * |
|
99 | + * @param callable $callback |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + protected static function normalizeMethod($callback) |
|
103 | + { |
|
104 | + $class = is_string($callback[0]) ? $callback[0] : get_class($callback[0]); |
|
105 | + |
|
106 | + return "{$class}@{$callback[1]}"; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get all dependencies for a given method. |
|
111 | + * |
|
112 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container |
|
113 | + * @param callable|string $callback |
|
114 | + * @param array $parameters |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + protected static function getMethodDependencies($container, $callback, array $parameters = []) |
|
118 | + { |
|
119 | + $dependencies = []; |
|
120 | + |
|
121 | + foreach (static::getCallReflector($callback)->getParameters() as $parameter) { |
|
122 | + static::addDependencyForCallParameter($container, $parameter, $parameters, $dependencies); |
|
123 | + } |
|
124 | + |
|
125 | + return array_merge($dependencies, $parameters); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Get the proper reflection instance for the given callback. |
|
130 | + * |
|
131 | + * @param callable|string $callback |
|
132 | + * @return \ReflectionFunctionAbstract |
|
133 | + */ |
|
134 | + protected static function getCallReflector($callback) |
|
135 | + { |
|
136 | + if (is_string($callback) && strpos($callback, '::') !== false) { |
|
137 | + $callback = explode('::', $callback); |
|
138 | + } |
|
139 | + |
|
140 | + return is_array($callback) |
|
141 | + ? new ReflectionMethod($callback[0], $callback[1]) |
|
142 | + : new ReflectionFunction($callback); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Get the dependency for the given call parameter. |
|
147 | + * |
|
148 | + * @param \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Container\Container $container |
|
149 | + * @param \ReflectionParameter $parameter |
|
150 | + * @param array $parameters |
|
151 | + * @param array $dependencies |
|
152 | + * @return mixed |
|
153 | + */ |
|
154 | + protected static function addDependencyForCallParameter($container, $parameter, |
|
155 | + array &$parameters, &$dependencies) |
|
156 | + { |
|
157 | + if (array_key_exists($parameter->name, $parameters)) { |
|
158 | + $dependencies[] = $parameters[$parameter->name]; |
|
159 | + |
|
160 | + unset($parameters[$parameter->name]); |
|
161 | + } elseif ($parameter->getClass()) { |
|
162 | + $dependencies[] = $container->make($parameter->getClass()->name); |
|
163 | + } elseif ($parameter->isDefaultValueAvailable()) { |
|
164 | + $dependencies[] = $parameter->getDefaultValue(); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Determine if the given string is in Class@method syntax. |
|
170 | + * |
|
171 | + * @param mixed $callback |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + protected static function isCallableWithAtSign($callback) |
|
175 | + { |
|
176 | + return is_string($callback) && strpos($callback, '@') !== false; |
|
177 | + } |
|
178 | 178 | } |
@@ -24,15 +24,15 @@ discard block |
||
24 | 24 | * @param string|null $defaultMethod |
25 | 25 | * @return mixed |
26 | 26 | */ |
27 | - public static function call($container, $callback, array $parameters = [], $defaultMethod = null) |
|
27 | + public static function call( $container, $callback, array $parameters = [ ], $defaultMethod = null ) |
|
28 | 28 | { |
29 | - if (static::isCallableWithAtSign($callback) || $defaultMethod) { |
|
30 | - return static::callClass($container, $callback, $parameters, $defaultMethod); |
|
29 | + if ( static::isCallableWithAtSign( $callback ) || $defaultMethod ) { |
|
30 | + return static::callClass( $container, $callback, $parameters, $defaultMethod ); |
|
31 | 31 | } |
32 | 32 | |
33 | - return static::callBoundMethod($container, $callback, function () use ($container, $callback, $parameters) { |
|
33 | + return static::callBoundMethod( $container, $callback, function() use ( $container, $callback, $parameters ) { |
|
34 | 34 | return call_user_func_array( |
35 | - $callback, static::getMethodDependencies($container, $callback, $parameters) |
|
35 | + $callback, static::getMethodDependencies( $container, $callback, $parameters ) |
|
36 | 36 | ); |
37 | 37 | }); |
38 | 38 | } |
@@ -48,22 +48,22 @@ discard block |
||
48 | 48 | * |
49 | 49 | * @throws \InvalidArgumentException |
50 | 50 | */ |
51 | - protected static function callClass($container, $target, array $parameters = [], $defaultMethod = null) |
|
51 | + protected static function callClass( $container, $target, array $parameters = [ ], $defaultMethod = null ) |
|
52 | 52 | { |
53 | - $segments = explode('@', $target); |
|
53 | + $segments = explode( '@', $target ); |
|
54 | 54 | |
55 | 55 | // We will assume an @ sign is used to delimit the class name from the method |
56 | 56 | // name. We will split on this @ sign and then build a callable array that |
57 | 57 | // we can pass right back into the "call" method for dependency binding. |
58 | - $method = count($segments) == 2 |
|
59 | - ? $segments[1] : $defaultMethod; |
|
58 | + $method = count( $segments ) == 2 |
|
59 | + ? $segments[ 1 ] : $defaultMethod; |
|
60 | 60 | |
61 | - if (is_null($method)) { |
|
62 | - throw new InvalidArgumentException('Method not provided.'); |
|
61 | + if ( is_null( $method ) ) { |
|
62 | + throw new InvalidArgumentException( 'Method not provided.' ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | return static::call( |
66 | - $container, [$container->make($segments[0]), $method], $parameters |
|
66 | + $container, [ $container->make( $segments[ 0 ] ), $method ], $parameters |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
@@ -75,19 +75,19 @@ discard block |
||
75 | 75 | * @param mixed $default |
76 | 76 | * @return mixed |
77 | 77 | */ |
78 | - protected static function callBoundMethod($container, $callback, $default) |
|
78 | + protected static function callBoundMethod( $container, $callback, $default ) |
|
79 | 79 | { |
80 | - if (! is_array($callback)) { |
|
80 | + if ( ! is_array( $callback ) ) { |
|
81 | 81 | return $default instanceof Closure ? $default() : $default; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // Here we need to turn the array callable into a Class@method string we can use to |
85 | 85 | // examine the container and see if there are any method bindings for this given |
86 | 86 | // method. If there are, we can call this method binding callback immediately. |
87 | - $method = static::normalizeMethod($callback); |
|
87 | + $method = static::normalizeMethod( $callback ); |
|
88 | 88 | |
89 | - if ($container->hasMethodBinding($method)) { |
|
90 | - return $container->callMethodBinding($method, $callback[0]); |
|
89 | + if ( $container->hasMethodBinding( $method ) ) { |
|
90 | + return $container->callMethodBinding( $method, $callback[ 0 ] ); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return $default instanceof Closure ? $default() : $default; |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | * @param callable $callback |
100 | 100 | * @return string |
101 | 101 | */ |
102 | - protected static function normalizeMethod($callback) |
|
102 | + protected static function normalizeMethod( $callback ) |
|
103 | 103 | { |
104 | - $class = is_string($callback[0]) ? $callback[0] : get_class($callback[0]); |
|
104 | + $class = is_string( $callback[ 0 ] ) ? $callback[ 0 ] : get_class( $callback[ 0 ] ); |
|
105 | 105 | |
106 | - return "{$class}@{$callback[1]}"; |
|
106 | + return "{$class}@{$callback[ 1 ]}"; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -114,15 +114,15 @@ discard block |
||
114 | 114 | * @param array $parameters |
115 | 115 | * @return array |
116 | 116 | */ |
117 | - protected static function getMethodDependencies($container, $callback, array $parameters = []) |
|
117 | + protected static function getMethodDependencies( $container, $callback, array $parameters = [ ] ) |
|
118 | 118 | { |
119 | - $dependencies = []; |
|
119 | + $dependencies = [ ]; |
|
120 | 120 | |
121 | - foreach (static::getCallReflector($callback)->getParameters() as $parameter) { |
|
122 | - static::addDependencyForCallParameter($container, $parameter, $parameters, $dependencies); |
|
121 | + foreach ( static::getCallReflector( $callback )->getParameters() as $parameter ) { |
|
122 | + static::addDependencyForCallParameter( $container, $parameter, $parameters, $dependencies ); |
|
123 | 123 | } |
124 | 124 | |
125 | - return array_merge($dependencies, $parameters); |
|
125 | + return array_merge( $dependencies, $parameters ); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -131,15 +131,15 @@ discard block |
||
131 | 131 | * @param callable|string $callback |
132 | 132 | * @return \ReflectionFunctionAbstract |
133 | 133 | */ |
134 | - protected static function getCallReflector($callback) |
|
134 | + protected static function getCallReflector( $callback ) |
|
135 | 135 | { |
136 | - if (is_string($callback) && strpos($callback, '::') !== false) { |
|
137 | - $callback = explode('::', $callback); |
|
136 | + if ( is_string( $callback ) && strpos( $callback, '::' ) !== false ) { |
|
137 | + $callback = explode( '::', $callback ); |
|
138 | 138 | } |
139 | 139 | |
140 | - return is_array($callback) |
|
141 | - ? new ReflectionMethod($callback[0], $callback[1]) |
|
142 | - : new ReflectionFunction($callback); |
|
140 | + return is_array( $callback ) |
|
141 | + ? new ReflectionMethod( $callback[ 0 ], $callback[ 1 ] ) |
|
142 | + : new ReflectionFunction( $callback ); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -151,17 +151,17 @@ discard block |
||
151 | 151 | * @param array $dependencies |
152 | 152 | * @return mixed |
153 | 153 | */ |
154 | - protected static function addDependencyForCallParameter($container, $parameter, |
|
155 | - array &$parameters, &$dependencies) |
|
154 | + protected static function addDependencyForCallParameter( $container, $parameter, |
|
155 | + array &$parameters, &$dependencies ) |
|
156 | 156 | { |
157 | - if (array_key_exists($parameter->name, $parameters)) { |
|
158 | - $dependencies[] = $parameters[$parameter->name]; |
|
159 | - |
|
160 | - unset($parameters[$parameter->name]); |
|
161 | - } elseif ($parameter->getClass()) { |
|
162 | - $dependencies[] = $container->make($parameter->getClass()->name); |
|
163 | - } elseif ($parameter->isDefaultValueAvailable()) { |
|
164 | - $dependencies[] = $parameter->getDefaultValue(); |
|
157 | + if ( array_key_exists( $parameter->name, $parameters ) ) { |
|
158 | + $dependencies[ ] = $parameters[ $parameter->name ]; |
|
159 | + |
|
160 | + unset( $parameters[ $parameter->name ] ); |
|
161 | + } elseif ( $parameter->getClass() ) { |
|
162 | + $dependencies[ ] = $container->make( $parameter->getClass()->name ); |
|
163 | + } elseif ( $parameter->isDefaultValueAvailable() ) { |
|
164 | + $dependencies[ ] = $parameter->getDefaultValue(); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * @param mixed $callback |
172 | 172 | * @return bool |
173 | 173 | */ |
174 | - protected static function isCallableWithAtSign($callback) |
|
174 | + protected static function isCallableWithAtSign( $callback ) |
|
175 | 175 | { |
176 | - return is_string($callback) && strpos($callback, '@') !== false; |
|
176 | + return is_string( $callback ) && strpos( $callback, '@' ) !== false; |
|
177 | 177 | } |
178 | 178 | } |
@@ -13,8 +13,7 @@ discard block |
||
13 | 13 | use ReflectionFunction; |
14 | 14 | use InvalidArgumentException; |
15 | 15 | |
16 | -class BoundMethod |
|
17 | -{ |
|
16 | +class BoundMethod { |
|
18 | 17 | /** |
19 | 18 | * Call the given Closure / class@method and inject its dependencies. |
20 | 19 | * |
@@ -24,8 +23,7 @@ discard block |
||
24 | 23 | * @param string|null $defaultMethod |
25 | 24 | * @return mixed |
26 | 25 | */ |
27 | - public static function call($container, $callback, array $parameters = [], $defaultMethod = null) |
|
28 | - { |
|
26 | + public static function call($container, $callback, array $parameters = [], $defaultMethod = null) { |
|
29 | 27 | if (static::isCallableWithAtSign($callback) || $defaultMethod) { |
30 | 28 | return static::callClass($container, $callback, $parameters, $defaultMethod); |
31 | 29 | } |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @throws \InvalidArgumentException |
50 | 48 | */ |
51 | - protected static function callClass($container, $target, array $parameters = [], $defaultMethod = null) |
|
52 | - { |
|
49 | + protected static function callClass($container, $target, array $parameters = [], $defaultMethod = null) { |
|
53 | 50 | $segments = explode('@', $target); |
54 | 51 | |
55 | 52 | // We will assume an @ sign is used to delimit the class name from the method |
@@ -75,8 +72,7 @@ discard block |
||
75 | 72 | * @param mixed $default |
76 | 73 | * @return mixed |
77 | 74 | */ |
78 | - protected static function callBoundMethod($container, $callback, $default) |
|
79 | - { |
|
75 | + protected static function callBoundMethod($container, $callback, $default) { |
|
80 | 76 | if (! is_array($callback)) { |
81 | 77 | return $default instanceof Closure ? $default() : $default; |
82 | 78 | } |
@@ -99,8 +95,7 @@ discard block |
||
99 | 95 | * @param callable $callback |
100 | 96 | * @return string |
101 | 97 | */ |
102 | - protected static function normalizeMethod($callback) |
|
103 | - { |
|
98 | + protected static function normalizeMethod($callback) { |
|
104 | 99 | $class = is_string($callback[0]) ? $callback[0] : get_class($callback[0]); |
105 | 100 | |
106 | 101 | return "{$class}@{$callback[1]}"; |
@@ -114,8 +109,7 @@ discard block |
||
114 | 109 | * @param array $parameters |
115 | 110 | * @return array |
116 | 111 | */ |
117 | - protected static function getMethodDependencies($container, $callback, array $parameters = []) |
|
118 | - { |
|
112 | + protected static function getMethodDependencies($container, $callback, array $parameters = []) { |
|
119 | 113 | $dependencies = []; |
120 | 114 | |
121 | 115 | foreach (static::getCallReflector($callback)->getParameters() as $parameter) { |
@@ -131,8 +125,7 @@ discard block |
||
131 | 125 | * @param callable|string $callback |
132 | 126 | * @return \ReflectionFunctionAbstract |
133 | 127 | */ |
134 | - protected static function getCallReflector($callback) |
|
135 | - { |
|
128 | + protected static function getCallReflector($callback) { |
|
136 | 129 | if (is_string($callback) && strpos($callback, '::') !== false) { |
137 | 130 | $callback = explode('::', $callback); |
138 | 131 | } |
@@ -152,8 +145,7 @@ discard block |
||
152 | 145 | * @return mixed |
153 | 146 | */ |
154 | 147 | protected static function addDependencyForCallParameter($container, $parameter, |
155 | - array &$parameters, &$dependencies) |
|
156 | - { |
|
148 | + array &$parameters, &$dependencies) { |
|
157 | 149 | if (array_key_exists($parameter->name, $parameters)) { |
158 | 150 | $dependencies[] = $parameters[$parameter->name]; |
159 | 151 | |
@@ -171,8 +163,7 @@ discard block |
||
171 | 163 | * @param mixed $callback |
172 | 164 | * @return bool |
173 | 165 | */ |
174 | - protected static function isCallableWithAtSign($callback) |
|
175 | - { |
|
166 | + protected static function isCallableWithAtSign($callback) { |
|
176 | 167 | return is_string($callback) && strpos($callback, '@') !== false; |
177 | 168 | } |
178 | 169 | } |
@@ -4,95 +4,95 @@ |
||
4 | 4 | |
5 | 5 | interface Log |
6 | 6 | { |
7 | - /** |
|
8 | - * Log an alert message to the logs. |
|
9 | - * |
|
10 | - * @param string $message |
|
11 | - * @param array $context |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function alert($message, array $context = []); |
|
7 | + /** |
|
8 | + * Log an alert message to the logs. |
|
9 | + * |
|
10 | + * @param string $message |
|
11 | + * @param array $context |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function alert($message, array $context = []); |
|
15 | 15 | |
16 | - /** |
|
17 | - * Log a critical message to the logs. |
|
18 | - * |
|
19 | - * @param string $message |
|
20 | - * @param array $context |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function critical($message, array $context = []); |
|
16 | + /** |
|
17 | + * Log a critical message to the logs. |
|
18 | + * |
|
19 | + * @param string $message |
|
20 | + * @param array $context |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function critical($message, array $context = []); |
|
24 | 24 | |
25 | - /** |
|
26 | - * Log an error message to the logs. |
|
27 | - * |
|
28 | - * @param string $message |
|
29 | - * @param array $context |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - public function error($message, array $context = []); |
|
25 | + /** |
|
26 | + * Log an error message to the logs. |
|
27 | + * |
|
28 | + * @param string $message |
|
29 | + * @param array $context |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + public function error($message, array $context = []); |
|
33 | 33 | |
34 | - /** |
|
35 | - * Log a warning message to the logs. |
|
36 | - * |
|
37 | - * @param string $message |
|
38 | - * @param array $context |
|
39 | - * @return void |
|
40 | - */ |
|
41 | - public function warning($message, array $context = []); |
|
34 | + /** |
|
35 | + * Log a warning message to the logs. |
|
36 | + * |
|
37 | + * @param string $message |
|
38 | + * @param array $context |
|
39 | + * @return void |
|
40 | + */ |
|
41 | + public function warning($message, array $context = []); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Log a notice to the logs. |
|
45 | - * |
|
46 | - * @param string $message |
|
47 | - * @param array $context |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function notice($message, array $context = []); |
|
43 | + /** |
|
44 | + * Log a notice to the logs. |
|
45 | + * |
|
46 | + * @param string $message |
|
47 | + * @param array $context |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function notice($message, array $context = []); |
|
51 | 51 | |
52 | - /** |
|
53 | - * Log an informational message to the logs. |
|
54 | - * |
|
55 | - * @param string $message |
|
56 | - * @param array $context |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public function info($message, array $context = []); |
|
52 | + /** |
|
53 | + * Log an informational message to the logs. |
|
54 | + * |
|
55 | + * @param string $message |
|
56 | + * @param array $context |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public function info($message, array $context = []); |
|
60 | 60 | |
61 | - /** |
|
62 | - * Log a debug message to the logs. |
|
63 | - * |
|
64 | - * @param string $message |
|
65 | - * @param array $context |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public function debug($message, array $context = []); |
|
61 | + /** |
|
62 | + * Log a debug message to the logs. |
|
63 | + * |
|
64 | + * @param string $message |
|
65 | + * @param array $context |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public function debug($message, array $context = []); |
|
69 | 69 | |
70 | - /** |
|
71 | - * Log a message to the logs. |
|
72 | - * |
|
73 | - * @param string $level |
|
74 | - * @param string $message |
|
75 | - * @param array $context |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - public function log($level, $message, array $context = []); |
|
70 | + /** |
|
71 | + * Log a message to the logs. |
|
72 | + * |
|
73 | + * @param string $level |
|
74 | + * @param string $message |
|
75 | + * @param array $context |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + public function log($level, $message, array $context = []); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Register a file log handler. |
|
82 | - * |
|
83 | - * @param string $path |
|
84 | - * @param string $level |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function useFiles($path, $level = 'debug'); |
|
80 | + /** |
|
81 | + * Register a file log handler. |
|
82 | + * |
|
83 | + * @param string $path |
|
84 | + * @param string $level |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function useFiles($path, $level = 'debug'); |
|
88 | 88 | |
89 | - /** |
|
90 | - * Register a daily file log handler. |
|
91 | - * |
|
92 | - * @param string $path |
|
93 | - * @param int $days |
|
94 | - * @param string $level |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function useDailyFiles($path, $days = 0, $level = 'debug'); |
|
89 | + /** |
|
90 | + * Register a daily file log handler. |
|
91 | + * |
|
92 | + * @param string $path |
|
93 | + * @param int $days |
|
94 | + * @param string $level |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public function useDailyFiles($path, $days = 0, $level = 'debug'); |
|
98 | 98 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @param array $context |
12 | 12 | * @return void |
13 | 13 | */ |
14 | - public function alert($message, array $context = []); |
|
14 | + public function alert( $message, array $context = [ ] ); |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Log a critical message to the logs. |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * @param array $context |
21 | 21 | * @return void |
22 | 22 | */ |
23 | - public function critical($message, array $context = []); |
|
23 | + public function critical( $message, array $context = [ ] ); |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Log an error message to the logs. |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param array $context |
30 | 30 | * @return void |
31 | 31 | */ |
32 | - public function error($message, array $context = []); |
|
32 | + public function error( $message, array $context = [ ] ); |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Log a warning message to the logs. |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @param array $context |
39 | 39 | * @return void |
40 | 40 | */ |
41 | - public function warning($message, array $context = []); |
|
41 | + public function warning( $message, array $context = [ ] ); |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Log a notice to the logs. |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param array $context |
48 | 48 | * @return void |
49 | 49 | */ |
50 | - public function notice($message, array $context = []); |
|
50 | + public function notice( $message, array $context = [ ] ); |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Log an informational message to the logs. |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @param array $context |
57 | 57 | * @return void |
58 | 58 | */ |
59 | - public function info($message, array $context = []); |
|
59 | + public function info( $message, array $context = [ ] ); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Log a debug message to the logs. |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param array $context |
66 | 66 | * @return void |
67 | 67 | */ |
68 | - public function debug($message, array $context = []); |
|
68 | + public function debug( $message, array $context = [ ] ); |
|
69 | 69 | |
70 | 70 | /** |
71 | 71 | * Log a message to the logs. |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @param array $context |
76 | 76 | * @return void |
77 | 77 | */ |
78 | - public function log($level, $message, array $context = []); |
|
78 | + public function log( $level, $message, array $context = [ ] ); |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Register a file log handler. |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @param string $level |
85 | 85 | * @return void |
86 | 86 | */ |
87 | - public function useFiles($path, $level = 'debug'); |
|
87 | + public function useFiles( $path, $level = 'debug' ); |
|
88 | 88 | |
89 | 89 | /** |
90 | 90 | * Register a daily file log handler. |
@@ -94,5 +94,5 @@ discard block |
||
94 | 94 | * @param string $level |
95 | 95 | * @return void |
96 | 96 | */ |
97 | - public function useDailyFiles($path, $days = 0, $level = 'debug'); |
|
97 | + public function useDailyFiles( $path, $days = 0, $level = 'debug' ); |
|
98 | 98 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | |
9 | 9 | namespace GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Logging; |
10 | 10 | |
11 | -interface Log |
|
12 | -{ |
|
11 | +interface Log { |
|
13 | 12 | /** |
14 | 13 | * Log an alert message to the logs. |
15 | 14 | * |
@@ -10,162 +10,162 @@ |
||
10 | 10 | |
11 | 11 | interface Session |
12 | 12 | { |
13 | - /** |
|
14 | - * Get the name of the session. |
|
15 | - * |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function getName(); |
|
19 | - |
|
20 | - /** |
|
21 | - * Get the current session ID. |
|
22 | - * |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function getId(); |
|
26 | - |
|
27 | - /** |
|
28 | - * Set the session ID. |
|
29 | - * |
|
30 | - * @param string $id |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function setId($id); |
|
34 | - |
|
35 | - /** |
|
36 | - * Start the session, reading the data from a handler. |
|
37 | - * |
|
38 | - * @return bool |
|
39 | - */ |
|
40 | - public function start(); |
|
41 | - |
|
42 | - /** |
|
43 | - * Save the session data to storage. |
|
44 | - * |
|
45 | - * @return bool |
|
46 | - */ |
|
47 | - public function save(); |
|
48 | - |
|
49 | - /** |
|
50 | - * Get all of the session data. |
|
51 | - * |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function all(); |
|
55 | - |
|
56 | - /** |
|
57 | - * Checks if a key exists. |
|
58 | - * |
|
59 | - * @param string|array $key |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function exists($key); |
|
63 | - |
|
64 | - /** |
|
65 | - * Checks if an a key is present and not null. |
|
66 | - * |
|
67 | - * @param string|array $key |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function has($key); |
|
71 | - |
|
72 | - /** |
|
73 | - * Get an item from the session. |
|
74 | - * |
|
75 | - * @param string $key |
|
76 | - * @param mixed $default |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function get($key, $default = null); |
|
80 | - |
|
81 | - /** |
|
82 | - * Put a key / value pair or array of key / value pairs in the session. |
|
83 | - * |
|
84 | - * @param string|array $key |
|
85 | - * @param mixed $value |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function put($key, $value = null); |
|
89 | - |
|
90 | - /** |
|
91 | - * Get the CSRF token value. |
|
92 | - * |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function token(); |
|
96 | - |
|
97 | - /** |
|
98 | - * Remove an item from the session, returning its value. |
|
99 | - * |
|
100 | - * @param string $key |
|
101 | - * @return mixed |
|
102 | - */ |
|
103 | - public function remove($key); |
|
104 | - |
|
105 | - /** |
|
106 | - * Remove one or many items from the session. |
|
107 | - * |
|
108 | - * @param string|array $keys |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public function forget($keys); |
|
112 | - |
|
113 | - /** |
|
114 | - * Remove all of the items from the session. |
|
115 | - * |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - public function flush(); |
|
119 | - |
|
120 | - /** |
|
121 | - * Generate a new session ID for the session. |
|
122 | - * |
|
123 | - * @param bool $destroy |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - public function migrate($destroy = false); |
|
127 | - |
|
128 | - /** |
|
129 | - * Determine if the session has been started. |
|
130 | - * |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function isStarted(); |
|
134 | - |
|
135 | - /** |
|
136 | - * Get the previous URL from the session. |
|
137 | - * |
|
138 | - * @return string|null |
|
139 | - */ |
|
140 | - public function previousUrl(); |
|
141 | - |
|
142 | - /** |
|
143 | - * Set the "previous" URL in the session. |
|
144 | - * |
|
145 | - * @param string $url |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - public function setPreviousUrl($url); |
|
149 | - |
|
150 | - /** |
|
151 | - * Get the session handler instance. |
|
152 | - * |
|
153 | - * @return \SessionHandlerInterface |
|
154 | - */ |
|
155 | - public function getHandler(); |
|
156 | - |
|
157 | - /** |
|
158 | - * Determine if the session handler needs a request. |
|
159 | - * |
|
160 | - * @return bool |
|
161 | - */ |
|
162 | - public function handlerNeedsRequest(); |
|
163 | - |
|
164 | - /** |
|
165 | - * Set the request on the handler instance. |
|
166 | - * |
|
167 | - * @param \Illuminate\Http\Request $request |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - public function setRequestOnHandler($request); |
|
13 | + /** |
|
14 | + * Get the name of the session. |
|
15 | + * |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function getName(); |
|
19 | + |
|
20 | + /** |
|
21 | + * Get the current session ID. |
|
22 | + * |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function getId(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Set the session ID. |
|
29 | + * |
|
30 | + * @param string $id |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function setId($id); |
|
34 | + |
|
35 | + /** |
|
36 | + * Start the session, reading the data from a handler. |
|
37 | + * |
|
38 | + * @return bool |
|
39 | + */ |
|
40 | + public function start(); |
|
41 | + |
|
42 | + /** |
|
43 | + * Save the session data to storage. |
|
44 | + * |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + public function save(); |
|
48 | + |
|
49 | + /** |
|
50 | + * Get all of the session data. |
|
51 | + * |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function all(); |
|
55 | + |
|
56 | + /** |
|
57 | + * Checks if a key exists. |
|
58 | + * |
|
59 | + * @param string|array $key |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function exists($key); |
|
63 | + |
|
64 | + /** |
|
65 | + * Checks if an a key is present and not null. |
|
66 | + * |
|
67 | + * @param string|array $key |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function has($key); |
|
71 | + |
|
72 | + /** |
|
73 | + * Get an item from the session. |
|
74 | + * |
|
75 | + * @param string $key |
|
76 | + * @param mixed $default |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function get($key, $default = null); |
|
80 | + |
|
81 | + /** |
|
82 | + * Put a key / value pair or array of key / value pairs in the session. |
|
83 | + * |
|
84 | + * @param string|array $key |
|
85 | + * @param mixed $value |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function put($key, $value = null); |
|
89 | + |
|
90 | + /** |
|
91 | + * Get the CSRF token value. |
|
92 | + * |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function token(); |
|
96 | + |
|
97 | + /** |
|
98 | + * Remove an item from the session, returning its value. |
|
99 | + * |
|
100 | + * @param string $key |
|
101 | + * @return mixed |
|
102 | + */ |
|
103 | + public function remove($key); |
|
104 | + |
|
105 | + /** |
|
106 | + * Remove one or many items from the session. |
|
107 | + * |
|
108 | + * @param string|array $keys |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public function forget($keys); |
|
112 | + |
|
113 | + /** |
|
114 | + * Remove all of the items from the session. |
|
115 | + * |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + public function flush(); |
|
119 | + |
|
120 | + /** |
|
121 | + * Generate a new session ID for the session. |
|
122 | + * |
|
123 | + * @param bool $destroy |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + public function migrate($destroy = false); |
|
127 | + |
|
128 | + /** |
|
129 | + * Determine if the session has been started. |
|
130 | + * |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function isStarted(); |
|
134 | + |
|
135 | + /** |
|
136 | + * Get the previous URL from the session. |
|
137 | + * |
|
138 | + * @return string|null |
|
139 | + */ |
|
140 | + public function previousUrl(); |
|
141 | + |
|
142 | + /** |
|
143 | + * Set the "previous" URL in the session. |
|
144 | + * |
|
145 | + * @param string $url |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + public function setPreviousUrl($url); |
|
149 | + |
|
150 | + /** |
|
151 | + * Get the session handler instance. |
|
152 | + * |
|
153 | + * @return \SessionHandlerInterface |
|
154 | + */ |
|
155 | + public function getHandler(); |
|
156 | + |
|
157 | + /** |
|
158 | + * Determine if the session handler needs a request. |
|
159 | + * |
|
160 | + * @return bool |
|
161 | + */ |
|
162 | + public function handlerNeedsRequest(); |
|
163 | + |
|
164 | + /** |
|
165 | + * Set the request on the handler instance. |
|
166 | + * |
|
167 | + * @param \Illuminate\Http\Request $request |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + public function setRequestOnHandler($request); |
|
171 | 171 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param string $id |
31 | 31 | * @return void |
32 | 32 | */ |
33 | - public function setId($id); |
|
33 | + public function setId( $id ); |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Start the session, reading the data from a handler. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param string|array $key |
60 | 60 | * @return bool |
61 | 61 | */ |
62 | - public function exists($key); |
|
62 | + public function exists( $key ); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Checks if an a key is present and not null. |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param string|array $key |
68 | 68 | * @return bool |
69 | 69 | */ |
70 | - public function has($key); |
|
70 | + public function has( $key ); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Get an item from the session. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param mixed $default |
77 | 77 | * @return mixed |
78 | 78 | */ |
79 | - public function get($key, $default = null); |
|
79 | + public function get( $key, $default = null ); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Put a key / value pair or array of key / value pairs in the session. |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param mixed $value |
86 | 86 | * @return void |
87 | 87 | */ |
88 | - public function put($key, $value = null); |
|
88 | + public function put( $key, $value = null ); |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * Get the CSRF token value. |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @param string $key |
101 | 101 | * @return mixed |
102 | 102 | */ |
103 | - public function remove($key); |
|
103 | + public function remove( $key ); |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Remove one or many items from the session. |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param string|array $keys |
109 | 109 | * @return void |
110 | 110 | */ |
111 | - public function forget($keys); |
|
111 | + public function forget( $keys ); |
|
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Remove all of the items from the session. |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param bool $destroy |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | - public function migrate($destroy = false); |
|
126 | + public function migrate( $destroy = false ); |
|
127 | 127 | |
128 | 128 | /** |
129 | 129 | * Determine if the session has been started. |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @param string $url |
146 | 146 | * @return void |
147 | 147 | */ |
148 | - public function setPreviousUrl($url); |
|
148 | + public function setPreviousUrl( $url ); |
|
149 | 149 | |
150 | 150 | /** |
151 | 151 | * Get the session handler instance. |
@@ -167,5 +167,5 @@ discard block |
||
167 | 167 | * @param \Illuminate\Http\Request $request |
168 | 168 | * @return void |
169 | 169 | */ |
170 | - public function setRequestOnHandler($request); |
|
170 | + public function setRequestOnHandler( $request ); |
|
171 | 171 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | |
9 | 9 | namespace GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Session; |
10 | 10 | |
11 | -interface Session |
|
12 | -{ |
|
11 | +interface Session { |
|
13 | 12 | /** |
14 | 13 | * Get the name of the session. |
15 | 14 | * |
@@ -4,27 +4,27 @@ |
||
4 | 4 | |
5 | 5 | interface Monitor |
6 | 6 | { |
7 | - /** |
|
8 | - * Register a callback to be executed on every iteration through the queue loop. |
|
9 | - * |
|
10 | - * @param mixed $callback |
|
11 | - * @return void |
|
12 | - */ |
|
13 | - public function looping($callback); |
|
7 | + /** |
|
8 | + * Register a callback to be executed on every iteration through the queue loop. |
|
9 | + * |
|
10 | + * @param mixed $callback |
|
11 | + * @return void |
|
12 | + */ |
|
13 | + public function looping($callback); |
|
14 | 14 | |
15 | - /** |
|
16 | - * Register a callback to be executed when a job fails after the maximum amount of retries. |
|
17 | - * |
|
18 | - * @param mixed $callback |
|
19 | - * @return void |
|
20 | - */ |
|
21 | - public function failing($callback); |
|
15 | + /** |
|
16 | + * Register a callback to be executed when a job fails after the maximum amount of retries. |
|
17 | + * |
|
18 | + * @param mixed $callback |
|
19 | + * @return void |
|
20 | + */ |
|
21 | + public function failing($callback); |
|
22 | 22 | |
23 | - /** |
|
24 | - * Register a callback to be executed when a daemon queue is stopping. |
|
25 | - * |
|
26 | - * @param mixed $callback |
|
27 | - * @return void |
|
28 | - */ |
|
29 | - public function stopping($callback); |
|
23 | + /** |
|
24 | + * Register a callback to be executed when a daemon queue is stopping. |
|
25 | + * |
|
26 | + * @param mixed $callback |
|
27 | + * @return void |
|
28 | + */ |
|
29 | + public function stopping($callback); |
|
30 | 30 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @param mixed $callback |
11 | 11 | * @return void |
12 | 12 | */ |
13 | - public function looping($callback); |
|
13 | + public function looping( $callback ); |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * Register a callback to be executed when a job fails after the maximum amount of retries. |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param mixed $callback |
19 | 19 | * @return void |
20 | 20 | */ |
21 | - public function failing($callback); |
|
21 | + public function failing( $callback ); |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * Register a callback to be executed when a daemon queue is stopping. |
@@ -26,5 +26,5 @@ discard block |
||
26 | 26 | * @param mixed $callback |
27 | 27 | * @return void |
28 | 28 | */ |
29 | - public function stopping($callback); |
|
29 | + public function stopping( $callback ); |
|
30 | 30 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | |
9 | 9 | namespace GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Queue; |
10 | 10 | |
11 | -interface Monitor |
|
12 | -{ |
|
11 | +interface Monitor { |
|
13 | 12 | /** |
14 | 13 | * Register a callback to be executed on every iteration through the queue loop. |
15 | 14 | * |
@@ -6,17 +6,17 @@ |
||
6 | 6 | |
7 | 7 | class EntityNotFoundException extends InvalidArgumentException |
8 | 8 | { |
9 | - /** |
|
10 | - * Create a new exception instance. |
|
11 | - * |
|
12 | - * @param string $type |
|
13 | - * @param mixed $id |
|
14 | - * @return void |
|
15 | - */ |
|
16 | - public function __construct($type, $id) |
|
17 | - { |
|
18 | - $id = (string) $id; |
|
9 | + /** |
|
10 | + * Create a new exception instance. |
|
11 | + * |
|
12 | + * @param string $type |
|
13 | + * @param mixed $id |
|
14 | + * @return void |
|
15 | + */ |
|
16 | + public function __construct($type, $id) |
|
17 | + { |
|
18 | + $id = (string) $id; |
|
19 | 19 | |
20 | - parent::__construct("Queueable entity [{$type}] not found for ID [{$id}]."); |
|
21 | - } |
|
20 | + parent::__construct("Queueable entity [{$type}] not found for ID [{$id}]."); |
|
21 | + } |
|
22 | 22 | } |
@@ -13,10 +13,10 @@ |
||
13 | 13 | * @param mixed $id |
14 | 14 | * @return void |
15 | 15 | */ |
16 | - public function __construct($type, $id) |
|
16 | + public function __construct( $type, $id ) |
|
17 | 17 | { |
18 | - $id = (string) $id; |
|
18 | + $id = (string)$id; |
|
19 | 19 | |
20 | - parent::__construct("Queueable entity [{$type}] not found for ID [{$id}]."); |
|
20 | + parent::__construct( "Queueable entity [{$type}] not found for ID [{$id}]." ); |
|
21 | 21 | } |
22 | 22 | } |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use InvalidArgumentException; |
6 | 6 | |
7 | -class EntityNotFoundException extends InvalidArgumentException |
|
8 | -{ |
|
7 | +class EntityNotFoundException extends InvalidArgumentException { |
|
9 | 8 | /** |
10 | 9 | * Create a new exception instance. |
11 | 10 | * |
@@ -13,8 +12,7 @@ discard block |
||
13 | 12 | * @param mixed $id |
14 | 13 | * @return void |
15 | 14 | */ |
16 | - public function __construct($type, $id) |
|
17 | - { |
|
15 | + public function __construct($type, $id) { |
|
18 | 16 | $id = (string) $id; |
19 | 17 | |
20 | 18 | parent::__construct("Queueable entity [{$type}] not found for ID [{$id}]."); |
@@ -4,12 +4,12 @@ |
||
4 | 4 | |
5 | 5 | interface EntityResolver |
6 | 6 | { |
7 | - /** |
|
8 | - * Resolve the entity for the given ID. |
|
9 | - * |
|
10 | - * @param string $type |
|
11 | - * @param mixed $id |
|
12 | - * @return mixed |
|
13 | - */ |
|
14 | - public function resolve($type, $id); |
|
7 | + /** |
|
8 | + * Resolve the entity for the given ID. |
|
9 | + * |
|
10 | + * @param string $type |
|
11 | + * @param mixed $id |
|
12 | + * @return mixed |
|
13 | + */ |
|
14 | + public function resolve($type, $id); |
|
15 | 15 | } |
@@ -11,5 +11,5 @@ |
||
11 | 11 | * @param mixed $id |
12 | 12 | * @return mixed |
13 | 13 | */ |
14 | - public function resolve($type, $id); |
|
14 | + public function resolve( $type, $id ); |
|
15 | 15 | } |
@@ -8,8 +8,7 @@ |
||
8 | 8 | |
9 | 9 | namespace GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Queue; |
10 | 10 | |
11 | -interface EntityResolver |
|
12 | -{ |
|
11 | +interface EntityResolver { |
|
13 | 12 | /** |
14 | 13 | * Resolve the entity for the given ID. |
15 | 14 | * |