|
2 | 2 |
|
3 | 3 | namespace Nwidart\Modules; |
4 | 4 |
|
5 | | -use Exception; |
6 | 5 | use Illuminate\Filesystem\Filesystem; |
7 | 6 | use Illuminate\Support\Collection; |
8 | 7 | use Nwidart\Modules\Contracts\ActivatorInterface; |
@@ -50,91 +49,28 @@ public function __construct(Filesystem $files, array $paths, string $manifestPat |
50 | 49 | $this->activator = $activator; |
51 | 50 | } |
52 | 51 |
|
53 | | - /** |
54 | | - * Get all of the service provider class names for all packages. |
55 | | - */ |
56 | | - public function providers(): array |
57 | | - { |
58 | | - return $this->config('providers'); |
59 | | - } |
60 | | - |
61 | | - /** |
62 | | - * Get all of the service provider class names for all packages. |
63 | | - */ |
64 | | - public function providersArray(): array |
65 | | - { |
66 | | - return $this->getManifest()['providers'] ?? []; |
67 | | - } |
68 | | - |
69 | | - /** |
70 | | - * Get all of the aliases for all packages. |
71 | | - */ |
72 | | - public function aliases(): array |
73 | | - { |
74 | | - return $this->config('aliases'); |
75 | | - } |
76 | | - |
77 | | - /** |
78 | | - * Get all of the values for all packages for the given configuration name. |
79 | | - */ |
80 | | - public function config(string $key): array |
81 | | - { |
82 | | - return collect($this->getManifest())->flatMap(function ($configuration) use ($key) { |
83 | | - return (array) ($configuration[$key] ?? []); |
84 | | - })->filter()->all(); |
85 | | - } |
86 | | - |
87 | 52 | /** |
88 | 53 | * Get the current package manifest. |
89 | 54 | */ |
90 | | - protected function getManifest(): array |
| 55 | + public function getProviders(): array |
91 | 56 | { |
92 | 57 | if (! is_null($this->manifest)) { |
93 | 58 | return $this->manifest; |
94 | 59 | } |
95 | 60 |
|
96 | | - if (! is_file($this->manifestPath)) { |
97 | | - $this->build(); |
98 | | - } |
99 | | - |
100 | | - return $this->manifest = is_file($this->manifestPath) ? |
101 | | - $this->files->getRequire($this->manifestPath) : []; |
| 61 | + return $this->manifest = $this->build(); |
102 | 62 | } |
103 | 63 |
|
104 | 64 | /** |
105 | 65 | * Build the manifest and write it to disk. |
106 | 66 | */ |
107 | | - public function build(): void |
| 67 | + public function build(): array |
108 | 68 | { |
109 | | - $providers = $this->getModulesData() |
| 69 | + return $this->getModulesData() |
110 | 70 | ->pluck('providers') |
111 | 71 | ->flatten() |
112 | 72 | ->filter() |
113 | 73 | ->toArray(); |
114 | | - |
115 | | - $this->write( |
116 | | - [ |
117 | | - 'providers' => $providers, |
118 | | - 'eager' => $providers, |
119 | | - 'deferred' => [], |
120 | | - ] |
121 | | - ); |
122 | | - } |
123 | | - |
124 | | - /** |
125 | | - * Write the given manifest array to disk. |
126 | | - * |
127 | | - * @throws \Exception |
128 | | - */ |
129 | | - protected function write(array $manifest): void |
130 | | - { |
131 | | - if (! is_writable($dirname = dirname($this->manifestPath))) { |
132 | | - throw new Exception("The {$dirname} directory must be present and writable."); |
133 | | - } |
134 | | - $this->files->replace( |
135 | | - $this->manifestPath, |
136 | | - '<?php return '.var_export($manifest, true).';' |
137 | | - ); |
138 | 74 | } |
139 | 75 |
|
140 | 76 | public function registerFiles(): void |
|
0 commit comments