diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index ae12244..0381e16 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -8,6 +8,7 @@ namespace yii\base; use Yii; +use yii\helpers\Console; use yii\web\HttpException; /** @@ -510,6 +511,9 @@ abstract class Application extends Module { if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) { $message = $exception->getName() . ': ' . $exception->getMessage(); + if (Yii::$app->controller instanceof \yii\console\Controller) { + $message = Yii::$app->controller->ansiFormat($message, Console::FG_RED); + } } else { $message = YII_DEBUG ? (string)$exception : 'Error: ' . $exception->getMessage(); } diff --git a/framework/yii/console/Controller.php b/framework/yii/console/Controller.php index f605893..667031f 100644 --- a/framework/yii/console/Controller.php +++ b/framework/yii/console/Controller.php @@ -89,24 +89,22 @@ class Controller extends \yii\base\Controller */ public function bindActionParams($action, $params) { + $args = array(); if (!empty($params)) { $options = $this->globalOptions(); foreach ($params as $name => $value) { if (in_array($name, $options, true)) { $this->$name = $value; - unset($params[$name]); + } elseif (is_int($name)) { + $args[] = $value; + } else { + throw new Exception(Yii::t('yii', 'Unknown option: --{name}', array( + '{name}' => $name, + ))); } } } - $args = isset($params[Request::ANONYMOUS_PARAMS]) ? $params[Request::ANONYMOUS_PARAMS] : array(); - unset($params[Request::ANONYMOUS_PARAMS]); - if (!empty($params)) { - throw new Exception(Yii::t('yii', 'Unknown options: {params}', array( - '{params}' => implode(', ', array_keys($params)), - ))); - } - if ($action instanceof InlineAction) { $method = new \ReflectionMethod($this, $action->actionMethod); } else { diff --git a/framework/yii/console/Request.php b/framework/yii/console/Request.php index a9a4b03..fe1e23b 100644 --- a/framework/yii/console/Request.php +++ b/framework/yii/console/Request.php @@ -13,8 +13,6 @@ namespace yii\console; */ class Request extends \yii\base\Request { - const ANONYMOUS_PARAMS = '-args'; - private $_params; /** @@ -57,13 +55,13 @@ class Request extends \yii\base\Request $route = ''; } - $params = array(self::ANONYMOUS_PARAMS => array()); + $params = array(); foreach ($rawParams as $param) { if (preg_match('/^--(\w+)(=(.*))?$/', $param, $matches)) { $name = $matches[1]; $params[$name] = isset($matches[3]) ? $matches[3] : true; } else { - $params[self::ANONYMOUS_PARAMS][] = $param; + $params[] = $param; } } diff --git a/framework/yii/console/controllers/MessageController.php b/framework/yii/console/controllers/MessageController.php index f0efd4d..5c85c21 100644 --- a/framework/yii/console/controllers/MessageController.php +++ b/framework/yii/console/controllers/MessageController.php @@ -71,7 +71,7 @@ class MessageController extends Controller public function actionExtract($configFile) { if (!is_file($configFile)) { - throw new Exception("the configuration file {$configFile} does not exist."); + throw new Exception("The configuration file does not exist: $configFile"); } $config = array_merge(array( diff --git a/tests/unit/framework/console/controllers/AssetControllerTest.php b/tests/unit/framework/console/controllers/AssetControllerTest.php index 5da927a..3d53b6c 100644 --- a/tests/unit/framework/console/controllers/AssetControllerTest.php +++ b/tests/unit/framework/console/controllers/AssetControllerTest.php @@ -79,10 +79,7 @@ class AssetControllerTest extends TestCase $controller = $this->createAssetController(); ob_start(); ob_implicit_flush(false); - $params = array( - \yii\console\Request::ANONYMOUS_PARAMS => $args - ); - $controller->run($actionId, $params); + $controller->run($actionId, $args); return ob_get_clean(); } diff --git a/tests/unit/framework/console/controllers/MessageControllerTest.php b/tests/unit/framework/console/controllers/MessageControllerTest.php index c508fd0..cdd38b8 100644 --- a/tests/unit/framework/console/controllers/MessageControllerTest.php +++ b/tests/unit/framework/console/controllers/MessageControllerTest.php @@ -15,6 +15,7 @@ class MessageControllerTest extends TestCase public function setUp() { + $this->mockApplication(); $this->sourcePath = Yii::getAlias('@yiiunit/runtime/test_source'); $this->createDir($this->sourcePath); if (!file_exists($this->sourcePath)) { @@ -100,10 +101,7 @@ class MessageControllerTest extends TestCase $controller = $this->createMessageController(); ob_start(); ob_implicit_flush(false); - $params = array( - \yii\console\Request::ANONYMOUS_PARAMS => $args - ); - $controller->run($actionId, $params); + $controller->run($actionId, $args); return ob_get_clean(); }