From e8eccc281d79b0186b1d2ad3298f8ccf100989fc Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 19 Oct 2013 02:01:58 +0400 Subject: [PATCH 01/26] Refactored instanceof in Module into method in Application --- framework/yii/base/Application.php | 14 ++++++++++++++ framework/yii/base/Module.php | 12 ++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index d92b05c..b3803cb 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -172,6 +172,20 @@ abstract class Application extends Module } /** + * Initializes the application. + * This method is called after the application is created and initialized with property values + * given in configuration. + */ + public function init() + { + $this->preloadComponents(); + if ($this->controllerNamespace === null) { + $this->controllerNamespace = 'app\\controllers'; + } + } + + + /** * Loads components that are declared in [[preload]]. * @throws InvalidConfigException if a component or module to be preloaded is unknown */ diff --git a/framework/yii/base/Module.php b/framework/yii/base/Module.php index abf39ec..8e62d0a 100644 --- a/framework/yii/base/Module.php +++ b/framework/yii/base/Module.php @@ -167,20 +167,16 @@ abstract class Module extends Component /** * Initializes the module. * This method is called after the module is created and initialized with property values - * given in configuration. The default implement will create a path alias using the module [[id]] + * given in configuration. The default implementation will create a path alias using the module [[id]] * and then call [[preloadComponents()]] to load components that are declared in [[preload]]. */ public function init() { $this->preloadComponents(); if ($this->controllerNamespace === null) { - if ($this instanceof Application) { - $this->controllerNamespace = 'app\\controllers'; - } else { - $class = get_class($this); - if (($pos = strrpos($class, '\\')) !== false) { - $this->controllerNamespace = substr($class, 0, $pos) . '\\controllers'; - } + $class = get_class($this); + if (($pos = strrpos($class, '\\')) !== false) { + $this->controllerNamespace = substr($class, 0, $pos) . '\\controllers'; } } } From 3e2bcfdf52c5dd96f349a993ded466d7967bac5e Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 19 Oct 2013 02:19:27 +0400 Subject: [PATCH 02/26] Refactored Module::setBasePath to remove instanceof condition --- framework/yii/base/Application.php | 12 ++++++++++++ framework/yii/base/Module.php | 3 --- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index b3803cb..55258ee 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -222,6 +222,18 @@ abstract class Application extends Module } /** + * Sets the root directory of the applicaition and the @app alias. + * This method can only be invoked at the beginning of the constructor. + * @param string $path the root directory of the application. + * @throws InvalidParamException if the directory does not exist. + */ + public function setBasePath($path) + { + parent::setBasePath($path); + Yii::setAlias('@app', $this->getBasePath()); + } + + /** * Runs the application. * This is the main entrance of an application. * @return integer the exit status (0 means normal, non-zero values mean abnormal) diff --git a/framework/yii/base/Module.php b/framework/yii/base/Module.php index 8e62d0a..a03fd83 100644 --- a/framework/yii/base/Module.php +++ b/framework/yii/base/Module.php @@ -217,9 +217,6 @@ abstract class Module extends Component $p = realpath($path); if ($p !== false && is_dir($p)) { $this->_basePath = $p; - if ($this instanceof Application) { - Yii::setAlias('@app', $p); - } } else { throw new InvalidParamException("The directory does not exist: $path"); } From 54e1abaa7b28924c01c75e7ee5859246696cb179 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 19 Oct 2013 02:22:05 +0400 Subject: [PATCH 03/26] Better Module::init refactoring --- framework/yii/base/Application.php | 19 +++++-------------- framework/yii/base/Module.php | 12 ++++++------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index 55258ee..11abfd6 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -140,6 +140,11 @@ abstract class Application extends Module $this->registerCoreComponents(); Component::__construct($config); + + $this->preloadComponents(); + if ($this->controllerNamespace === null) { + $this->controllerNamespace = 'app\\controllers'; + } } /** @@ -172,20 +177,6 @@ abstract class Application extends Module } /** - * Initializes the application. - * This method is called after the application is created and initialized with property values - * given in configuration. - */ - public function init() - { - $this->preloadComponents(); - if ($this->controllerNamespace === null) { - $this->controllerNamespace = 'app\\controllers'; - } - } - - - /** * Loads components that are declared in [[preload]]. * @throws InvalidConfigException if a component or module to be preloaded is unknown */ diff --git a/framework/yii/base/Module.php b/framework/yii/base/Module.php index a03fd83..a7aa387 100644 --- a/framework/yii/base/Module.php +++ b/framework/yii/base/Module.php @@ -130,6 +130,12 @@ abstract class Module extends Component $this->id = $id; $this->module = $parent; parent::__construct($config); + if ($this->controllerNamespace === null) { + $class = get_class($this); + if (($pos = strrpos($class, '\\')) !== false) { + $this->controllerNamespace = substr($class, 0, $pos) . '\\controllers'; + } + } } /** @@ -173,12 +179,6 @@ abstract class Module extends Component public function init() { $this->preloadComponents(); - if ($this->controllerNamespace === null) { - $class = get_class($this); - if (($pos = strrpos($class, '\\')) !== false) { - $this->controllerNamespace = substr($class, 0, $pos) . '\\controllers'; - } - } } /** From 8583de701df813f72ece5ee4d52eb3edcf845c2d Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 19 Oct 2013 02:23:05 +0400 Subject: [PATCH 04/26] Removed unnecessary call --- framework/yii/base/Application.php | 1 - 1 file changed, 1 deletion(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index 11abfd6..5de7969 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -141,7 +141,6 @@ abstract class Application extends Module Component::__construct($config); - $this->preloadComponents(); if ($this->controllerNamespace === null) { $this->controllerNamespace = 'app\\controllers'; } From 9434cc8f40b6815ce39c6e51b91fd701663bdc6f Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 19 Oct 2013 13:30:31 +0400 Subject: [PATCH 05/26] Moved Application::$controllerNamespace init into variable declaration, reordered Module::__construct. --- framework/yii/base/Application.php | 11 +++++++---- framework/yii/base/Module.php | 3 +-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index 5de7969..c871548 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -54,6 +54,13 @@ abstract class Application extends Module * @event ActionEvent an event raised after executing a controller action. */ const EVENT_AFTER_ACTION = 'afterAction'; + + /** + * @var string the namespace that controller classes are in. If not set, + * it will use the "app\controllers" namespace. + */ + public $controllerNamespace = 'app\\controllers'; + /** * @var string the application name. */ @@ -140,10 +147,6 @@ abstract class Application extends Module $this->registerCoreComponents(); Component::__construct($config); - - if ($this->controllerNamespace === null) { - $this->controllerNamespace = 'app\\controllers'; - } } /** diff --git a/framework/yii/base/Module.php b/framework/yii/base/Module.php index 0e5c592..996d0f2 100644 --- a/framework/yii/base/Module.php +++ b/framework/yii/base/Module.php @@ -83,7 +83,6 @@ abstract class Module extends Component * it will use the "controllers" sub-namespace under the namespace of this module. * For example, if the namespace of this module is "foo\bar", then the default * controller namespace would be "foo\bar\controllers". - * If the module is an application, it will default to "app\controllers". */ public $controllerNamespace; /** @@ -127,9 +126,9 @@ abstract class Module extends Component */ public function __construct($id, $parent = null, $config = []) { + parent::__construct($config); $this->id = $id; $this->module = $parent; - parent::__construct($config); if ($this->controllerNamespace === null) { $class = get_class($this); if (($pos = strrpos($class, '\\')) !== false) { From 8e1199b0f6ee5371c1dbc39037b088890731ca8b Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sat, 19 Oct 2013 23:24:51 +0400 Subject: [PATCH 06/26] Moved setting controllerNamespace back to init --- framework/yii/base/Module.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/framework/yii/base/Module.php b/framework/yii/base/Module.php index 996d0f2..1fdf5ee 100644 --- a/framework/yii/base/Module.php +++ b/framework/yii/base/Module.php @@ -126,15 +126,9 @@ abstract class Module extends Component */ public function __construct($id, $parent = null, $config = []) { - parent::__construct($config); $this->id = $id; $this->module = $parent; - if ($this->controllerNamespace === null) { - $class = get_class($this); - if (($pos = strrpos($class, '\\')) !== false) { - $this->controllerNamespace = substr($class, 0, $pos) . '\\controllers'; - } - } + parent::__construct($config); } /** @@ -178,6 +172,12 @@ abstract class Module extends Component public function init() { $this->preloadComponents(); + if ($this->controllerNamespace === null) { + $class = get_class($this); + if (($pos = strrpos($class, '\\')) !== false) { + $this->controllerNamespace = substr($class, 0, $pos) . '\\controllers'; + } + } } /** From c2dabfa78e5dfc8863b7137173e71afe9393187a Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Sun, 20 Oct 2013 00:59:43 +0400 Subject: [PATCH 07/26] Adjusted short tags --- apps/advanced/backend/views/layouts/main.php | 10 ++-- apps/advanced/backend/views/site/error.php | 4 +- apps/advanced/backend/views/site/login.php | 10 ++-- apps/advanced/frontend/views/layouts/main.php | 10 ++-- apps/advanced/frontend/views/site/about.php | 4 +- apps/advanced/frontend/views/site/contact.php | 12 ++--- apps/advanced/frontend/views/site/error.php | 4 +- apps/advanced/frontend/views/site/login.php | 10 ++-- .../views/site/requestPasswordResetToken.php | 6 +-- .../advanced/frontend/views/site/resetPassword.php | 6 +-- apps/advanced/frontend/views/site/signup.php | 10 ++-- apps/basic/views/layouts/main.php | 10 ++-- apps/basic/views/site/about.php | 4 +- apps/basic/views/site/contact.php | 12 ++--- apps/basic/views/site/error.php | 4 +- apps/basic/views/site/login.php | 8 +-- docs/guide/upgrade-from-v1.md | 6 +-- docs/guide/view.md | 16 +++--- framework/yii/debug/views/default/index.php | 10 ++-- framework/yii/debug/views/default/toolbar.php | 10 ++-- framework/yii/debug/views/default/view.php | 4 +- framework/yii/debug/views/layouts/main.php | 4 +- .../generators/controller/templates/controller.php | 8 +-- .../gii/generators/controller/templates/view.php | 6 +-- .../gii/generators/crud/templates/controller.php | 58 +++++++++++----------- .../yii/gii/generators/crud/templates/search.php | 18 +++---- .../gii/generators/crud/templates/views/_form.php | 10 ++-- .../generators/crud/templates/views/_search.php | 12 ++--- .../gii/generators/crud/templates/views/create.php | 12 ++--- .../gii/generators/crud/templates/views/index.php | 20 ++++---- .../gii/generators/crud/templates/views/update.php | 14 +++--- .../gii/generators/crud/templates/views/view.php | 16 +++--- .../yii/gii/generators/form/templates/action.php | 6 +-- .../yii/gii/generators/form/templates/form.php | 16 +++--- .../yii/gii/generators/model/templates/model.php | 20 ++++---- .../gii/generators/module/templates/controller.php | 2 +- .../yii/gii/generators/module/templates/module.php | 6 +-- .../yii/gii/generators/module/templates/view.php | 12 ++--- framework/yii/gii/views/default/diff.php | 2 +- framework/yii/gii/views/default/index.php | 6 +-- framework/yii/gii/views/default/view.php | 8 +-- framework/yii/gii/views/default/view/files.php | 6 +-- framework/yii/gii/views/default/view/results.php | 2 +- framework/yii/gii/views/layouts/generator.php | 2 +- framework/yii/gii/views/layouts/main.php | 6 +-- framework/yii/requirements/views/web/index.php | 12 ++--- framework/yii/views/errorHandler/callStackItem.php | 8 +-- framework/yii/views/errorHandler/error.php | 8 +-- framework/yii/views/errorHandler/exception.php | 18 +++---- .../yii/views/errorHandler/previousException.php | 12 ++--- framework/yii/views/migration.php | 4 +- tests/unit/data/views/layout.php | 2 +- 52 files changed, 253 insertions(+), 253 deletions(-) diff --git a/apps/advanced/backend/views/layouts/main.php b/apps/advanced/backend/views/layouts/main.php index 1c003e5..85a4d2b 100644 --- a/apps/advanced/backend/views/layouts/main.php +++ b/apps/advanced/backend/views/layouts/main.php @@ -15,8 +15,8 @@ AppAsset::register($this); - - <?=Html::encode($this->title); ?> + + <?= Html::encode($this->title) ?> head(); ?> @@ -48,13 +48,13 @@ AppAsset::register($this); isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], ]); ?> - +
-

© My Company

-

+

© My Company

+

diff --git a/apps/advanced/backend/views/site/error.php b/apps/advanced/backend/views/site/error.php index eef87f6..15a8eee 100644 --- a/apps/advanced/backend/views/site/error.php +++ b/apps/advanced/backend/views/site/error.php @@ -13,10 +13,10 @@ $this->title = $name; ?>
-

title); ?>

+

title) ?>

- +

diff --git a/apps/advanced/backend/views/site/login.php b/apps/advanced/backend/views/site/login.php index d52eaa1..65495bf 100644 --- a/apps/advanced/backend/views/site/login.php +++ b/apps/advanced/backend/views/site/login.php @@ -11,18 +11,18 @@ $this->title = 'Login'; $this->params['breadcrumbs'][] = $this->title; ?>