Browse Source

Fix #18656: Added ability for `yii serve`'s `--router` param to take an alias

tags/2.0.43
Mark Huot 3 years ago committed by GitHub
parent
commit
25c0e6dcad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 11
      framework/console/controllers/ServeController.php

1
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

11
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");
}
/**

Loading…
Cancel
Save