|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SixtyEightPublishers\User\DI; |
|
6
|
|
|
|
|
7
|
|
|
use Kdyby; |
|
8
|
|
|
use Nette; |
|
9
|
|
|
use SixtyEightPublishers; |
|
10
|
|
|
|
|
11
|
|
|
final class UserExtension extends Nette\DI\CompilerExtension implements |
|
12
|
|
|
Kdyby\Doctrine\DI\IEntityProvider, |
|
13
|
|
|
Kdyby\Doctrine\DI\ITargetEntityProvider, |
|
14
|
|
|
Kdyby\Translation\DI\ITranslationProvider |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var array */ |
|
17
|
|
|
private $defaults = [ |
|
18
|
|
|
# 'common' is loaded in constructor |
|
19
|
|
|
# 'doctrine_identity' is loaded in constructor |
|
20
|
|
|
# 'forgot_password' is loaded in constructor |
|
21
|
|
|
# 'authentication' is loaded in constructor |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string[]|\SixtyEightPublishers\User\DI\IExtensionAdapter[] */ |
|
25
|
|
|
private $extensionAdapters = [ |
|
26
|
|
|
'common' => SixtyEightPublishers\User\Common\DI\CommonExtensionAdapter::class, |
|
27
|
|
|
'doctrine_identity' => SixtyEightPublishers\User\DoctrineIdentity\DI\DoctrineIdentityExtensionAdapter::class, |
|
28
|
|
|
'forgot_password' => SixtyEightPublishers\User\ForgotPassword\DI\ForgotPasswordExtensionAdapter::class, |
|
29
|
|
|
'authentication' => SixtyEightPublishers\User\Authentication\DI\AuthenticationExtensionAdapter::class, |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** @var bool */ |
|
33
|
|
|
private $extensionAdaptersBuilded = FALSE; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->defaults = array_merge($this->defaults, [ |
|
38
|
|
|
'common' => SixtyEightPublishers\User\Common\DI\CommonExtensionAdapter::getDefaults(), |
|
39
|
|
|
'doctrine_identity' => SixtyEightPublishers\User\DoctrineIdentity\DI\DoctrineIdentityExtensionAdapter::getDefaults(), |
|
40
|
|
|
'forgot_password' => SixtyEightPublishers\User\ForgotPassword\DI\ForgotPasswordExtensionAdapter::getDefaults(), |
|
41
|
|
|
'authentication' => SixtyEightPublishers\User\Authentication\DI\AuthenticationExtensionAdapter::getDefaults(), |
|
42
|
|
|
]); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
|
|
public function loadConfiguration(): void |
|
49
|
|
|
{ |
|
50
|
|
|
foreach ($this->getExtensionAdapters() as $extensionAdapter) { |
|
51
|
|
|
$extensionAdapter->loadConfiguration(); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function beforeCompile(): void |
|
59
|
|
|
{ |
|
60
|
|
|
foreach ($this->getExtensionAdapters() as $extensionAdapter) { |
|
61
|
|
|
$extensionAdapter->beforeCompile(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
|
|
public function afterCompile(Nette\PhpGenerator\ClassType $class): void |
|
69
|
|
|
{ |
|
70
|
|
|
foreach ($this->getExtensionAdapters() as $extensionAdapter) { |
|
71
|
|
|
$extensionAdapter->afterCompile($class); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param array $config |
|
77
|
|
|
*/ |
|
78
|
|
|
private function buildExtensionAdapters(array $config): void |
|
79
|
|
|
{ |
|
80
|
|
|
$extensionAdapterFactory = new ExtensionAdapterFactory($this->getContainerBuilder(), new \ArrayObject()); |
|
81
|
|
|
|
|
82
|
|
|
foreach ($this->extensionAdapters as $name => $className) { |
|
83
|
|
|
$this->extensionAdapters[$name] = $extensionAdapterFactory->create( |
|
84
|
|
|
$className, |
|
|
|
|
|
|
85
|
|
|
$this->prefix($name), |
|
86
|
|
|
$config[$name] |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return \SixtyEightPublishers\User\DI\IExtensionAdapter[] |
|
93
|
|
|
*/ |
|
94
|
|
|
private function getExtensionAdapters(): array |
|
95
|
|
|
{ |
|
96
|
|
|
if (FALSE === $this->extensionAdaptersBuilded) { |
|
97
|
|
|
/** @noinspection PhpInternalEntityUsedInspection */ |
|
98
|
|
|
$config = $this->validateConfig(Nette\DI\Helpers::expand($this->defaults, $this->getContainerBuilder()->parameters)); |
|
99
|
|
|
|
|
100
|
|
|
$this->buildExtensionAdapters($config); |
|
|
|
|
|
|
101
|
|
|
$this->extensionAdaptersBuilded = TRUE; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return $this->extensionAdapters; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/**************** interface \Kdyby\Doctrine\DI\IEntityProvider ****************/ |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* {@inheritdoc} |
|
111
|
|
|
*/ |
|
112
|
|
View Code Duplication |
public function getEntityMappings(): array |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
$map = array_values(array_map( |
|
115
|
|
|
function (Kdyby\Doctrine\DI\IEntityProvider $provider) { |
|
116
|
|
|
return $provider->getEntityMappings(); |
|
117
|
|
|
}, |
|
118
|
|
|
$this->getExtensionAdapters() |
|
119
|
|
|
)); |
|
120
|
|
|
|
|
121
|
|
|
return 0 < count($map) ? array_merge(...$map) : []; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/**************** interface \Kdyby\Doctrine\DI\ITargetEntityProvider ****************/ |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* {@inheritdoc} |
|
128
|
|
|
*/ |
|
129
|
|
View Code Duplication |
public function getTargetEntityMappings(): array |
|
|
|
|
|
|
130
|
|
|
{ |
|
131
|
|
|
$map = array_values(array_map( |
|
132
|
|
|
function (Kdyby\Doctrine\DI\ITargetEntityProvider $provider) { |
|
133
|
|
|
return $provider->getTargetEntityMappings(); |
|
134
|
|
|
}, |
|
135
|
|
|
$this->getExtensionAdapters() |
|
136
|
|
|
)); |
|
137
|
|
|
|
|
138
|
|
|
return 0 < count($map) ? array_merge(...$map) : []; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/**************** interface \Kdyby\Translation\DI\ITranslationProvider ****************/ |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* {@inheritdoc} |
|
145
|
|
|
*/ |
|
146
|
|
View Code Duplication |
public function getTranslationResources(): array |
|
|
|
|
|
|
147
|
|
|
{ |
|
148
|
|
|
$map = array_values(array_map( |
|
149
|
|
|
function (Kdyby\Translation\DI\ITranslationProvider $provider) { |
|
150
|
|
|
return $provider->getTranslationResources(); |
|
151
|
|
|
}, |
|
152
|
|
|
$this->getExtensionAdapters() |
|
153
|
|
|
)); |
|
154
|
|
|
|
|
155
|
|
|
return 0 < count($map) ? array_merge(...$map) : []; |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.