Completed
Push — develop ( e2688f...d26e21 )
by Zack
29:42 queued 09:43
created
vendor_prefixed/illuminate/filesystem/FilesystemAdapter.php 1 patch
Indentation   +522 added lines, -522 removed lines patch added patch discarded remove patch
@@ -29,526 +29,526 @@
 block discarded – undo
29 29
  */
30 30
 class FilesystemAdapter implements FilesystemContract, CloudFilesystemContract
31 31
 {
32
-    /**
33
-     * The Flysystem filesystem implementation.
34
-     *
35
-     * @var \League\Flysystem\FilesystemInterface
36
-     */
37
-    protected $driver;
38
-
39
-    /**
40
-     * Create a new filesystem adapter instance.
41
-     *
42
-     * @param  \League\Flysystem\FilesystemInterface  $driver
43
-     * @return void
44
-     */
45
-    public function __construct(FilesystemInterface $driver)
46
-    {
47
-        $this->driver = $driver;
48
-    }
49
-
50
-    /**
51
-     * Assert that the given file exists.
52
-     *
53
-     * @param  string  $path
54
-     * @return void
55
-     */
56
-    public function assertExists($path)
57
-    {
58
-        PHPUnit::assertTrue(
59
-            $this->exists($path), "Unable to find a file at path [{$path}]."
60
-        );
61
-    }
62
-
63
-    /**
64
-     * Assert that the given file does not exist.
65
-     *
66
-     * @param  string  $path
67
-     * @return void
68
-     */
69
-    public function assertMissing($path)
70
-    {
71
-        PHPUnit::assertFalse(
72
-            $this->exists($path), "Found unexpected file at path [{$path}]."
73
-        );
74
-    }
75
-
76
-    /**
77
-     * Determine if a file exists.
78
-     *
79
-     * @param  string  $path
80
-     * @return bool
81
-     */
82
-    public function exists($path)
83
-    {
84
-        return $this->driver->has($path);
85
-    }
86
-
87
-    /**
88
-     * Get the full path for the file at the given "short" path.
89
-     *
90
-     * @param  string  $path
91
-     * @return string
92
-     */
93
-    public function path($path)
94
-    {
95
-        return $this->driver->getAdapter()->getPathPrefix().$path;
96
-    }
97
-
98
-    /**
99
-     * Get the contents of a file.
100
-     *
101
-     * @param  string  $path
102
-     * @return string
103
-     *
104
-     * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException
105
-     */
106
-    public function get($path)
107
-    {
108
-        try {
109
-            return $this->driver->read($path);
110
-        } catch (FileNotFoundException $e) {
111
-            throw new ContractFileNotFoundException($path, $e->getCode(), $e);
112
-        }
113
-    }
114
-
115
-    /**
116
-     * Write the contents of a file.
117
-     *
118
-     * @param  string  $path
119
-     * @param  string|resource  $contents
120
-     * @param  array  $options
121
-     * @return bool
122
-     */
123
-    public function put($path, $contents, $options = [])
124
-    {
125
-        if (is_string($options)) {
126
-            $options = ['visibility' => $options];
127
-        }
128
-
129
-        // If the given contents is actually a file or uploaded file instance than we will
130
-        // automatically store the file using a stream. This provides a convenient path
131
-        // for the developer to store streams without managing them manually in code.
132
-        if ($contents instanceof File ||
133
-            $contents instanceof UploadedFile) {
134
-            return $this->putFile($path, $contents, $options);
135
-        }
136
-
137
-        return is_resource($contents)
138
-                ? $this->driver->putStream($path, $contents, $options)
139
-                : $this->driver->put($path, $contents, $options);
140
-    }
141
-
142
-    /**
143
-     * Store the uploaded file on the disk.
144
-     *
145
-     * @param  string  $path
146
-     * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
147
-     * @param  array  $options
148
-     * @return string|false
149
-     */
150
-    public function putFile($path, $file, $options = [])
151
-    {
152
-        return $this->putFileAs($path, $file, $file->hashName(), $options);
153
-    }
154
-
155
-    /**
156
-     * Store the uploaded file on the disk with a given name.
157
-     *
158
-     * @param  string  $path
159
-     * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
160
-     * @param  string  $name
161
-     * @param  array  $options
162
-     * @return string|false
163
-     */
164
-    public function putFileAs($path, $file, $name, $options = [])
165
-    {
166
-        $stream = fopen($file->getRealPath(), 'r+');
167
-
168
-        // Next, we will format the path of the file and store the file using a stream since
169
-        // they provide better performance than alternatives. Once we write the file this
170
-        // stream will get closed automatically by us so the developer doesn't have to.
171
-        $result = $this->put(
172
-            $path = trim($path.'/'.$name, '/'), $stream, $options
173
-        );
174
-
175
-        if (is_resource($stream)) {
176
-            fclose($stream);
177
-        }
178
-
179
-        return $result ? $path : false;
180
-    }
181
-
182
-    /**
183
-     * Get the visibility for the given path.
184
-     *
185
-     * @param  string  $path
186
-     * @return string
187
-     */
188
-    public function getVisibility($path)
189
-    {
190
-        if ($this->driver->getVisibility($path) == AdapterInterface::VISIBILITY_PUBLIC) {
191
-            return FilesystemContract::VISIBILITY_PUBLIC;
192
-        }
193
-
194
-        return FilesystemContract::VISIBILITY_PRIVATE;
195
-    }
196
-
197
-    /**
198
-     * Set the visibility for the given path.
199
-     *
200
-     * @param  string  $path
201
-     * @param  string  $visibility
202
-     * @return void
203
-     */
204
-    public function setVisibility($path, $visibility)
205
-    {
206
-        return $this->driver->setVisibility($path, $this->parseVisibility($visibility));
207
-    }
208
-
209
-    /**
210
-     * Prepend to a file.
211
-     *
212
-     * @param  string  $path
213
-     * @param  string  $data
214
-     * @param  string  $separator
215
-     * @return int
216
-     */
217
-    public function prepend($path, $data, $separator = PHP_EOL)
218
-    {
219
-        if ($this->exists($path)) {
220
-            return $this->put($path, $data.$separator.$this->get($path));
221
-        }
222
-
223
-        return $this->put($path, $data);
224
-    }
225
-
226
-    /**
227
-     * Append to a file.
228
-     *
229
-     * @param  string  $path
230
-     * @param  string  $data
231
-     * @param  string  $separator
232
-     * @return int
233
-     */
234
-    public function append($path, $data, $separator = PHP_EOL)
235
-    {
236
-        if ($this->exists($path)) {
237
-            return $this->put($path, $this->get($path).$separator.$data);
238
-        }
239
-
240
-        return $this->put($path, $data);
241
-    }
242
-
243
-    /**
244
-     * Delete the file at a given path.
245
-     *
246
-     * @param  string|array  $paths
247
-     * @return bool
248
-     */
249
-    public function delete($paths)
250
-    {
251
-        $paths = is_array($paths) ? $paths : func_get_args();
252
-
253
-        $success = true;
254
-
255
-        foreach ($paths as $path) {
256
-            try {
257
-                if (! $this->driver->delete($path)) {
258
-                    $success = false;
259
-                }
260
-            } catch (FileNotFoundException $e) {
261
-                $success = false;
262
-            }
263
-        }
264
-
265
-        return $success;
266
-    }
267
-
268
-    /**
269
-     * Copy a file to a new location.
270
-     *
271
-     * @param  string  $from
272
-     * @param  string  $to
273
-     * @return bool
274
-     */
275
-    public function copy($from, $to)
276
-    {
277
-        return $this->driver->copy($from, $to);
278
-    }
279
-
280
-    /**
281
-     * Move a file to a new location.
282
-     *
283
-     * @param  string  $from
284
-     * @param  string  $to
285
-     * @return bool
286
-     */
287
-    public function move($from, $to)
288
-    {
289
-        return $this->driver->rename($from, $to);
290
-    }
291
-
292
-    /**
293
-     * Get the file size of a given file.
294
-     *
295
-     * @param  string  $path
296
-     * @return int
297
-     */
298
-    public function size($path)
299
-    {
300
-        return $this->driver->getSize($path);
301
-    }
302
-
303
-    /**
304
-     * Get the mime-type of a given file.
305
-     *
306
-     * @param  string  $path
307
-     * @return string|false
308
-     */
309
-    public function mimeType($path)
310
-    {
311
-        return $this->driver->getMimetype($path);
312
-    }
313
-
314
-    /**
315
-     * Get the file's last modification time.
316
-     *
317
-     * @param  string  $path
318
-     * @return int
319
-     */
320
-    public function lastModified($path)
321
-    {
322
-        return $this->driver->getTimestamp($path);
323
-    }
324
-
325
-    /**
326
-     * Get the URL for the file at the given path.
327
-     *
328
-     * @param  string  $path
329
-     * @return string
330
-     */
331
-    public function url($path)
332
-    {
333
-        $adapter = $this->driver->getAdapter();
334
-
335
-        if (method_exists($adapter, 'getUrl')) {
336
-            return $adapter->getUrl($path);
337
-        } elseif ($adapter instanceof AwsS3Adapter) {
338
-            return $this->getAwsUrl($adapter, $path);
339
-        } elseif ($adapter instanceof LocalAdapter) {
340
-            return $this->getLocalUrl($path);
341
-        } else {
342
-            throw new RuntimeException('This driver does not support retrieving URLs.');
343
-        }
344
-    }
345
-
346
-    /**
347
-     * Get the URL for the file at the given path.
348
-     *
349
-     * @param  \League\Flysystem\AwsS3v3\AwsS3Adapter  $adapter
350
-     * @param  string  $path
351
-     * @return string
352
-     */
353
-    protected function getAwsUrl($adapter, $path)
354
-    {
355
-        return $adapter->getClient()->getObjectUrl(
356
-            $adapter->getBucket(), $adapter->getPathPrefix().$path
357
-        );
358
-    }
359
-
360
-    /**
361
-     * Get the URL for the file at the given path.
362
-     *
363
-     * @param  string  $path
364
-     * @return string
365
-     */
366
-    protected function getLocalUrl($path)
367
-    {
368
-        $config = $this->driver->getConfig();
369
-
370
-        // If an explicit base URL has been set on the disk configuration then we will use
371
-        // it as the base URL instead of the default path. This allows the developer to
372
-        // have full control over the base path for this filesystem's generated URLs.
373
-        if ($config->has('url')) {
374
-            return rtrim($config->get('url'), '/').'/'.ltrim($path, '/');
375
-        }
376
-
377
-        $path = '/storage/'.$path;
378
-
379
-        // If the path contains "storage/public", it probably means the developer is using
380
-        // the default disk to generate the path instead of the "public" disk like they
381
-        // are really supposed to use. We will remove the public from this path here.
382
-        if (Str::contains($path, '/storage/public/')) {
383
-            return Str::replaceFirst('/public/', '/', $path);
384
-        } else {
385
-            return $path;
386
-        }
387
-    }
388
-
389
-    /**
390
-     * Get a temporary URL for the file at the given path.
391
-     *
392
-     * @param  string  $path
393
-     * @param  \DateTimeInterface  $expiration
394
-     * @param  array  $options
395
-     * @return string
396
-     */
397
-    public function temporaryUrl($path, $expiration, array $options = [])
398
-    {
399
-        $adapter = $this->driver->getAdapter();
400
-
401
-        if (method_exists($adapter, 'getTemporaryUrl')) {
402
-            return $adapter->getTemporaryUrl($path, $expiration, $options);
403
-        } elseif (! $adapter instanceof AwsS3Adapter) {
404
-            throw new RuntimeException('This driver does not support creating temporary URLs.');
405
-        }
406
-
407
-        $client = $adapter->getClient();
408
-
409
-        $command = $client->getCommand('GetObject', array_merge([
410
-            'Bucket' => $adapter->getBucket(),
411
-            'Key' => $adapter->getPathPrefix().$path,
412
-        ], $options));
413
-
414
-        return (string) $client->createPresignedRequest(
415
-            $command, $expiration
416
-        )->getUri();
417
-    }
418
-
419
-    /**
420
-     * Get an array of all files in a directory.
421
-     *
422
-     * @param  string|null  $directory
423
-     * @param  bool  $recursive
424
-     * @return array
425
-     */
426
-    public function files($directory = null, $recursive = false)
427
-    {
428
-        $contents = $this->driver->listContents($directory, $recursive);
429
-
430
-        return $this->filterContentsByType($contents, 'file');
431
-    }
432
-
433
-    /**
434
-     * Get all of the files from the given directory (recursive).
435
-     *
436
-     * @param  string|null  $directory
437
-     * @return array
438
-     */
439
-    public function allFiles($directory = null)
440
-    {
441
-        return $this->files($directory, true);
442
-    }
443
-
444
-    /**
445
-     * Get all of the directories within a given directory.
446
-     *
447
-     * @param  string|null  $directory
448
-     * @param  bool  $recursive
449
-     * @return array
450
-     */
451
-    public function directories($directory = null, $recursive = false)
452
-    {
453
-        $contents = $this->driver->listContents($directory, $recursive);
454
-
455
-        return $this->filterContentsByType($contents, 'dir');
456
-    }
457
-
458
-    /**
459
-     * Get all (recursive) of the directories within a given directory.
460
-     *
461
-     * @param  string|null  $directory
462
-     * @return array
463
-     */
464
-    public function allDirectories($directory = null)
465
-    {
466
-        return $this->directories($directory, true);
467
-    }
468
-
469
-    /**
470
-     * Create a directory.
471
-     *
472
-     * @param  string  $path
473
-     * @return bool
474
-     */
475
-    public function makeDirectory($path)
476
-    {
477
-        return $this->driver->createDir($path);
478
-    }
479
-
480
-    /**
481
-     * Recursively delete a directory.
482
-     *
483
-     * @param  string  $directory
484
-     * @return bool
485
-     */
486
-    public function deleteDirectory($directory)
487
-    {
488
-        return $this->driver->deleteDir($directory);
489
-    }
490
-
491
-    /**
492
-     * Get the Flysystem driver.
493
-     *
494
-     * @return \League\Flysystem\FilesystemInterface
495
-     */
496
-    public function getDriver()
497
-    {
498
-        return $this->driver;
499
-    }
500
-
501
-    /**
502
-     * Filter directory contents by type.
503
-     *
504
-     * @param  array  $contents
505
-     * @param  string  $type
506
-     * @return array
507
-     */
508
-    protected function filterContentsByType($contents, $type)
509
-    {
510
-        return Collection::make($contents)
511
-            ->where('type', $type)
512
-            ->pluck('path')
513
-            ->values()
514
-            ->all();
515
-    }
516
-
517
-    /**
518
-     * Parse the given visibility value.
519
-     *
520
-     * @param  string|null  $visibility
521
-     * @return string|null
522
-     *
523
-     * @throws \InvalidArgumentException
524
-     */
525
-    protected function parseVisibility($visibility)
526
-    {
527
-        if (is_null($visibility)) {
528
-            return;
529
-        }
530
-
531
-        switch ($visibility) {
532
-            case FilesystemContract::VISIBILITY_PUBLIC:
533
-                return AdapterInterface::VISIBILITY_PUBLIC;
534
-            case FilesystemContract::VISIBILITY_PRIVATE:
535
-                return AdapterInterface::VISIBILITY_PRIVATE;
536
-        }
537
-
538
-        throw new InvalidArgumentException('Unknown visibility: '.$visibility);
539
-    }
540
-
541
-    /**
542
-     * Pass dynamic methods call onto Flysystem.
543
-     *
544
-     * @param  string  $method
545
-     * @param  array  $parameters
546
-     * @return mixed
547
-     *
548
-     * @throws \BadMethodCallException
549
-     */
550
-    public function __call($method, array $parameters)
551
-    {
552
-        return call_user_func_array([$this->driver, $method], $parameters);
553
-    }
32
+	/**
33
+	 * The Flysystem filesystem implementation.
34
+	 *
35
+	 * @var \League\Flysystem\FilesystemInterface
36
+	 */
37
+	protected $driver;
38
+
39
+	/**
40
+	 * Create a new filesystem adapter instance.
41
+	 *
42
+	 * @param  \League\Flysystem\FilesystemInterface  $driver
43
+	 * @return void
44
+	 */
45
+	public function __construct(FilesystemInterface $driver)
46
+	{
47
+		$this->driver = $driver;
48
+	}
49
+
50
+	/**
51
+	 * Assert that the given file exists.
52
+	 *
53
+	 * @param  string  $path
54
+	 * @return void
55
+	 */
56
+	public function assertExists($path)
57
+	{
58
+		PHPUnit::assertTrue(
59
+			$this->exists($path), "Unable to find a file at path [{$path}]."
60
+		);
61
+	}
62
+
63
+	/**
64
+	 * Assert that the given file does not exist.
65
+	 *
66
+	 * @param  string  $path
67
+	 * @return void
68
+	 */
69
+	public function assertMissing($path)
70
+	{
71
+		PHPUnit::assertFalse(
72
+			$this->exists($path), "Found unexpected file at path [{$path}]."
73
+		);
74
+	}
75
+
76
+	/**
77
+	 * Determine if a file exists.
78
+	 *
79
+	 * @param  string  $path
80
+	 * @return bool
81
+	 */
82
+	public function exists($path)
83
+	{
84
+		return $this->driver->has($path);
85
+	}
86
+
87
+	/**
88
+	 * Get the full path for the file at the given "short" path.
89
+	 *
90
+	 * @param  string  $path
91
+	 * @return string
92
+	 */
93
+	public function path($path)
94
+	{
95
+		return $this->driver->getAdapter()->getPathPrefix().$path;
96
+	}
97
+
98
+	/**
99
+	 * Get the contents of a file.
100
+	 *
101
+	 * @param  string  $path
102
+	 * @return string
103
+	 *
104
+	 * @throws \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\FileNotFoundException
105
+	 */
106
+	public function get($path)
107
+	{
108
+		try {
109
+			return $this->driver->read($path);
110
+		} catch (FileNotFoundException $e) {
111
+			throw new ContractFileNotFoundException($path, $e->getCode(), $e);
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * Write the contents of a file.
117
+	 *
118
+	 * @param  string  $path
119
+	 * @param  string|resource  $contents
120
+	 * @param  array  $options
121
+	 * @return bool
122
+	 */
123
+	public function put($path, $contents, $options = [])
124
+	{
125
+		if (is_string($options)) {
126
+			$options = ['visibility' => $options];
127
+		}
128
+
129
+		// If the given contents is actually a file or uploaded file instance than we will
130
+		// automatically store the file using a stream. This provides a convenient path
131
+		// for the developer to store streams without managing them manually in code.
132
+		if ($contents instanceof File ||
133
+			$contents instanceof UploadedFile) {
134
+			return $this->putFile($path, $contents, $options);
135
+		}
136
+
137
+		return is_resource($contents)
138
+				? $this->driver->putStream($path, $contents, $options)
139
+				: $this->driver->put($path, $contents, $options);
140
+	}
141
+
142
+	/**
143
+	 * Store the uploaded file on the disk.
144
+	 *
145
+	 * @param  string  $path
146
+	 * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
147
+	 * @param  array  $options
148
+	 * @return string|false
149
+	 */
150
+	public function putFile($path, $file, $options = [])
151
+	{
152
+		return $this->putFileAs($path, $file, $file->hashName(), $options);
153
+	}
154
+
155
+	/**
156
+	 * Store the uploaded file on the disk with a given name.
157
+	 *
158
+	 * @param  string  $path
159
+	 * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
160
+	 * @param  string  $name
161
+	 * @param  array  $options
162
+	 * @return string|false
163
+	 */
164
+	public function putFileAs($path, $file, $name, $options = [])
165
+	{
166
+		$stream = fopen($file->getRealPath(), 'r+');
167
+
168
+		// Next, we will format the path of the file and store the file using a stream since
169
+		// they provide better performance than alternatives. Once we write the file this
170
+		// stream will get closed automatically by us so the developer doesn't have to.
171
+		$result = $this->put(
172
+			$path = trim($path.'/'.$name, '/'), $stream, $options
173
+		);
174
+
175
+		if (is_resource($stream)) {
176
+			fclose($stream);
177
+		}
178
+
179
+		return $result ? $path : false;
180
+	}
181
+
182
+	/**
183
+	 * Get the visibility for the given path.
184
+	 *
185
+	 * @param  string  $path
186
+	 * @return string
187
+	 */
188
+	public function getVisibility($path)
189
+	{
190
+		if ($this->driver->getVisibility($path) == AdapterInterface::VISIBILITY_PUBLIC) {
191
+			return FilesystemContract::VISIBILITY_PUBLIC;
192
+		}
193
+
194
+		return FilesystemContract::VISIBILITY_PRIVATE;
195
+	}
196
+
197
+	/**
198
+	 * Set the visibility for the given path.
199
+	 *
200
+	 * @param  string  $path
201
+	 * @param  string  $visibility
202
+	 * @return void
203
+	 */
204
+	public function setVisibility($path, $visibility)
205
+	{
206
+		return $this->driver->setVisibility($path, $this->parseVisibility($visibility));
207
+	}
208
+
209
+	/**
210
+	 * Prepend to a file.
211
+	 *
212
+	 * @param  string  $path
213
+	 * @param  string  $data
214
+	 * @param  string  $separator
215
+	 * @return int
216
+	 */
217
+	public function prepend($path, $data, $separator = PHP_EOL)
218
+	{
219
+		if ($this->exists($path)) {
220
+			return $this->put($path, $data.$separator.$this->get($path));
221
+		}
222
+
223
+		return $this->put($path, $data);
224
+	}
225
+
226
+	/**
227
+	 * Append to a file.
228
+	 *
229
+	 * @param  string  $path
230
+	 * @param  string  $data
231
+	 * @param  string  $separator
232
+	 * @return int
233
+	 */
234
+	public function append($path, $data, $separator = PHP_EOL)
235
+	{
236
+		if ($this->exists($path)) {
237
+			return $this->put($path, $this->get($path).$separator.$data);
238
+		}
239
+
240
+		return $this->put($path, $data);
241
+	}
242
+
243
+	/**
244
+	 * Delete the file at a given path.
245
+	 *
246
+	 * @param  string|array  $paths
247
+	 * @return bool
248
+	 */
249
+	public function delete($paths)
250
+	{
251
+		$paths = is_array($paths) ? $paths : func_get_args();
252
+
253
+		$success = true;
254
+
255
+		foreach ($paths as $path) {
256
+			try {
257
+				if (! $this->driver->delete($path)) {
258
+					$success = false;
259
+				}
260
+			} catch (FileNotFoundException $e) {
261
+				$success = false;
262
+			}
263
+		}
264
+
265
+		return $success;
266
+	}
267
+
268
+	/**
269
+	 * Copy a file to a new location.
270
+	 *
271
+	 * @param  string  $from
272
+	 * @param  string  $to
273
+	 * @return bool
274
+	 */
275
+	public function copy($from, $to)
276
+	{
277
+		return $this->driver->copy($from, $to);
278
+	}
279
+
280
+	/**
281
+	 * Move a file to a new location.
282
+	 *
283
+	 * @param  string  $from
284
+	 * @param  string  $to
285
+	 * @return bool
286
+	 */
287
+	public function move($from, $to)
288
+	{
289
+		return $this->driver->rename($from, $to);
290
+	}
291
+
292
+	/**
293
+	 * Get the file size of a given file.
294
+	 *
295
+	 * @param  string  $path
296
+	 * @return int
297
+	 */
298
+	public function size($path)
299
+	{
300
+		return $this->driver->getSize($path);
301
+	}
302
+
303
+	/**
304
+	 * Get the mime-type of a given file.
305
+	 *
306
+	 * @param  string  $path
307
+	 * @return string|false
308
+	 */
309
+	public function mimeType($path)
310
+	{
311
+		return $this->driver->getMimetype($path);
312
+	}
313
+
314
+	/**
315
+	 * Get the file's last modification time.
316
+	 *
317
+	 * @param  string  $path
318
+	 * @return int
319
+	 */
320
+	public function lastModified($path)
321
+	{
322
+		return $this->driver->getTimestamp($path);
323
+	}
324
+
325
+	/**
326
+	 * Get the URL for the file at the given path.
327
+	 *
328
+	 * @param  string  $path
329
+	 * @return string
330
+	 */
331
+	public function url($path)
332
+	{
333
+		$adapter = $this->driver->getAdapter();
334
+
335
+		if (method_exists($adapter, 'getUrl')) {
336
+			return $adapter->getUrl($path);
337
+		} elseif ($adapter instanceof AwsS3Adapter) {
338
+			return $this->getAwsUrl($adapter, $path);
339
+		} elseif ($adapter instanceof LocalAdapter) {
340
+			return $this->getLocalUrl($path);
341
+		} else {
342
+			throw new RuntimeException('This driver does not support retrieving URLs.');
343
+		}
344
+	}
345
+
346
+	/**
347
+	 * Get the URL for the file at the given path.
348
+	 *
349
+	 * @param  \League\Flysystem\AwsS3v3\AwsS3Adapter  $adapter
350
+	 * @param  string  $path
351
+	 * @return string
352
+	 */
353
+	protected function getAwsUrl($adapter, $path)
354
+	{
355
+		return $adapter->getClient()->getObjectUrl(
356
+			$adapter->getBucket(), $adapter->getPathPrefix().$path
357
+		);
358
+	}
359
+
360
+	/**
361
+	 * Get the URL for the file at the given path.
362
+	 *
363
+	 * @param  string  $path
364
+	 * @return string
365
+	 */
366
+	protected function getLocalUrl($path)
367
+	{
368
+		$config = $this->driver->getConfig();
369
+
370
+		// If an explicit base URL has been set on the disk configuration then we will use
371
+		// it as the base URL instead of the default path. This allows the developer to
372
+		// have full control over the base path for this filesystem's generated URLs.
373
+		if ($config->has('url')) {
374
+			return rtrim($config->get('url'), '/').'/'.ltrim($path, '/');
375
+		}
376
+
377
+		$path = '/storage/'.$path;
378
+
379
+		// If the path contains "storage/public", it probably means the developer is using
380
+		// the default disk to generate the path instead of the "public" disk like they
381
+		// are really supposed to use. We will remove the public from this path here.
382
+		if (Str::contains($path, '/storage/public/')) {
383
+			return Str::replaceFirst('/public/', '/', $path);
384
+		} else {
385
+			return $path;
386
+		}
387
+	}
388
+
389
+	/**
390
+	 * Get a temporary URL for the file at the given path.
391
+	 *
392
+	 * @param  string  $path
393
+	 * @param  \DateTimeInterface  $expiration
394
+	 * @param  array  $options
395
+	 * @return string
396
+	 */
397
+	public function temporaryUrl($path, $expiration, array $options = [])
398
+	{
399
+		$adapter = $this->driver->getAdapter();
400
+
401
+		if (method_exists($adapter, 'getTemporaryUrl')) {
402
+			return $adapter->getTemporaryUrl($path, $expiration, $options);
403
+		} elseif (! $adapter instanceof AwsS3Adapter) {
404
+			throw new RuntimeException('This driver does not support creating temporary URLs.');
405
+		}
406
+
407
+		$client = $adapter->getClient();
408
+
409
+		$command = $client->getCommand('GetObject', array_merge([
410
+			'Bucket' => $adapter->getBucket(),
411
+			'Key' => $adapter->getPathPrefix().$path,
412
+		], $options));
413
+
414
+		return (string) $client->createPresignedRequest(
415
+			$command, $expiration
416
+		)->getUri();
417
+	}
418
+
419
+	/**
420
+	 * Get an array of all files in a directory.
421
+	 *
422
+	 * @param  string|null  $directory
423
+	 * @param  bool  $recursive
424
+	 * @return array
425
+	 */
426
+	public function files($directory = null, $recursive = false)
427
+	{
428
+		$contents = $this->driver->listContents($directory, $recursive);
429
+
430
+		return $this->filterContentsByType($contents, 'file');
431
+	}
432
+
433
+	/**
434
+	 * Get all of the files from the given directory (recursive).
435
+	 *
436
+	 * @param  string|null  $directory
437
+	 * @return array
438
+	 */
439
+	public function allFiles($directory = null)
440
+	{
441
+		return $this->files($directory, true);
442
+	}
443
+
444
+	/**
445
+	 * Get all of the directories within a given directory.
446
+	 *
447
+	 * @param  string|null  $directory
448
+	 * @param  bool  $recursive
449
+	 * @return array
450
+	 */
451
+	public function directories($directory = null, $recursive = false)
452
+	{
453
+		$contents = $this->driver->listContents($directory, $recursive);
454
+
455
+		return $this->filterContentsByType($contents, 'dir');
456
+	}
457
+
458
+	/**
459
+	 * Get all (recursive) of the directories within a given directory.
460
+	 *
461
+	 * @param  string|null  $directory
462
+	 * @return array
463
+	 */
464
+	public function allDirectories($directory = null)
465
+	{
466
+		return $this->directories($directory, true);
467
+	}
468
+
469
+	/**
470
+	 * Create a directory.
471
+	 *
472
+	 * @param  string  $path
473
+	 * @return bool
474
+	 */
475
+	public function makeDirectory($path)
476
+	{
477
+		return $this->driver->createDir($path);
478
+	}
479
+
480
+	/**
481
+	 * Recursively delete a directory.
482
+	 *
483
+	 * @param  string  $directory
484
+	 * @return bool
485
+	 */
486
+	public function deleteDirectory($directory)
487
+	{
488
+		return $this->driver->deleteDir($directory);
489
+	}
490
+
491
+	/**
492
+	 * Get the Flysystem driver.
493
+	 *
494
+	 * @return \League\Flysystem\FilesystemInterface
495
+	 */
496
+	public function getDriver()
497
+	{
498
+		return $this->driver;
499
+	}
500
+
501
+	/**
502
+	 * Filter directory contents by type.
503
+	 *
504
+	 * @param  array  $contents
505
+	 * @param  string  $type
506
+	 * @return array
507
+	 */
508
+	protected function filterContentsByType($contents, $type)
509
+	{
510
+		return Collection::make($contents)
511
+			->where('type', $type)
512
+			->pluck('path')
513
+			->values()
514
+			->all();
515
+	}
516
+
517
+	/**
518
+	 * Parse the given visibility value.
519
+	 *
520
+	 * @param  string|null  $visibility
521
+	 * @return string|null
522
+	 *
523
+	 * @throws \InvalidArgumentException
524
+	 */
525
+	protected function parseVisibility($visibility)
526
+	{
527
+		if (is_null($visibility)) {
528
+			return;
529
+		}
530
+
531
+		switch ($visibility) {
532
+			case FilesystemContract::VISIBILITY_PUBLIC:
533
+				return AdapterInterface::VISIBILITY_PUBLIC;
534
+			case FilesystemContract::VISIBILITY_PRIVATE:
535
+				return AdapterInterface::VISIBILITY_PRIVATE;
536
+		}
537
+
538
+		throw new InvalidArgumentException('Unknown visibility: '.$visibility);
539
+	}
540
+
541
+	/**
542
+	 * Pass dynamic methods call onto Flysystem.
543
+	 *
544
+	 * @param  string  $method
545
+	 * @param  array  $parameters
546
+	 * @return mixed
547
+	 *
548
+	 * @throws \BadMethodCallException
549
+	 */
550
+	public function __call($method, array $parameters)
551
+	{
552
+		return call_user_func_array([$this->driver, $method], $parameters);
553
+	}
554 554
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/filesystem/FilesystemManager.php 1 patch
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -27,325 +27,325 @@
 block discarded – undo
27 27
  */
28 28
 class FilesystemManager implements FactoryContract
29 29
 {
30
-    /**
31
-     * The application instance.
32
-     *
33
-     * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Foundation\Application
34
-     */
35
-    protected $app;
36
-
37
-    /**
38
-     * The array of resolved filesystem drivers.
39
-     *
40
-     * @var array
41
-     */
42
-    protected $disks = [];
43
-
44
-    /**
45
-     * The registered custom driver creators.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $customCreators = [];
50
-
51
-    /**
52
-     * Create a new filesystem manager instance.
53
-     *
54
-     * @param  \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Foundation\Application  $app
55
-     * @return void
56
-     */
57
-    public function __construct($app)
58
-    {
59
-        $this->app = $app;
60
-    }
61
-
62
-    /**
63
-     * Get a filesystem instance.
64
-     *
65
-     * @param  string  $name
66
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
67
-     */
68
-    public function drive($name = null)
69
-    {
70
-        return $this->disk($name);
71
-    }
72
-
73
-    /**
74
-     * Get a filesystem instance.
75
-     *
76
-     * @param  string  $name
77
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
78
-     */
79
-    public function disk($name = null)
80
-    {
81
-        $name = $name ?: $this->getDefaultDriver();
82
-
83
-        return $this->disks[$name] = $this->get($name);
84
-    }
85
-
86
-    /**
87
-     * Get a default cloud filesystem instance.
88
-     *
89
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
90
-     */
91
-    public function cloud()
92
-    {
93
-        $name = $this->getDefaultCloudDriver();
94
-
95
-        return $this->disks[$name] = $this->get($name);
96
-    }
97
-
98
-    /**
99
-     * Attempt to get the disk from the local cache.
100
-     *
101
-     * @param  string  $name
102
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
103
-     */
104
-    protected function get($name)
105
-    {
106
-        return isset($this->disks[$name]) ? $this->disks[$name] : $this->resolve($name);
107
-    }
108
-
109
-    /**
110
-     * Resolve the given disk.
111
-     *
112
-     * @param  string  $name
113
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
114
-     *
115
-     * @throws \InvalidArgumentException
116
-     */
117
-    protected function resolve($name)
118
-    {
119
-        $config = $this->getConfig($name);
120
-
121
-        if (isset($this->customCreators[$config['driver']])) {
122
-            return $this->callCustomCreator($config);
123
-        }
124
-
125
-        $driverMethod = 'create'.ucfirst($config['driver']).'Driver';
126
-
127
-        if (method_exists($this, $driverMethod)) {
128
-            return $this->{$driverMethod}($config);
129
-        } else {
130
-            throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported.");
131
-        }
132
-    }
133
-
134
-    /**
135
-     * Call a custom driver creator.
136
-     *
137
-     * @param  array  $config
138
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
139
-     */
140
-    protected function callCustomCreator(array $config)
141
-    {
142
-        $driver = $this->customCreators[$config['driver']]($this->app, $config);
143
-
144
-        if ($driver instanceof FilesystemInterface) {
145
-            return $this->adapt($driver);
146
-        }
147
-
148
-        return $driver;
149
-    }
150
-
151
-    /**
152
-     * Create an instance of the local driver.
153
-     *
154
-     * @param  array  $config
155
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
156
-     */
157
-    public function createLocalDriver(array $config)
158
-    {
159
-        $permissions = isset($config['permissions']) ? $config['permissions'] : [];
160
-
161
-        $links = Arr::get($config, 'links') === 'skip'
162
-            ? LocalAdapter::SKIP_LINKS
163
-            : LocalAdapter::DISALLOW_LINKS;
164
-
165
-        return $this->adapt($this->createFlysystem(new LocalAdapter(
166
-            $config['root'], LOCK_EX, $links, $permissions
167
-        ), $config));
168
-    }
169
-
170
-    /**
171
-     * Create an instance of the ftp driver.
172
-     *
173
-     * @param  array  $config
174
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
175
-     */
176
-    public function createFtpDriver(array $config)
177
-    {
178
-        $ftpConfig = Arr::only($config, [
179
-            'host', 'username', 'password', 'port', 'root', 'passive', 'ssl', 'timeout',
180
-        ]);
181
-
182
-        return $this->adapt($this->createFlysystem(
183
-            new FtpAdapter($ftpConfig), $config
184
-        ));
185
-    }
186
-
187
-    /**
188
-     * Create an instance of the Amazon S3 driver.
189
-     *
190
-     * @param  array  $config
191
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Cloud
192
-     */
193
-    public function createS3Driver(array $config)
194
-    {
195
-        $s3Config = $this->formatS3Config($config);
196
-
197
-        $root = isset($s3Config['root']) ? $s3Config['root'] : null;
198
-
199
-        $options = isset($config['options']) ? $config['options'] : [];
200
-
201
-        return $this->adapt($this->createFlysystem(
202
-            new S3Adapter(new S3Client($s3Config), $s3Config['bucket'], $root, $options), $config
203
-        ));
204
-    }
205
-
206
-    /**
207
-     * Format the given S3 configuration with the default options.
208
-     *
209
-     * @param  array  $config
210
-     * @return array
211
-     */
212
-    protected function formatS3Config(array $config)
213
-    {
214
-        $config += ['version' => 'latest'];
215
-
216
-        if ($config['key'] && $config['secret']) {
217
-            $config['credentials'] = Arr::only($config, ['key', 'secret']);
218
-        }
219
-
220
-        return $config;
221
-    }
222
-
223
-    /**
224
-     * Create an instance of the Rackspace driver.
225
-     *
226
-     * @param  array  $config
227
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Cloud
228
-     */
229
-    public function createRackspaceDriver(array $config)
230
-    {
231
-        $client = new Rackspace($config['endpoint'], [
232
-            'username' => $config['username'], 'apiKey' => $config['key'],
233
-        ]);
234
-
235
-        $root = isset($config['root']) ? $config['root'] : null;
236
-
237
-        return $this->adapt($this->createFlysystem(
238
-            new RackspaceAdapter($this->getRackspaceContainer($client, $config), $root), $config
239
-        ));
240
-    }
241
-
242
-    /**
243
-     * Get the Rackspace Cloud Files container.
244
-     *
245
-     * @param  \OpenCloud\Rackspace  $client
246
-     * @param  array  $config
247
-     * @return \OpenCloud\ObjectStore\Resource\Container
248
-     */
249
-    protected function getRackspaceContainer(Rackspace $client, array $config)
250
-    {
251
-        $urlType = Arr::get($config, 'url_type');
252
-
253
-        $store = $client->objectStoreService('cloudFiles', $config['region'], $urlType);
254
-
255
-        return $store->getContainer($config['container']);
256
-    }
257
-
258
-    /**
259
-     * Create a Flysystem instance with the given adapter.
260
-     *
261
-     * @param  \League\Flysystem\AdapterInterface  $adapter
262
-     * @param  array  $config
263
-     * @return \League\Flysystem\FlysystemInterface
264
-     */
265
-    protected function createFlysystem(AdapterInterface $adapter, array $config)
266
-    {
267
-        $config = Arr::only($config, ['visibility', 'disable_asserts', 'url']);
268
-
269
-        return new Flysystem($adapter, count($config) > 0 ? $config : null);
270
-    }
271
-
272
-    /**
273
-     * Adapt the filesystem implementation.
274
-     *
275
-     * @param  \League\Flysystem\FilesystemInterface  $filesystem
276
-     * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
277
-     */
278
-    protected function adapt(FilesystemInterface $filesystem)
279
-    {
280
-        return new FilesystemAdapter($filesystem);
281
-    }
282
-
283
-    /**
284
-     * Set the given disk instance.
285
-     *
286
-     * @param  string  $name
287
-     * @param  mixed  $disk
288
-     * @return void
289
-     */
290
-    public function set($name, $disk)
291
-    {
292
-        $this->disks[$name] = $disk;
293
-    }
294
-
295
-    /**
296
-     * Get the filesystem connection configuration.
297
-     *
298
-     * @param  string  $name
299
-     * @return array
300
-     */
301
-    protected function getConfig($name)
302
-    {
303
-        return $this->app['config']["filesystems.disks.{$name}"];
304
-    }
305
-
306
-    /**
307
-     * Get the default driver name.
308
-     *
309
-     * @return string
310
-     */
311
-    public function getDefaultDriver()
312
-    {
313
-        return $this->app['config']['filesystems.default'];
314
-    }
315
-
316
-    /**
317
-     * Get the default cloud driver name.
318
-     *
319
-     * @return string
320
-     */
321
-    public function getDefaultCloudDriver()
322
-    {
323
-        return $this->app['config']['filesystems.cloud'];
324
-    }
325
-
326
-    /**
327
-     * Register a custom driver creator Closure.
328
-     *
329
-     * @param  string    $driver
330
-     * @param  \Closure  $callback
331
-     * @return $this
332
-     */
333
-    public function extend($driver, Closure $callback)
334
-    {
335
-        $this->customCreators[$driver] = $callback;
336
-
337
-        return $this;
338
-    }
339
-
340
-    /**
341
-     * Dynamically call the default driver instance.
342
-     *
343
-     * @param  string  $method
344
-     * @param  array   $parameters
345
-     * @return mixed
346
-     */
347
-    public function __call($method, $parameters)
348
-    {
349
-        return $this->disk()->$method(...$parameters);
350
-    }
30
+	/**
31
+	 * The application instance.
32
+	 *
33
+	 * @var \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Foundation\Application
34
+	 */
35
+	protected $app;
36
+
37
+	/**
38
+	 * The array of resolved filesystem drivers.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected $disks = [];
43
+
44
+	/**
45
+	 * The registered custom driver creators.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $customCreators = [];
50
+
51
+	/**
52
+	 * Create a new filesystem manager instance.
53
+	 *
54
+	 * @param  \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Foundation\Application  $app
55
+	 * @return void
56
+	 */
57
+	public function __construct($app)
58
+	{
59
+		$this->app = $app;
60
+	}
61
+
62
+	/**
63
+	 * Get a filesystem instance.
64
+	 *
65
+	 * @param  string  $name
66
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
67
+	 */
68
+	public function drive($name = null)
69
+	{
70
+		return $this->disk($name);
71
+	}
72
+
73
+	/**
74
+	 * Get a filesystem instance.
75
+	 *
76
+	 * @param  string  $name
77
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
78
+	 */
79
+	public function disk($name = null)
80
+	{
81
+		$name = $name ?: $this->getDefaultDriver();
82
+
83
+		return $this->disks[$name] = $this->get($name);
84
+	}
85
+
86
+	/**
87
+	 * Get a default cloud filesystem instance.
88
+	 *
89
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
90
+	 */
91
+	public function cloud()
92
+	{
93
+		$name = $this->getDefaultCloudDriver();
94
+
95
+		return $this->disks[$name] = $this->get($name);
96
+	}
97
+
98
+	/**
99
+	 * Attempt to get the disk from the local cache.
100
+	 *
101
+	 * @param  string  $name
102
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
103
+	 */
104
+	protected function get($name)
105
+	{
106
+		return isset($this->disks[$name]) ? $this->disks[$name] : $this->resolve($name);
107
+	}
108
+
109
+	/**
110
+	 * Resolve the given disk.
111
+	 *
112
+	 * @param  string  $name
113
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
114
+	 *
115
+	 * @throws \InvalidArgumentException
116
+	 */
117
+	protected function resolve($name)
118
+	{
119
+		$config = $this->getConfig($name);
120
+
121
+		if (isset($this->customCreators[$config['driver']])) {
122
+			return $this->callCustomCreator($config);
123
+		}
124
+
125
+		$driverMethod = 'create'.ucfirst($config['driver']).'Driver';
126
+
127
+		if (method_exists($this, $driverMethod)) {
128
+			return $this->{$driverMethod}($config);
129
+		} else {
130
+			throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported.");
131
+		}
132
+	}
133
+
134
+	/**
135
+	 * Call a custom driver creator.
136
+	 *
137
+	 * @param  array  $config
138
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
139
+	 */
140
+	protected function callCustomCreator(array $config)
141
+	{
142
+		$driver = $this->customCreators[$config['driver']]($this->app, $config);
143
+
144
+		if ($driver instanceof FilesystemInterface) {
145
+			return $this->adapt($driver);
146
+		}
147
+
148
+		return $driver;
149
+	}
150
+
151
+	/**
152
+	 * Create an instance of the local driver.
153
+	 *
154
+	 * @param  array  $config
155
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
156
+	 */
157
+	public function createLocalDriver(array $config)
158
+	{
159
+		$permissions = isset($config['permissions']) ? $config['permissions'] : [];
160
+
161
+		$links = Arr::get($config, 'links') === 'skip'
162
+			? LocalAdapter::SKIP_LINKS
163
+			: LocalAdapter::DISALLOW_LINKS;
164
+
165
+		return $this->adapt($this->createFlysystem(new LocalAdapter(
166
+			$config['root'], LOCK_EX, $links, $permissions
167
+		), $config));
168
+	}
169
+
170
+	/**
171
+	 * Create an instance of the ftp driver.
172
+	 *
173
+	 * @param  array  $config
174
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
175
+	 */
176
+	public function createFtpDriver(array $config)
177
+	{
178
+		$ftpConfig = Arr::only($config, [
179
+			'host', 'username', 'password', 'port', 'root', 'passive', 'ssl', 'timeout',
180
+		]);
181
+
182
+		return $this->adapt($this->createFlysystem(
183
+			new FtpAdapter($ftpConfig), $config
184
+		));
185
+	}
186
+
187
+	/**
188
+	 * Create an instance of the Amazon S3 driver.
189
+	 *
190
+	 * @param  array  $config
191
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Cloud
192
+	 */
193
+	public function createS3Driver(array $config)
194
+	{
195
+		$s3Config = $this->formatS3Config($config);
196
+
197
+		$root = isset($s3Config['root']) ? $s3Config['root'] : null;
198
+
199
+		$options = isset($config['options']) ? $config['options'] : [];
200
+
201
+		return $this->adapt($this->createFlysystem(
202
+			new S3Adapter(new S3Client($s3Config), $s3Config['bucket'], $root, $options), $config
203
+		));
204
+	}
205
+
206
+	/**
207
+	 * Format the given S3 configuration with the default options.
208
+	 *
209
+	 * @param  array  $config
210
+	 * @return array
211
+	 */
212
+	protected function formatS3Config(array $config)
213
+	{
214
+		$config += ['version' => 'latest'];
215
+
216
+		if ($config['key'] && $config['secret']) {
217
+			$config['credentials'] = Arr::only($config, ['key', 'secret']);
218
+		}
219
+
220
+		return $config;
221
+	}
222
+
223
+	/**
224
+	 * Create an instance of the Rackspace driver.
225
+	 *
226
+	 * @param  array  $config
227
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Cloud
228
+	 */
229
+	public function createRackspaceDriver(array $config)
230
+	{
231
+		$client = new Rackspace($config['endpoint'], [
232
+			'username' => $config['username'], 'apiKey' => $config['key'],
233
+		]);
234
+
235
+		$root = isset($config['root']) ? $config['root'] : null;
236
+
237
+		return $this->adapt($this->createFlysystem(
238
+			new RackspaceAdapter($this->getRackspaceContainer($client, $config), $root), $config
239
+		));
240
+	}
241
+
242
+	/**
243
+	 * Get the Rackspace Cloud Files container.
244
+	 *
245
+	 * @param  \OpenCloud\Rackspace  $client
246
+	 * @param  array  $config
247
+	 * @return \OpenCloud\ObjectStore\Resource\Container
248
+	 */
249
+	protected function getRackspaceContainer(Rackspace $client, array $config)
250
+	{
251
+		$urlType = Arr::get($config, 'url_type');
252
+
253
+		$store = $client->objectStoreService('cloudFiles', $config['region'], $urlType);
254
+
255
+		return $store->getContainer($config['container']);
256
+	}
257
+
258
+	/**
259
+	 * Create a Flysystem instance with the given adapter.
260
+	 *
261
+	 * @param  \League\Flysystem\AdapterInterface  $adapter
262
+	 * @param  array  $config
263
+	 * @return \League\Flysystem\FlysystemInterface
264
+	 */
265
+	protected function createFlysystem(AdapterInterface $adapter, array $config)
266
+	{
267
+		$config = Arr::only($config, ['visibility', 'disable_asserts', 'url']);
268
+
269
+		return new Flysystem($adapter, count($config) > 0 ? $config : null);
270
+	}
271
+
272
+	/**
273
+	 * Adapt the filesystem implementation.
274
+	 *
275
+	 * @param  \League\Flysystem\FilesystemInterface  $filesystem
276
+	 * @return \GravityKit\GravityView\Foundation\ThirdParty\Illuminate\Contracts\Filesystem\Filesystem
277
+	 */
278
+	protected function adapt(FilesystemInterface $filesystem)
279
+	{
280
+		return new FilesystemAdapter($filesystem);
281
+	}
282
+
283
+	/**
284
+	 * Set the given disk instance.
285
+	 *
286
+	 * @param  string  $name
287
+	 * @param  mixed  $disk
288
+	 * @return void
289
+	 */
290
+	public function set($name, $disk)
291
+	{
292
+		$this->disks[$name] = $disk;
293
+	}
294
+
295
+	/**
296
+	 * Get the filesystem connection configuration.
297
+	 *
298
+	 * @param  string  $name
299
+	 * @return array
300
+	 */
301
+	protected function getConfig($name)
302
+	{
303
+		return $this->app['config']["filesystems.disks.{$name}"];
304
+	}
305
+
306
+	/**
307
+	 * Get the default driver name.
308
+	 *
309
+	 * @return string
310
+	 */
311
+	public function getDefaultDriver()
312
+	{
313
+		return $this->app['config']['filesystems.default'];
314
+	}
315
+
316
+	/**
317
+	 * Get the default cloud driver name.
318
+	 *
319
+	 * @return string
320
+	 */
321
+	public function getDefaultCloudDriver()
322
+	{
323
+		return $this->app['config']['filesystems.cloud'];
324
+	}
325
+
326
+	/**
327
+	 * Register a custom driver creator Closure.
328
+	 *
329
+	 * @param  string    $driver
330
+	 * @param  \Closure  $callback
331
+	 * @return $this
332
+	 */
333
+	public function extend($driver, Closure $callback)
334
+	{
335
+		$this->customCreators[$driver] = $callback;
336
+
337
+		return $this;
338
+	}
339
+
340
+	/**
341
+	 * Dynamically call the default driver instance.
342
+	 *
343
+	 * @param  string  $method
344
+	 * @param  array   $parameters
345
+	 * @return mixed
346
+	 */
347
+	public function __call($method, $parameters)
348
+	{
349
+		return $this->disk()->$method(...$parameters);
350
+	}
351 351
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/filesystem/Filesystem.php 1 patch
Indentation   +557 added lines, -557 removed lines patch added patch discarded remove patch
@@ -16,561 +16,561 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/container/Container.php 1 patch
Indentation   +1207 added lines, -1207 removed lines patch added patch discarded remove patch
@@ -18,1211 +18,1211 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/container/ContextualBindingBuilder.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -12,63 +12,63 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/container/BoundMethod.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -15,164 +15,164 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/contracts/Logging/Log.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -4,95 +4,95 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/contracts/Session/Session.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -10,162 +10,162 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
vendor_prefixed/illuminate/contracts/Queue/Monitor.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -4,27 +4,27 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.