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
|
220 |
|
public function boot() |
15
|
|
|
{ |
16
|
220 |
|
$this->registerNamespaces(); |
17
|
220 |
|
$this->registerModules(); |
18
|
220 |
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Register the service provider. |
22
|
|
|
*/ |
23
|
220 |
|
public function register() |
24
|
|
|
{ |
25
|
220 |
|
$this->registerServices(); |
26
|
220 |
|
$this->setupStubPath(); |
27
|
220 |
|
$this->registerProviders(); |
28
|
220 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Setup stub path. |
32
|
|
|
*/ |
33
|
220 |
|
public function setupStubPath() |
34
|
|
|
{ |
35
|
220 |
|
Stub::setBasePath(__DIR__ . '/Commands/stubs'); |
36
|
|
|
|
37
|
|
|
$this->app->booted(function ($app) { |
38
|
|
|
/** @var RepositoryInterface $moduleRepository */ |
39
|
220 |
|
$moduleRepository = $app[RepositoryInterface::class]; |
40
|
220 |
|
if ($moduleRepository->config('stubs.enabled') === true) { |
41
|
|
|
Stub::setBasePath($moduleRepository->config('stubs.path')); |
|
|
|
|
42
|
|
|
} |
43
|
220 |
|
}); |
44
|
220 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
220 |
|
protected function registerServices() |
50
|
|
|
{ |
51
|
|
|
$this->app->singleton(Contracts\RepositoryInterface::class, function ($app) { |
52
|
|
|
$path = $app['config']->get('modules.paths.modules'); |
53
|
|
|
|
54
|
|
|
return new Laravel\LaravelFileRepository($app, $path); |
55
|
220 |
|
}); |
56
|
|
|
$this->app->singleton(Contracts\ActivatorInterface::class, function ($app) { |
57
|
196 |
|
$activator = $app['config']->get('modules.activator'); |
58
|
196 |
|
$class = $app['config']->get('modules.activators.' . $activator)['class']; |
59
|
|
|
|
60
|
196 |
|
if ($class === null) { |
61
|
1 |
|
throw InvalidActivatorClass::missingConfig(); |
62
|
|
|
} |
63
|
|
|
|
64
|
195 |
|
return new $class($app); |
65
|
220 |
|
}); |
66
|
220 |
|
$this->app->alias(Contracts\RepositoryInterface::class, 'modules'); |
67
|
220 |
|
} |
68
|
|
|
} |
69
|
|
|
|
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: