1 | <?php |
||
9 | class Registrar |
||
10 | { |
||
11 | /** |
||
12 | * register files. |
||
13 | * |
||
14 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
15 | * @param array $addons |
||
16 | */ |
||
17 | 4 | public function register(Application $app, array $addons) |
|
18 | { |
||
19 | // prepare helper functions |
||
20 | 4 | foreach ($addons as $addon) { |
|
21 | 2 | $this->loadFiles($addon, $addon->config('addon.files', [])); |
|
22 | } |
||
23 | |||
24 | 4 | foreach ($addons as $addon) { |
|
25 | // load config |
||
26 | 2 | $this->loadConfigurationFiles($addon); |
|
27 | |||
28 | // regist service providers |
||
29 | 2 | $providers = $addon->config('addon.providers', []); |
|
30 | 2 | foreach ($providers as $provider) { |
|
31 | 1 | $app->register($provider); |
|
32 | } |
||
33 | |||
34 | // register commands |
||
35 | 2 | $commands = $addon->config('addon.commands', $addon->config('addon.console.commands', [])); |
|
36 | 2 | if (!is_array($commands)) $commands = [$commands]; |
|
37 | 2 | Artisan::starting(function ($artisan) use ($commands) { |
|
38 | $artisan->resolveCommands($commands); |
||
39 | 2 | }); |
|
40 | |||
41 | // register named middleware |
||
42 | 2 | $middlewares = $addon->config('addon.middleware', $addon->config('addon.http.route_middlewares', [])); |
|
43 | 2 | foreach ($middlewares as $name => $middleware) { |
|
44 | if (is_array($middleware)) { |
||
45 | $app['router']->middlewareGroup($name, $middleware); |
||
46 | } |
||
47 | else { |
||
48 | 2 | $app['router']->aliasMiddleware($name, $middleware); |
|
49 | } |
||
50 | } |
||
51 | } |
||
52 | 4 | } |
|
53 | |||
54 | /** |
||
55 | * load addon initial script files. |
||
56 | * |
||
57 | * @param \Jumilla\Addomnipot\Laravel\Addon $addon |
||
58 | * @param array $files |
||
59 | */ |
||
60 | 2 | protected function loadFiles(Addon $addon, array $files) |
|
75 | |||
76 | /** |
||
77 | * Load the configuration items from all of the files. |
||
78 | * |
||
79 | * @param \Jumilla\Addomnipot\Laravel\Addon $addon |
||
80 | */ |
||
81 | 2 | protected function loadConfigurationFiles(Addon $addon) |
|
89 | |||
90 | /** |
||
91 | * Get all of the configuration files for the directory. |
||
92 | * |
||
93 | * @param string $directoryPath |
||
94 | * |
||
95 | * @return array |
||
96 | */ |
||
97 | 2 | protected function getConfigurationFiles($directoryPath) |
|
110 | |||
111 | /** |
||
112 | * boot addon. |
||
113 | * |
||
114 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
115 | * @param array $addons |
||
116 | */ |
||
117 | 2 | public function boot(Application $app, array $addons) |
|
123 | |||
124 | /** |
||
125 | * Register the package's component namespaces. |
||
126 | * |
||
127 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
128 | * @param \Jumilla\Addomnipot\Laravel\Addon $addon |
||
129 | */ |
||
130 | 1 | protected function registerPackage(Application $app, Addon $addon) |
|
149 | } |
||
150 |