From 6519da3c925521b6c11e78939e4de3c9d2747be7 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 3 Apr 2013 15:15:03 -0400 Subject: [PATCH] reverted back the previous changes, and fixed ChainedDependency. --- framework/caching/ChainedDependency.php | 20 ++++++-------------- framework/caching/DbDependency.php | 18 ++++++++++-------- framework/caching/ExpressionDependency.php | 13 ++++++++++++- framework/caching/FileDependency.php | 16 +++++++--------- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/framework/caching/ChainedDependency.php b/framework/caching/ChainedDependency.php index af34e9d..7c7058e 100644 --- a/framework/caching/ChainedDependency.php +++ b/framework/caching/ChainedDependency.php @@ -22,11 +22,10 @@ namespace yii\caching; class ChainedDependency extends Dependency { /** - * @var array list of dependencies that this dependency is composed of. - * Each array element should be a dependency object or a configuration array - * that can be used to create a dependency object via [[\Yii::createObject()]]. + * @var Dependency[] list of dependencies that this dependency is composed of. + * Each array element must be a dependency object. */ - public $dependencies = array(); + public $dependencies; /** * @var boolean whether this dependency is depending on every dependency in [[dependencies]]. * Defaults to true, meaning if any of the dependencies has changed, this dependency is considered changed. @@ -37,9 +36,8 @@ class ChainedDependency extends Dependency /** * Constructor. - * @param array $dependencies list of dependencies that this dependency is composed of. - * Each array element should be a dependency object or a configuration array - * that can be used to create a dependency object via [[\Yii::createObject()]]. + * @param Dependency[] $dependencies list of dependencies that this dependency is composed of. + * Each array element should be a dependency object. * @param array $config name-value pairs that will be used to initialize the object properties */ public function __construct($dependencies = array(), $config = array()) @@ -54,9 +52,6 @@ class ChainedDependency extends Dependency public function evaluateDependency() { foreach ($this->dependencies as $dependency) { - if (!$dependency instanceof Dependency) { - $dependency = \Yii::createObject($dependency); - } $dependency->evaluateDependency(); } } @@ -79,10 +74,7 @@ class ChainedDependency extends Dependency */ public function getHasChanged() { - foreach ($this->dependencies as $i => $dependency) { - if (!$dependency instanceof Dependency) { - $this->dependencies[$i] = $dependency = \Yii::createObject($dependency); - } + foreach ($this->dependencies as $dependency) { if ($this->dependOnAll && $dependency->getHasChanged()) { return true; } elseif (!$this->dependOnAll && !$dependency->getHasChanged()) { diff --git a/framework/caching/DbDependency.php b/framework/caching/DbDependency.php index 4308dc1..cbe0ae1 100644 --- a/framework/caching/DbDependency.php +++ b/framework/caching/DbDependency.php @@ -28,23 +28,25 @@ class DbDependency extends Dependency public $db = 'db'; /** * @var string the SQL query whose result is used to determine if the dependency has been changed. - * Only the first row of the query result will be used. This property must be always set, otherwise - * an exception would be raised. + * Only the first row of the query result will be used. */ public $sql; /** * @var array the parameters (name=>value) to be bound to the SQL statement specified by [[sql]]. */ - public $params = array(); + public $params; /** - * Initializes the database dependency object. + * Constructor. + * @param string $sql the SQL query whose result is used to determine if the dependency has been changed. + * @param array $params the parameters (name=>value) to be bound to the SQL statement specified by [[sql]]. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function init() + public function __construct($sql, $params = array(), $config = array()) { - if ($this->sql === null) { - throw new InvalidConfigException('DbDependency::sql must be set.'); - } + $this->sql = $sql; + $this->params = $params; + parent::__construct($config); } /** diff --git a/framework/caching/ExpressionDependency.php b/framework/caching/ExpressionDependency.php index bf70291..e13c962 100644 --- a/framework/caching/ExpressionDependency.php +++ b/framework/caching/ExpressionDependency.php @@ -22,7 +22,18 @@ class ExpressionDependency extends Dependency /** * @var string the PHP expression whose result is used to determine the dependency. */ - public $expression = 'true'; + public $expression; + + /** + * Constructor. + * @param string $expression the PHP expression whose result is used to determine the dependency. + * @param array $config name-value pairs that will be used to initialize the object properties + */ + public function __construct($expression = 'true', $config = array()) + { + $this->expression = $expression; + parent::__construct($config); + } /** * Generates the data needed to determine if dependency has been changed. diff --git a/framework/caching/FileDependency.php b/framework/caching/FileDependency.php index 8d858ec..3797dde 100644 --- a/framework/caching/FileDependency.php +++ b/framework/caching/FileDependency.php @@ -7,8 +7,6 @@ namespace yii\caching; -use yii\base\InvalidConfigException; - /** * FileDependency represents a dependency based on a file's last modification time. * @@ -22,19 +20,19 @@ class FileDependency extends Dependency { /** * @var string the name of the file whose last modification time is used to - * check if the dependency has been changed. This property must be always set, - * otherwise an exception would be raised. + * check if the dependency has been changed. */ public $fileName; /** - * Initializes the database dependency object. + * Constructor. + * @param string $fileName name of the file whose change is to be checked. + * @param array $config name-value pairs that will be used to initialize the object properties */ - public function init() + public function __construct($fileName = null, $config = array()) { - if ($this->file === null) { - throw new InvalidConfigException('FileDependency::fileName must be set.'); - } + $this->fileName = $fileName; + parent::__construct($config); } /**