1 | <?php |
||
32 | class Bootstrap implements BootstrapInterface |
||
33 | { |
||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 10 | public function bootstrap($app) |
|
57 | |||
58 | /** |
||
59 | * Initialize container with module classes. |
||
60 | * |
||
61 | * @param \yii\base\Application $app |
||
62 | * @param array $map the previously built class map list |
||
63 | */ |
||
64 | 10 | protected function initContainer($app, $map) |
|
65 | { |
||
66 | 10 | $di = Yii::$container; |
|
67 | try { |
||
68 | // events |
||
69 | 10 | $di->set(Event\FormEvent::class); |
|
70 | 10 | $di->set(Event\ProfileEvent::class); |
|
71 | 10 | $di->set(Event\ResetPasswordEvent::class); |
|
72 | 10 | $di->set(Event\SocialNetworkAuthEvent::class); |
|
73 | 10 | $di->set(Event\SocialNetworkConnectEvent::class); |
|
74 | 10 | $di->set(Event\UserEvent::class); |
|
75 | |||
76 | // forms |
||
77 | 10 | $di->set(Form\LoginForm::class); |
|
78 | 10 | $di->set(Form\RecoveryForm::class); |
|
79 | 10 | $di->set(Form\RegistrationForm::class); |
|
80 | 10 | $di->set(Form\ResendForm::class); |
|
81 | 10 | $di->set(Form\SettingsForm::class); |
|
82 | |||
83 | // helpers |
||
84 | 10 | $di->set(Helper\AuthHelper::class); |
|
85 | 10 | $di->set(Helper\GravatarHelper::class); |
|
86 | 10 | $di->set(Helper\SecurityHelper::class); |
|
87 | 10 | $di->set(Helper\TimezoneHelper::class); |
|
88 | |||
89 | // services |
||
90 | 10 | $di->set(Service\AccountConfirmationService::class); |
|
91 | 10 | $di->set(Service\EmailChangeService::class); |
|
92 | 10 | $di->set(Service\PasswordRecoveryService::class); |
|
93 | 10 | $di->set(Service\ResendConfirmationService::class); |
|
94 | 10 | $di->set(Service\ResetPasswordService::class); |
|
95 | 10 | $di->set(Service\SocialNetworkAccountConnectService::class); |
|
96 | 10 | $di->set(Service\SocialNetworkAuthenticateService::class); |
|
97 | 10 | $di->set(Service\UserBlockService::class); |
|
98 | 10 | $di->set(Service\UserCreateService::class); |
|
99 | 10 | $di->set(Service\UserRegisterService::class); |
|
100 | 10 | $di->set(Service\UserConfirmationService::class); |
|
101 | 10 | $di->set(Service\AuthItemEditionService::class); |
|
102 | 10 | $di->set(Service\UpdateAuthAssignmentsService::class); |
|
103 | 10 | $di->set(Service\SwitchIdentityService::class); |
|
104 | |||
105 | // email change strategy |
||
106 | 10 | $di->set(Strategy\DefaultEmailChangeStrategy::class); |
|
107 | 10 | $di->set(Strategy\InsecureEmailChangeStrategy::class); |
|
108 | 10 | $di->set(Strategy\SecureEmailChangeStrategy::class); |
|
109 | |||
110 | // validators |
||
111 | 10 | $di->set(Validator\AjaxRequestModelValidator::class); |
|
112 | 10 | $di->set(TimeZoneValidator::class); |
|
113 | |||
114 | // class map models + query classes |
||
115 | 10 | $modelClassMap = []; |
|
116 | 10 | foreach ($map as $class => $definition) { |
|
117 | 10 | $di->set($class, $definition); |
|
118 | 10 | $model = is_array($definition) ? $definition['class'] : $definition; |
|
119 | 10 | $name = (substr($class, strrpos($class, '\\') + 1)); |
|
120 | 10 | $modelClassMap[$class] = $model; |
|
121 | 10 | if (in_array($name, ['User', 'Profile', 'Token', 'SocialNetworkAccount'])) { |
|
122 | 10 | $di->set( |
|
123 | 10 | "Da\\User\\Query\\{$name}Query", |
|
124 | 10 | function () use ($model) { |
|
125 | 10 | return $model::find(); |
|
126 | 10 | } |
|
127 | ); |
||
128 | } |
||
129 | } |
||
130 | 10 | $di->setSingleton(ClassMapHelper::class, ClassMapHelper::class, [$modelClassMap]); |
|
131 | |||
132 | // search classes |
||
133 | 10 | if (!$di->has(Search\UserSearch::class)) { |
|
134 | $di->set(Search\UserSearch::class, [$di->get(Query\UserQuery::class)]); |
||
135 | } |
||
136 | 10 | if (!$di->has(Search\PermissionSearch::class)) { |
|
137 | $di->set(Search\PermissionSearch::class); |
||
138 | } |
||
139 | 10 | if (!$di->has(Search\RoleSearch::class)) { |
|
140 | $di->set(Search\RoleSearch::class); |
||
141 | } |
||
142 | |||
143 | 10 | if ($app instanceof WebApplication) { |
|
144 | // override Yii |
||
145 | 10 | $di->set( |
|
146 | 10 | 'yii\web\User', |
|
147 | [ |
||
148 | 10 | 'enableAutoLogin' => true, |
|
149 | 'loginUrl' => ['/user/security/login'], |
||
150 | 10 | 'identityClass' => $di->get(ClassMapHelper::class)->get(User::class), |
|
151 | ] |
||
152 | ); |
||
153 | } |
||
154 | } catch (Exception $e) { |
||
155 | die($e); |
||
156 | } |
||
157 | 10 | } |
|
158 | |||
159 | /** |
||
160 | * Registers module translation messages. |
||
161 | * |
||
162 | * @param Application $app |
||
163 | */ |
||
164 | 10 | protected function initTranslations(Application $app) |
|
165 | { |
||
166 | 10 | if (!isset($app->get('i18n')->translations['usuario*'])) { |
|
167 | /** @var Module $module */ |
||
168 | $module = $app->getModule('user'); |
||
169 | |||
170 | $app->get('i18n')->translations['usuario*'] = $module->i18nTranslationConfig; |
||
171 | } |
||
172 | 10 | } |
|
173 | |||
174 | /** |
||
175 | * Ensures the auth manager is the one provided by the library. |
||
176 | * |
||
177 | * @param Application $app |
||
178 | */ |
||
179 | 10 | protected function initAuthManager(Application $app) |
|
190 | |||
191 | /** |
||
192 | * Initializes web url routes (rules in Yii2). |
||
193 | * |
||
194 | * @param WebApplication $app |
||
195 | */ |
||
196 | 10 | protected function initUrlRoutes(WebApplication $app) |
|
213 | |||
214 | /** |
||
215 | * Ensures required mail parameters needed for the mail service. |
||
216 | * |
||
217 | * @param Application $app |
||
218 | * @param Module|\yii\base\Module $module |
||
219 | */ |
||
220 | 10 | protected function initMailServiceConfiguration(Application $app, Module $module) |
|
232 | |||
233 | /** |
||
234 | * Ensures the authCollection component is configured. |
||
235 | * |
||
236 | * @param WebApplication $app |
||
237 | */ |
||
238 | 10 | protected function initAuthCollection(WebApplication $app) |
|
244 | |||
245 | /** |
||
246 | * Registers console commands to main app. |
||
247 | * |
||
248 | * @param ConsoleApplication $app |
||
249 | */ |
||
250 | protected function initConsoleCommands(ConsoleApplication $app) |
||
254 | |||
255 | /** |
||
256 | * Registers controllers. |
||
257 | * |
||
258 | * @param WebApplication $app |
||
259 | */ |
||
260 | 10 | protected function initControllerNamespace(WebApplication $app) |
|
265 | |||
266 | /** |
||
267 | * Builds class map according to user configuration. |
||
268 | * |
||
269 | * @param array $userClassMap user configuration on the module |
||
270 | * |
||
271 | * @return array |
||
272 | */ |
||
273 | 10 | protected function buildClassMap(array $userClassMap) |
|
330 | |||
331 | /** |
||
332 | * Returns the parent class name route of a short class name. |
||
333 | * |
||
334 | * @param array $routes class name routes |
||
335 | * @param string $name |
||
336 | * |
||
337 | * @throws Exception |
||
338 | * @return int|string |
||
339 | * |
||
340 | */ |
||
341 | 10 | protected function getRoute(array $routes, $name) |
|
350 | } |
||
351 |
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: