From fc5045fd0c7eef429abc3f3495adee5fd720026d Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 8 May 2013 12:16:30 +0200 Subject: [PATCH 1/5] Fixed Copy paste error console/Controller also naming of formatString -> ansiFormat --- framework/console/Controller.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 539bca4..9f34046 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -128,13 +128,13 @@ class Controller extends \yii\base\Controller * * Example: * ~~~ - * $this->formatString('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE); + * $this->ansiFormat('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE); * ~~~ * * @param string $string the string to be formatted * @return string */ - public function formatString($string) + public function ansiFormat($string) { if ($this->ansi === true || $this->ansi === null && Console::streamSupportsAnsiColors(STDOUT)) { $args = func_get_args(); @@ -202,9 +202,9 @@ class Controller extends \yii\base\Controller public function input($prompt = null) { if (isset($prompt)) { - static::stdout($prompt); + $this->stdout($prompt); } - return static::stdin(); + return Console::stdin(); } /** @@ -217,7 +217,7 @@ class Controller extends \yii\base\Controller */ public function output($text = null) { - return static::stdout($text . PHP_EOL); + return $this->stdout($text . PHP_EOL); } /** @@ -230,7 +230,7 @@ class Controller extends \yii\base\Controller */ public function error($text = null) { - return static::stderr($text . PHP_EOL); + return $this->stderr($text . PHP_EOL); } /** @@ -276,7 +276,7 @@ class Controller extends \yii\base\Controller * * @return string An option character the user chose */ - public static function select($prompt, $options = array()) + public function select($prompt, $options = array()) { return Console::select($prompt, $options); } From 51357e58f091a68f2950513604cc7633d7416747 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 8 May 2013 12:46:54 +0200 Subject: [PATCH 2/5] more console helper and controller refactoring changed name of ansi switch to --colors https://github.com/yiisoft/yii2/commit/69cad905dd049be9d9b35d8103cd60591e13c6ae#commitcomment-3168489 issue #33 --- framework/console/Controller.php | 55 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 9f34046..c07d92d 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -36,10 +36,12 @@ class Controller extends \yii\base\Controller public $interactive = true; /** - * @var bool whether to enable ANSI style in output. If not set it will be auto detected. - * Default is disabled on Windows systems and enabled on linux. + * @var bool whether to enable ANSI style in output. + * Setting this will affect [[ansiFormat()]], [[stdout()]] and [[stderr()]]. + * If not set it will be auto detected using [[yii\helpers\Console::streamSupportsAnsiColors()]] with STDOUT + * for [[ansiFormat()]] and [[stdout()]] and STDERR for [[stderr()]]. */ - public $ansi; + public $colors; /** * Runs an action with the specified action ID and parameters. @@ -193,47 +195,6 @@ class Controller extends \yii\base\Controller } /** - * Asks the user for input. Ends when the user types a carriage return (PHP_EOL). Optionally, It also provides a - * prompt. - * - * @param string $prompt the prompt (optional) - * @return string the user's input - */ - public function input($prompt = null) - { - if (isset($prompt)) { - $this->stdout($prompt); - } - return Console::stdin(); - } - - /** - * Prints text to STDOUT appended with a carriage return (PHP_EOL). - * - * @param string $text - * @param bool $raw - * - * @return mixed Number of bytes printed or bool false on error - */ - public function output($text = null) - { - return $this->stdout($text . PHP_EOL); - } - - /** - * Prints text to STDERR appended with a carriage return (PHP_EOL). - * - * @param string $text - * @param bool $raw - * - * @return mixed Number of bytes printed or false on error - */ - public function error($text = null) - { - return $this->stderr($text . PHP_EOL); - } - - /** * Prompts the user for input and validates it * * @param string $text prompt string @@ -248,7 +209,11 @@ class Controller extends \yii\base\Controller */ public function prompt($text, $options = array()) { - return Console::prompt($text, $options); + if ($this->interactive) { + return Console::prompt($text, $options); + } else { + return isset($options['default']) ? $options['default'] : ''; + } } /** From 01ae01508838864d3a450f1163924beb6b4f78b1 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 8 May 2013 06:58:34 -0400 Subject: [PATCH 3/5] Fixes issue #180: DbSession crashes with autoStart --- framework/web/DbSession.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/web/DbSession.php b/framework/web/DbSession.php index 2910b40..e81aa7f 100644 --- a/framework/web/DbSession.php +++ b/framework/web/DbSession.php @@ -71,13 +71,13 @@ class DbSession extends Session */ public function init() { - parent::init(); if (is_string($this->db)) { $this->db = Yii::$app->getComponent($this->db); } if (!$this->db instanceof Connection) { throw new InvalidConfigException("DbSession::db must be either a DB connection instance or the application component ID of a DB connection."); - } + } + parent::init(); } /** From 2dd51d5b46b75d179dbc7cf0c239b303370fafd9 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 8 May 2013 07:16:48 -0400 Subject: [PATCH 4/5] Fixes issue #177. --- apps/bootstrap/protected/config/main.php | 10 ++++++++++ framework/base/Application.php | 1 - framework/logging/Logger.php | 6 ++++-- framework/logging/Router.php | 13 ++++++------- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/bootstrap/protected/config/main.php b/apps/bootstrap/protected/config/main.php index 96e0986..20b5e7e 100644 --- a/apps/bootstrap/protected/config/main.php +++ b/apps/bootstrap/protected/config/main.php @@ -3,6 +3,7 @@ return array( 'id' => 'hello', 'basePath' => dirname(__DIR__), + 'preload' => array('log'), 'components' => array( 'cache' => array( 'class' => 'yii\caching\FileCache', @@ -14,6 +15,15 @@ return array( 'assetManager' => array( 'bundles' => require(__DIR__ . '/assets.php'), ), + 'log' => array( + 'class' => 'yii\logging\Router', + 'targets' => array( + 'file' => array( + 'class' => 'yii\logging\FileTarget', + 'levels' => array('error', 'warning'), + ), + ), + ), ), 'params' => array( 'adminEmail' => 'admin@example.com', diff --git a/framework/base/Application.php b/framework/base/Application.php index 5b92f76..ac7cc6a 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -8,7 +8,6 @@ namespace yii\base; use Yii; -use yii\helpers\FileHelper; /** * Application is the base class for all application classes. diff --git a/framework/logging/Logger.php b/framework/logging/Logger.php index 607c388..5c9a89d 100644 --- a/framework/logging/Logger.php +++ b/framework/logging/Logger.php @@ -6,7 +6,9 @@ */ namespace yii\logging; -use yii\base\InvalidConfigException; + +use \yii\base\Component; +use \yii\base\InvalidConfigException; /** * Logger records logged messages in memory. @@ -17,7 +19,7 @@ use yii\base\InvalidConfigException; * @author Qiang Xue * @since 2.0 */ -class Logger extends \yii\base\Component +class Logger extends Component { /** * Error message level. An error message is one that indicates the abnormal termination of the diff --git a/framework/logging/Router.php b/framework/logging/Router.php index 2f399fe..f544b72 100644 --- a/framework/logging/Router.php +++ b/framework/logging/Router.php @@ -28,16 +28,16 @@ use yii\base\Application; * 'preload' => array('log'), * 'components' => array( * 'log' => array( - * 'class' => '\yii\logging\Router', + * 'class' => 'yii\logging\Router', * 'targets' => array( * 'file' => array( - * 'class' => '\yii\logging\FileTarget', - * 'levels' => 'trace, info', - * 'categories' => 'yii\*', + * 'class' => 'yii\logging\FileTarget', + * 'levels' => array('trace', 'info'), + * 'categories' => array('yii\*'), * ), * 'email' => array( - * 'class' => '\yii\logging\EmailTarget', - * 'levels' => 'error, warning', + * 'class' => 'yii\logging\EmailTarget', + * 'levels' => array('error', 'warning'), * 'emails' => array('admin@example.com'), * ), * ), @@ -73,7 +73,6 @@ class Router extends Component public function init() { parent::init(); - foreach ($this->targets as $name => $target) { if (!$target instanceof Target) { $this->targets[$name] = Yii::createObject($target); From c5bad9ea1b88adffe41390a9de13cea9bf0189f8 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 8 May 2013 09:39:34 -0400 Subject: [PATCH 5/5] Fixes issue #172: Added Object::className(). --- apps/bootstrap/protected/views/layouts/main.php | 6 ++++-- apps/bootstrap/protected/views/site/contact.php | 4 +++- apps/bootstrap/protected/views/site/login.php | 4 +++- framework/base/Object.php | 8 ++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/bootstrap/protected/views/layouts/main.php b/apps/bootstrap/protected/views/layouts/main.php index 0eaeb99..1e8a3af 100644 --- a/apps/bootstrap/protected/views/layouts/main.php +++ b/apps/bootstrap/protected/views/layouts/main.php @@ -1,9 +1,11 @@ registerAssetBundle('app'); ?> beginPage(); ?> @@ -23,7 +25,7 @@ $this->registerAssetBundle('app');