1 | <?php |
||
16 | class LaravelModulesServiceProvider extends ServiceProvider |
||
17 | { |
||
18 | /** |
||
19 | * Indicates if loading of the provider is deferred. |
||
20 | * |
||
21 | * @var bool |
||
22 | */ |
||
23 | protected $defer = false; |
||
24 | |||
25 | /** |
||
26 | * Booting the package. |
||
27 | */ |
||
28 | 42 | public function boot() |
|
34 | |||
35 | /** |
||
36 | * Register all modules. |
||
37 | */ |
||
38 | 42 | protected function registerModules() |
|
42 | |||
43 | /** |
||
44 | * Register the service provider. |
||
45 | */ |
||
46 | 42 | public function register() |
|
52 | |||
53 | /** |
||
54 | * Setup stub path. |
||
55 | */ |
||
56 | 42 | public function setupStubPath() |
|
57 | { |
||
58 | $this->app->booted(function ($app) { |
||
59 | 42 | Stub::setBasePath(__DIR__.'/Commands/stubs'); |
|
60 | |||
61 | 42 | if ($app['modules']->config('stubs.enabled') === true) { |
|
62 | Stub::setBasePath($app['modules']->config('stubs.path')); |
||
63 | } |
||
64 | 42 | }); |
|
65 | 42 | } |
|
66 | |||
67 | /** |
||
68 | * Register package's namespaces. |
||
69 | */ |
||
70 | 42 | protected function registerNamespaces() |
|
78 | |||
79 | /** |
||
80 | * Register laravel html package. |
||
81 | */ |
||
82 | protected function registerHtml() |
||
83 | { |
||
84 | $this->app->register(HtmlServiceProvider::class); |
||
85 | |||
86 | $aliases = [ |
||
87 | 'HTML' => HtmlFacade::class, |
||
88 | 'Form' => FormFacade::class, |
||
89 | 'Module' => Module::class, |
||
90 | ]; |
||
91 | |||
92 | AliasLoader::getInstance($aliases)->register(); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Register the service provider. |
||
97 | */ |
||
98 | protected function registerServices() |
||
106 | |||
107 | /** |
||
108 | * Get the services provided by the provider. |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | public function provides() |
||
113 | { |
||
114 | return ['modules']; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Register providers. |
||
119 | */ |
||
120 | 42 | protected function registerProviders() |
|
125 | } |
||
126 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: