"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "framework/console/Controller.php" between
yii2-2.0.35.tar.gz and yii2-2.0.36.tar.gz

About: Yii 2 is a high-performance component-based PHP framework for developing large-scale Web applications (source).

Controller.php  (yii2-2.0.35):Controller.php  (yii2-2.0.36)
skipping to change at line 37 skipping to change at line 37
* *
* where `<route>` is a route to a controller action and the params will be popu lated as properties of a command. * where `<route>` is a route to a controller action and the params will be popu lated as properties of a command.
* See [[options()]] for details. * See [[options()]] for details.
* *
* @property string $help This property is read-only. * @property string $help This property is read-only.
* @property string $helpSummary This property is read-only. * @property string $helpSummary This property is read-only.
* @property array $passedOptionValues The properties corresponding to the passe d options. This property is * @property array $passedOptionValues The properties corresponding to the passe d options. This property is
* read-only. * read-only.
* @property array $passedOptions The names of the options passed during executi on. This property is * @property array $passedOptions The names of the options passed during executi on. This property is
* read-only. * read-only.
* @property Request $request
* @property Response $response
* *
* @author Qiang Xue <qiang.xue@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0 * @since 2.0
*/ */
class Controller extends \yii\base\Controller class Controller extends \yii\base\Controller
{ {
/** /**
* @deprecated since 2.0.13. Use [[ExitCode::OK]] instead. * @deprecated since 2.0.13. Use [[ExitCode::OK]] instead.
*/ */
const EXIT_CODE_NORMAL = 0; const EXIT_CODE_NORMAL = 0;
skipping to change at line 66 skipping to change at line 68
/** /**
* @var bool whether to enable ANSI color in the output. * @var bool whether to enable ANSI color in the output.
* If not set, ANSI color will only be enabled for terminals that support it . * If not set, ANSI color will only be enabled for terminals that support it .
*/ */
public $color; public $color;
/** /**
* @var bool whether to display help information about current command. * @var bool whether to display help information about current command.
* @since 2.0.10 * @since 2.0.10
*/ */
public $help; public $help;
/**
* @var bool if true - script finish with `ExitCode::OK` in case of exceptio
n.
* false - `ExitCode::UNSPECIFIED_ERROR`.
* Default: `YII_ENV_TEST`
* @since 2.0.36
*/
public $silentExitOnException;
/** /**
* @var array the options passed during execution. * @var array the options passed during execution.
*/ */
private $_passedOptions = []; private $_passedOptions = [];
public function beforeAction($action)
{
$silentExit = $this->silentExitOnException !== null ? $this->silentExitO
nException : YII_ENV_TEST;
Yii::$app->errorHandler->silentExitOnException = $silentExit;
return parent::beforeAction($action);
}
/** /**
* Returns a value indicating whether ANSI color is enabled. * Returns a value indicating whether ANSI color is enabled.
* *
* ANSI color is enabled only if [[color]] is set true or is not set * ANSI color is enabled only if [[color]] is set true or is not set
* and the terminal supports ANSI color. * and the terminal supports ANSI color.
* *
* @param resource $stream the stream to check. * @param resource $stream the stream to check.
* @return bool Whether to enable ANSI style in output. * @return bool Whether to enable ANSI style in output.
*/ */
public function isColorEnabled($stream = \STDOUT) public function isColorEnabled($stream = \STDOUT)
skipping to change at line 184 skipping to change at line 201
* @throws Exception if there are unknown options or missing arguments * @throws Exception if there are unknown options or missing arguments
*/ */
public function bindActionParams($action, $params) public function bindActionParams($action, $params)
{ {
if ($action instanceof InlineAction) { if ($action instanceof InlineAction) {
$method = new \ReflectionMethod($this, $action->actionMethod); $method = new \ReflectionMethod($this, $action->actionMethod);
} else { } else {
$method = new \ReflectionMethod($action, 'run'); $method = new \ReflectionMethod($action, 'run');
} }
$args = array_values($params); $args = [];
$missing = []; $missing = [];
$actionParams = [];
$requestedParams = [];
foreach ($method->getParameters() as $i => $param) { foreach ($method->getParameters() as $i => $param) {
if ($param->isArray() && isset($args[$i])) { $name = $param->getName();
$args[$i] = $args[$i] === '' ? [] : preg_split('/\s*,\s*/', $arg $key = null;
s[$i]); if (array_key_exists($i, $params)) {
$key = $i;
} elseif (array_key_exists($name, $params)) {
$key = $name;
} }
if (!isset($args[$i])) {
if ($param->isDefaultValueAvailable()) { if ($key !== null) {
$args[$i] = $param->getDefaultValue(); if ($param->isArray()) {
} else { $params[$key] = $params[$key] === '' ? [] : preg_split('/\s*
$missing[] = $param->getName(); ,\s*/', $params[$key]);
}
$args[] = $actionParams[$key] = $params[$key];
unset($params[$key]);
} elseif (PHP_VERSION_ID >= 70100 && ($type = $param->getType()) !==
null && !$type->isBuiltin()) {
try {
$this->bindInjectedParams($type, $name, $args, $requestedPar
ams);
} catch (\yii\base\Exception $e) {
throw new Exception($e->getMessage());
} }
} elseif ($param->isDefaultValueAvailable()) {
$args[] = $actionParams[$i] = $param->getDefaultValue();
} else {
$missing[] = $name;
} }
} }
if (!empty($missing)) { if (!empty($missing)) {
throw new Exception(Yii::t('yii', 'Missing required arguments: {para ms}', ['params' => implode(', ', $missing)])); throw new Exception(Yii::t('yii', 'Missing required arguments: {para ms}', ['params' => implode(', ', $missing)]));
} }
// We use a different array here, specifically one that doesn't contain
service instances but descriptions instead.
if (\Yii::$app->requestedParams === null) {
\Yii::$app->requestedParams = array_merge($actionParams, $requestedP
arams);
}
return $args; return $args;
} }
/** /**
* Formats a string with ANSI codes. * Formats a string with ANSI codes.
* *
* You may pass additional parameters using the constants defined in [[\yii\ helpers\Console]]. * You may pass additional parameters using the constants defined in [[\yii\ helpers\Console]].
* *
* Example: * Example:
* *
skipping to change at line 245 skipping to change at line 283
* You may optionally format the string with ANSI codes by * You may optionally format the string with ANSI codes by
* passing additional parameters using the constants defined in [[\yii\helpe rs\Console]]. * passing additional parameters using the constants defined in [[\yii\helpe rs\Console]].
* *
* Example: * Example:
* *
* ``` * ```
* $this->stdout('This will be red and underlined.', Console::FG_RED, Consol e::UNDERLINE); * $this->stdout('This will be red and underlined.', Console::FG_RED, Consol e::UNDERLINE);
* ``` * ```
* *
* @param string $string the string to print * @param string $string the string to print
* @param int ...$args additional parameters to decorate the output
* @return int|bool Number of bytes printed or false on error * @return int|bool Number of bytes printed or false on error
*/ */
public function stdout($string) public function stdout($string)
{ {
if ($this->isColorEnabled()) { if ($this->isColorEnabled()) {
$args = func_get_args(); $args = func_get_args();
array_shift($args); array_shift($args);
$string = Console::ansiFormat($string, $args); $string = Console::ansiFormat($string, $args);
} }
skipping to change at line 376 skipping to change at line 415
* *
* Note that the values setting via options are not available * Note that the values setting via options are not available
* until [[beforeAction()]] is being called. * until [[beforeAction()]] is being called.
* *
* @param string $actionID the action id of the current request * @param string $actionID the action id of the current request
* @return string[] the names of the options valid for the action * @return string[] the names of the options valid for the action
*/ */
public function options($actionID) public function options($actionID)
{ {
// $actionId might be used in subclasses to provide options specific to action id // $actionId might be used in subclasses to provide options specific to action id
return ['color', 'interactive', 'help']; return ['color', 'interactive', 'help', 'silentExitOnException'];
} }
/** /**
* Returns option alias names. * Returns option alias names.
* Child classes may override this method to specify alias options. * Child classes may override this method to specify alias options.
* *
* @return array the options alias names valid for the action * @return array the options alias names valid for the action
* where the keys is alias name for option and value is option name. * where the keys is alias name for option and value is option name.
* *
* @since 2.0.8 * @since 2.0.8
 End of changes. 11 change blocks. 
11 lines changed or deleted 56 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)