1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MichaelRubel\AutoBinder\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Cache\Repository; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Illuminate\Support\Collection; |
8
|
|
|
use InvalidArgumentException; |
9
|
|
|
use MichaelRubel\AutoBinder\AutoBinder; |
|
|
|
|
10
|
|
|
|
11
|
|
|
class AutoBinderClearCommand extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $signature = 'binder:clear {folder : Folder to clear the cache from}'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $description = 'Clear a cached bindings'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param Repository $cache |
25
|
|
|
* |
26
|
|
|
* @return void |
27
|
|
|
*/ |
28
|
2 |
|
public function handle(Repository $cache): void |
29
|
|
|
{ |
30
|
2 |
|
$this->getFolders()->each(function ($folder) use ($cache) { |
31
|
2 |
|
$clue = $this->getClueFor($folder); |
32
|
|
|
|
33
|
2 |
|
if (! $cache->has($clue)) { |
34
|
1 |
|
throw new InvalidArgumentException('Cached folder ' . $folder . ' not found.'); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
$this->flushContainerBindings($cache, $clue); |
38
|
|
|
|
39
|
1 |
|
$cache->forget($clue); |
40
|
2 |
|
}); |
41
|
|
|
|
42
|
1 |
|
$this->info('Container binding cache cleared successfully!'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Retrieves folders to flush from the command input. |
47
|
|
|
* |
48
|
|
|
* @return Collection<int, string> |
49
|
|
|
*/ |
50
|
2 |
|
private function getFolders(): Collection |
51
|
|
|
{ |
52
|
2 |
|
$folders = explode(',', $this->argument('folder')); |
53
|
|
|
|
54
|
2 |
|
return collect($folders); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Retrieves the cache clue for the specified folder. |
59
|
|
|
* |
60
|
|
|
* @param string $folder |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
2 |
|
private function getClueFor(string $folder): string |
65
|
|
|
{ |
66
|
2 |
|
return (new AutoBinder($folder))->cacheClue(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Cleans up the application container bindings. |
71
|
|
|
* |
72
|
|
|
* @param Repository $cache |
73
|
|
|
* @param string $clue |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
1 |
|
private function flushContainerBindings(Repository $cache, string $clue): void |
78
|
|
|
{ |
79
|
1 |
|
with($cache->get($clue), fn ($fromCache) => collect($fromCache)->each( |
80
|
1 |
|
fn ($concrete, $interface) => app()->offsetUnset($interface) |
81
|
1 |
|
)); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths