|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nwidart\Modules; |
|
4
|
|
|
|
|
5
|
|
|
use Nwidart\Modules\Contracts\RepositoryInterface; |
|
6
|
|
|
use Nwidart\Modules\Exceptions\InvalidActivatorClass; |
|
7
|
|
|
use Nwidart\Modules\Support\Stub; |
|
8
|
|
|
|
|
9
|
|
|
class LaravelModulesServiceProvider extends ModulesServiceProvider |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Booting the package. |
|
13
|
|
|
*/ |
|
14
|
228 |
|
public function boot() |
|
15
|
|
|
{ |
|
16
|
228 |
|
$this->registerNamespaces(); |
|
17
|
228 |
|
$this->registerModules(); |
|
18
|
228 |
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Register the service provider. |
|
22
|
|
|
*/ |
|
23
|
228 |
|
public function register() |
|
24
|
|
|
{ |
|
25
|
228 |
|
$this->registerServices(); |
|
26
|
228 |
|
$this->setupStubPath(); |
|
27
|
228 |
|
$this->registerProviders(); |
|
28
|
228 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Setup stub path. |
|
32
|
|
|
*/ |
|
33
|
228 |
|
public function setupStubPath() |
|
34
|
|
|
{ |
|
35
|
228 |
|
$path = $this->app['config']->get('modules.stubs.path') ?? __DIR__ . '/Commands/stubs'; |
|
36
|
228 |
|
Stub::setBasePath($path); |
|
37
|
|
|
|
|
38
|
|
|
$this->app->booted(function ($app) { |
|
39
|
|
|
/** @var RepositoryInterface $moduleRepository */ |
|
40
|
228 |
|
$moduleRepository = $app[RepositoryInterface::class]; |
|
41
|
228 |
|
if ($moduleRepository->config('stubs.enabled') === true) { |
|
42
|
|
|
Stub::setBasePath($moduleRepository->config('stubs.path')); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
228 |
|
}); |
|
45
|
228 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
228 |
|
protected function registerServices() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->app->singleton(Contracts\RepositoryInterface::class, function ($app) { |
|
53
|
|
|
$path = $app['config']->get('modules.paths.modules'); |
|
54
|
|
|
|
|
55
|
|
|
return new Laravel\LaravelFileRepository($app, $path); |
|
56
|
228 |
|
}); |
|
57
|
|
|
$this->app->singleton(Contracts\ActivatorInterface::class, function ($app) { |
|
58
|
203 |
|
$activator = $app['config']->get('modules.activator'); |
|
59
|
203 |
|
$class = $app['config']->get('modules.activators.' . $activator)['class']; |
|
60
|
|
|
|
|
61
|
203 |
|
if ($class === null) { |
|
62
|
1 |
|
throw InvalidActivatorClass::missingConfig(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
202 |
|
return new $class($app); |
|
66
|
228 |
|
}); |
|
67
|
228 |
|
$this->app->alias(Contracts\RepositoryInterface::class, 'modules'); |
|
68
|
228 |
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: