1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Container\ServiceProviders; |
4
|
|
|
|
5
|
|
|
use Nip\Config\Config; |
6
|
|
|
use Nip\Container\Container; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ServiceProviderAwareTrait |
10
|
|
|
* @package Nip\Container\ServiceProviders |
11
|
|
|
*/ |
12
|
|
|
trait ServiceProviderAwareTrait |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* All of the registered service providers. |
16
|
|
|
* |
17
|
|
|
* @var ProviderRepository |
18
|
|
|
*/ |
19
|
|
|
protected $providerRepository = null; |
20
|
|
|
|
21
|
|
|
public function registerConfiguredProviders() |
22
|
|
|
{ |
23
|
|
|
$providers = $this->getConfiguredProviders(); |
24
|
|
|
foreach ($providers as $provider) { |
25
|
|
|
$this->getProviderRepository()->add($provider); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return $this->getProviderRepository()->register(); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return ProviderRepository |
33
|
|
|
*/ |
34
|
|
|
public function getProviderRepository() |
35
|
|
|
{ |
36
|
|
|
if ($this->providerRepository === null) { |
37
|
|
|
$this->providerRepository = new ProviderRepository(); |
38
|
|
|
$this->providerRepository->setContainer($this->getContainer()); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return $this->providerRepository; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
2 |
|
public function getConfiguredProviders() |
48
|
|
|
{ |
49
|
2 |
|
return $this->getConfigProvidersValue($this->getGenericProviders()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param null $default |
|
|
|
|
54
|
|
|
* @return array|null |
55
|
|
|
* @throws \Exception |
56
|
|
|
*/ |
57
|
2 |
|
protected function getConfigProvidersValue($default = null) |
58
|
|
|
{ |
59
|
2 |
|
if (function_exists('config') === false) { |
60
|
|
|
return $default; |
61
|
|
|
} |
62
|
2 |
|
if (function_exists('app') === false && !(Container::getInstance() instanceof Container)) { |
|
|
|
|
63
|
|
|
return $default; |
64
|
|
|
} |
65
|
2 |
|
$container = function_exists('app') ? app() : Container::getInstance(); |
66
|
2 |
|
if ($container->has('config') == false) { |
|
|
|
|
67
|
1 |
|
return $default; |
68
|
|
|
} |
69
|
1 |
|
$value = config('app.providers'); |
70
|
1 |
|
if ($value instanceof Config) { |
71
|
1 |
|
$value = $value->toArray(); |
72
|
|
|
} |
73
|
1 |
|
if (empty($value)) { |
74
|
|
|
return $default; |
75
|
|
|
} |
76
|
1 |
|
return $value; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
|
|
public function getGenericProviders() |
83
|
|
|
{ |
84
|
|
|
return []; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function bootProviders() |
88
|
|
|
{ |
89
|
|
|
$this->getProviderRepository()->boot(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.