Skip to content

Commit b837304

Browse files
authored
Merge pull request #567 from TonisOrmisson/fixed-console-pretty-urls-v1
v1: fixed pretty-urls not working from console apps
2 parents 300b4d9 + 1170563 commit b837304

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fix #546: The profile/show page must not be visible by default, implement configurable policy (TonisOrmisson)
99
- Fix #397: No more fatal Exceptions when connecting to already taken Social Network (edegaudenzi)
1010
- Ehh: Added option to pre-fill recovery email via url parameter (TonisOrmisson)
11+
- Ehh: Fixed pretty-url rules not initialized for console apps (TonisOrmisson)
1112

1213
## 1.6.3 Mar 18th, 2024
1314

src/User/Bootstrap.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use yii\helpers\ArrayHelper;
3131
use yii\i18n\PhpMessageSource;
3232
use yii\web\Application as WebApplication;
33+
use yii\web\UrlManager;
3334

3435
/**
3536
* Bootstrap class of the yii2-usuario extension. Configures container services, initializes translations,
@@ -49,10 +50,10 @@ public function bootstrap($app)
4950
$this->initTranslations($app);
5051
$this->initContainer($app, $map);
5152
$this->initMailServiceConfiguration($app, $app->getModule('user'));
53+
$this->initUrlRoutes($app);
5254

5355
if ($app instanceof WebApplication) {
5456
$this->initControllerNamespace($app);
55-
$this->initUrlRoutes($app);
5657
$this->initUrlRestRoutes($app);
5758
$this->initAuthCollection($app);
5859
$this->initAuthManager($app);
@@ -256,11 +257,11 @@ protected function initAuthManager(Application $app)
256257
/**
257258
* Initializes web url routes (rules in Yii2).
258259
*
259-
* @param WebApplication $app
260+
* @param Application $app
260261
*
261262
* @throws InvalidConfigException
262263
*/
263-
protected function initUrlRoutes(WebApplication $app)
264+
protected function initUrlRoutes(Application $app)
264265
{
265266
/** @var $module Module */
266267
$module = $app->getModule('user');
@@ -274,8 +275,13 @@ protected function initUrlRoutes(WebApplication $app)
274275
$config['routePrefix'] = 'user';
275276
}
276277

278+
$urlManager = $app->getUrlManager();
279+
if(!($urlManager instanceof UrlManager)) {
280+
return;
281+
}
282+
277283
$rule = Yii::createObject($config);
278-
$app->getUrlManager()->addRules([$rule], false);
284+
$urlManager->addRules([$rule], false);
279285
}
280286

281287
/**

0 commit comments

Comments
 (0)