From edc48dc9c76aa2a15f7efddd05d8f687bffb70d6 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sun, 20 Jan 2013 11:26:15 -0500 Subject: [PATCH] removed ApplicationComponent. --- framework/base/ApplicationComponent.php | 32 ------------------------- framework/base/Behavior.php | 11 +++++---- framework/base/Component.php | 11 +++++---- framework/base/ErrorHandler.php | 2 +- framework/base/Module.php | 10 ++++---- framework/base/Request.php | 2 +- framework/base/Response.php | 2 +- framework/base/SecurityManager.php | 2 +- framework/base/Theme.php | 2 +- framework/base/UrlManager.php | 4 ++-- framework/db/Connection.php | 5 ++-- 11 files changed, 27 insertions(+), 56 deletions(-) delete mode 100644 framework/base/ApplicationComponent.php diff --git a/framework/base/ApplicationComponent.php b/framework/base/ApplicationComponent.php deleted file mode 100644 index 982d94079e..0000000000 --- a/framework/base/ApplicationComponent.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @since 2.0 - */ -class ApplicationComponent extends Component -{ - /** - * @var string unique ID of this application component - */ - public $id; - - public function init() - { - parent::init(); - if ($this->id === null) { - $this->id = get_class($this); - } - } -} diff --git a/framework/base/Behavior.php b/framework/base/Behavior.php index 8cf100bc13..9155097e80 100644 --- a/framework/base/Behavior.php +++ b/framework/base/Behavior.php @@ -80,13 +80,14 @@ class Behavior extends \yii\base\Object * The default implementation will unset the [[owner]] property * and detach event handlers declared in [[events]]. * Make sure you call the parent implementation if you override this method. - * @param Component $owner the component that this behavior is to be detached from. */ - public function detach($owner) + public function detach() { - foreach ($this->events() as $event => $handler) { - $owner->off($event, is_string($handler) ? array($this, $handler) : $handler); + if ($this->owner) { + foreach ($this->events() as $event => $handler) { + $this->owner->off($event, is_string($handler) ? array($this, $handler) : $handler); + } + $this->owner = null; } - $this->owner = null; } } diff --git a/framework/base/Component.php b/framework/base/Component.php index fe959f8597..c6c91eb30d 100644 --- a/framework/base/Component.php +++ b/framework/base/Component.php @@ -76,7 +76,8 @@ class Component extends \yii\base\Object * will be implicitly called when executing `$component->property = $value;`. * @param string $name the property name or the event name * @param mixed $value the property value - * @throws UnknownPropertyException if the property is not defined or read-only. + * @throws UnknownPropertyException if the property is not defined + * @throws InvalidCallException if the property is read-only. * @see __get */ public function __set($name, $value) @@ -151,7 +152,7 @@ class Component extends \yii\base\Object * Do not call this method directly as it is a PHP magic method that * will be implicitly called when executing `unset($component->property)`. * @param string $name the property name - * @throws UnknownPropertyException if the property is read only. + * @throws InvalidCallException if the property is read only. */ public function __unset($name) { @@ -421,7 +422,7 @@ class Component extends \yii\base\Object public function trigger($name, $event = null) { $this->ensureBehaviors(); - if (isset($this->_e[$name])) { + if (isset($this->_e[$name]) && $this->_e[$name]->getCount()) { if ($event === null) { $event = new Event($this); } @@ -505,7 +506,7 @@ class Component extends \yii\base\Object if (isset($this->_b[$name])) { $behavior = $this->_b[$name]; unset($this->_b[$name]); - $behavior->detach($this); + $behavior->detach(); return $behavior; } else { return null; @@ -550,7 +551,7 @@ class Component extends \yii\base\Object $behavior = \Yii::createObject($behavior); } if (isset($this->_b[$name])) { - $this->_b[$name]->detach($this); + $this->_b[$name]->detach(); } $behavior->attach($this); return $this->_b[$name] = $behavior; diff --git a/framework/base/ErrorHandler.php b/framework/base/ErrorHandler.php index 765a01510c..9f1621a194 100644 --- a/framework/base/ErrorHandler.php +++ b/framework/base/ErrorHandler.php @@ -20,7 +20,7 @@ namespace yii\base; */ use yii\util\VarDumper; -class ErrorHandler extends ApplicationComponent +class ErrorHandler extends Component { /** * @var integer maximum number of source code lines to be displayed. Defaults to 25. diff --git a/framework/base/Module.php b/framework/base/Module.php index ef48ef13bc..f08d03363b 100644 --- a/framework/base/Module.php +++ b/framework/base/Module.php @@ -427,14 +427,14 @@ abstract class Module extends Component * Retrieves the named application component. * @param string $id application component ID (case-sensitive) * @param boolean $load whether to load the component if it is not yet loaded. - * @return ApplicationComponent|null the application component instance, null if the application component + * @return Component|null the application component instance, null if the application component * does not exist. * @see hasComponent() */ public function getComponent($id, $load = true) { if (isset($this->_components[$id])) { - if ($this->_components[$id] instanceof ApplicationComponent) { + if ($this->_components[$id] instanceof Component) { return $this->_components[$id]; } elseif ($load) { \Yii::trace("Loading \"$id\" application component", __CLASS__); @@ -447,10 +447,10 @@ abstract class Module extends Component /** * Registers an application component in this module. * @param string $id component ID - * @param ApplicationComponent|array|null $component the component to be added to the module. This can + * @param Component|array|null $component the component to be added to the module. This can * be one of the followings: * - * - an [[ApplicationComponent]] object + * - a [[Component]] object * - a configuration array: when [[getComponent()]] is called initially for this component, the array * will be used to instantiate the component * - null: the named component will be removed from the module @@ -476,7 +476,7 @@ abstract class Module extends Component if ($loadedOnly) { $components = array(); foreach ($this->_components as $component) { - if ($component instanceof ApplicationComponent) { + if ($component instanceof Component) { $components[] = $component; } } diff --git a/framework/base/Request.php b/framework/base/Request.php index 2295d0c3cb..0dbc568c03 100644 --- a/framework/base/Request.php +++ b/framework/base/Request.php @@ -13,7 +13,7 @@ namespace yii\base; * @author Qiang Xue * @since 2.0 */ -class Request extends ApplicationComponent +class Request extends Component { private $_scriptFile; private $_isConsoleRequest; diff --git a/framework/base/Response.php b/framework/base/Response.php index d2ef6543db..3ced584564 100644 --- a/framework/base/Response.php +++ b/framework/base/Response.php @@ -13,7 +13,7 @@ namespace yii\base; * @author Qiang Xue * @since 2.0 */ -class Response extends ApplicationComponent +class Response extends Component { public function beginOutput() { diff --git a/framework/base/SecurityManager.php b/framework/base/SecurityManager.php index 3c3b7795d2..441b908757 100644 --- a/framework/base/SecurityManager.php +++ b/framework/base/SecurityManager.php @@ -15,7 +15,7 @@ namespace yii\base; * @author Qiang Xue * @since 2.0 */ -class SecurityManager extends ApplicationComponent +class SecurityManager extends Component { const STATE_VALIDATION_KEY = 'Yii.SecurityManager.validationkey'; const STATE_ENCRYPTION_KEY = 'Yii.SecurityManager.encryptionkey'; diff --git a/framework/base/Theme.php b/framework/base/Theme.php index ec58807651..c1fc94a431 100644 --- a/framework/base/Theme.php +++ b/framework/base/Theme.php @@ -17,7 +17,7 @@ use yii\base\InvalidConfigException; * @author Qiang Xue * @since 2.0 */ -class Theme extends ApplicationComponent +class Theme extends Component { public $basePath; public $baseUrl; diff --git a/framework/base/UrlManager.php b/framework/base/UrlManager.php index 7568a9ebe5..3de8807342 100644 --- a/framework/base/UrlManager.php +++ b/framework/base/UrlManager.php @@ -9,7 +9,7 @@ namespace yii\base; -use \yii\base\ApplicationComponent; +use \yii\base\Component; /** * UrlManager manages the URLs of Yii applications. @@ -123,7 +123,7 @@ use \yii\base\ApplicationComponent; * @author Qiang Xue * @since 2.0 */ -class UrlManager extends ApplicationComponent +class UrlManager extends Component { const CACHE_KEY='Yii.UrlManager.rules'; const GET_FORMAT='get'; diff --git a/framework/db/Connection.php b/framework/db/Connection.php index ecee135bcb..7b31dc5239 100644 --- a/framework/db/Connection.php +++ b/framework/db/Connection.php @@ -9,6 +9,7 @@ namespace yii\db; +use yii\base\Component; use yii\base\InvalidConfigException; use yii\base\NotSupportedException; @@ -70,7 +71,7 @@ use yii\base\NotSupportedException; * } * ~~~ * - * Connection is often used as an [[\yii\base\ApplicationComponent|application component]] and configured in the application + * Connection is often used as an application component and configured in the application * configuration like the following: * * ~~~ @@ -98,7 +99,7 @@ use yii\base\NotSupportedException; * @author Qiang Xue * @since 2.0 */ -class Connection extends \yii\base\ApplicationComponent +class Connection extends Component { /** * @event Event an event that is triggered after a DB connection is established