From 25c0e6dcad33c8c56a300f3f0546021663b18f33 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Tue, 27 Jul 2021 15:35:47 -0400 Subject: [PATCH] Fix #18656: Added ability for `yii serve`'s `--router` param to take an alias --- framework/CHANGELOG.md | 1 + framework/console/controllers/ServeController.php | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 7e4e2e4f04..c0f12c9a14 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -19,6 +19,7 @@ Yii Framework 2 Change Log - Bug #18648: Fix `yii\web\Request` to properly handle HTTP Basic Auth headers (olegbaturin) - Enh #18726: Added `yii\helpers\Json::$prettyPrint` (rhertogh) - Enh #18734: Added `yii\validators\EmailValidator::$enableLocalIDN` (brandonkelly) +- Enh #18656: Added ability for `yii serve`'s `--router` param to take an alias (markhuot) 2.0.42.1 May 06, 2021 diff --git a/framework/console/controllers/ServeController.php b/framework/console/controllers/ServeController.php index 5eb9816597..67afee668b 100644 --- a/framework/console/controllers/ServeController.php +++ b/framework/console/controllers/ServeController.php @@ -36,7 +36,7 @@ class ServeController extends Controller */ public $docroot = '@app/web'; /** - * @var string path to router script. + * @var string path or [path alias](guide:concept-aliases) to router script. * See https://secure.php.net/manual/en/features.commandline.webserver.php */ public $router; @@ -52,6 +52,7 @@ class ServeController extends Controller public function actionIndex($address = 'localhost') { $documentRoot = Yii::getAlias($this->docroot); + $router = $this->router !== null ? Yii::getAlias($this->router) : null; if (strpos($address, ':') === false) { $address = $address . ':' . $this->port; @@ -67,19 +68,19 @@ class ServeController extends Controller return self::EXIT_CODE_ADDRESS_TAKEN_BY_ANOTHER_PROCESS; } - if ($this->router !== null && !file_exists($this->router)) { - $this->stdout("Routing file \"$this->router\" does not exist.\n", Console::FG_RED); + if ($this->router !== null && !file_exists($router)) { + $this->stdout("Routing file \"$router\" does not exist.\n", Console::FG_RED); return self::EXIT_CODE_NO_ROUTING_FILE; } $this->stdout("Server started on http://{$address}/\n"); $this->stdout("Document root is \"{$documentRoot}\"\n"); if ($this->router) { - $this->stdout("Routing file is \"$this->router\"\n"); + $this->stdout("Routing file is \"$router\"\n"); } $this->stdout("Quit the server with CTRL-C or COMMAND-C.\n"); - passthru('"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\" $this->router"); + passthru('"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\" $router"); } /**