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 MichaelRubel\AutoBinder\AutoBinder; |
|
|
|
|
9
|
|
|
|
10
|
|
|
class AutoBinderClearCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $signature = 'binder:clear {folders : Folders to clear the cache from}'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $description = 'Clear a cached bindings'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param Repository $cache |
24
|
|
|
* @return int |
25
|
|
|
*/ |
26
|
2 |
|
public function handle(Repository $cache): int |
27
|
|
|
{ |
28
|
2 |
|
$this->getFolders()->each(function ($folder) use ($cache) { |
29
|
2 |
|
$clue = $this->getClueFor($folder); |
30
|
|
|
|
31
|
2 |
|
if (! $cache->has($clue)) { |
32
|
1 |
|
$this->components->info( |
33
|
1 |
|
'Cached folder ' . $folder . ' not found.' |
34
|
1 |
|
); |
35
|
|
|
|
36
|
1 |
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
$this->flushContainerBindings($cache, $clue); |
40
|
|
|
|
41
|
1 |
|
$cache->forget($clue); |
42
|
2 |
|
}); |
43
|
|
|
|
44
|
2 |
|
$this->components->info( |
45
|
2 |
|
'Container binding cache cleared successfully!' |
46
|
2 |
|
); |
47
|
|
|
|
48
|
2 |
|
return Command::SUCCESS; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Retrieves folders to flush from the command input. |
53
|
|
|
* |
54
|
|
|
* @return Collection<int, string> |
55
|
|
|
*/ |
56
|
2 |
|
private function getFolders(): Collection |
57
|
|
|
{ |
58
|
2 |
|
$folders = explode(',', $this->argument('folders')); |
59
|
|
|
|
60
|
2 |
|
return collect($folders); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Retrieves the cache clue for the specified folder. |
65
|
|
|
* |
66
|
|
|
* @param string $folder |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
2 |
|
private function getClueFor(string $folder): string |
70
|
|
|
{ |
71
|
2 |
|
return (new AutoBinder($folder))->cacheClue(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Cleans up the application container bindings. |
76
|
|
|
* |
77
|
|
|
* @param Repository $cache |
78
|
|
|
* @param string $clue |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
1 |
|
private function flushContainerBindings(Repository $cache, string $clue): void |
82
|
|
|
{ |
83
|
1 |
|
with($cache->get($clue), fn ($fromCache) => collect($fromCache)->each( |
84
|
1 |
|
fn ($concrete, $interface) => app()->offsetUnset($interface) |
85
|
1 |
|
)); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
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