@ -10,16 +10,12 @@ 
			
		
	
		
		
			
				
					
					namespace yii\caching; namespace yii\caching;  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					/** /**  
			
		
	
		
		
			
				
					
					 * ChainedDependency represents a list of cache  dependencies.  * ChainedDependency represents a dependency which is composed of a list of other  dependencies.  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 *  *  
			
		
	
		
		
			
				
					
					 * If any of the dependencies reports a dependency change, ChainedDependency  * When [[dependOnAll]] is true, if any of the dependencies has changed, this dependency is  
			
				
				
			
		
	
		
		
			
				
					
					 * will return true for the checking.  * considered changed; When [[dependOnAll]] is false, if one of the dependencies has NOT changed,  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 * this dependency is considered NOT changed.  
			
		
	
		
		
			
				
					
					 *  *  
			
		
	
		
		
			
				
					
					 * To add dependencies to ChainedDependency, use {@link getDependencies Dependencies}  
			
		
	
		
		
			
				
					
					 * which gives a {@link CTypedList} instance and can be used like an array  
			
		
	
		
		
			
				
					
					 * (see {@link CList} for more details}).  
			
		
	
		
		
			
				
					
					 *  
			
		
	
		
		
			
				
					
					 * @property CTypedList $dependencies List of dependency objects.  
			
		
	
		
		
			
				
					
					 * @property boolean $hasChanged Whether the dependency is changed or not.  * @property boolean $hasChanged Whether the dependency is changed or not.  
			
		
	
		
		
			
				
					
					 *  *  
			
		
	
		
		
			
				
					
					 * @author Qiang Xue < qiang.xue @ gmail . com >   * @author Qiang Xue < qiang.xue @ gmail . com >   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -27,55 +23,52 @@ namespace yii\caching; 
			
		
	
		
		
			
				
					
					 */  */  
			
		
	
		
		
			
				
					
					class ChainedDependency extends Dependency class ChainedDependency extends Dependency  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
						private $_dependencies=null;  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
						/** 	/**  
			
		
	
		
		
			
				
					
						 * Constructor . 	 * @var array list of dependencies that this dependency is composed of.  
			
				
				
			
		
	
		
		
			
				
					
						 * @param array $dependencies the dependencies to be added to this chain.  	 * Each array element should be a dependency object or a configuration array   
			
				
				
			
		
	
		
		
			
				
					
						 * @since 1.1.4  	 * that can be used to create a dependency object via [[\Yii::createObject()]].   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
						 */ 	 */  
			
		
	
		
		
			
				
					
						public function __construct($dependencies=array()) 	public $dependencies = array();  
			
				
				
			
		
	
		
		
			
				
					
						{ 	/**  
			
				
				
			
		
	
		
		
			
				
					
							if(!empty($dependencies)) 	 * @var boolean whether this dependency is depending on every dependency in [[dependencies]].  
			
				
				
			
		
	
		
		
			
				
					
								$this->setDependencies($dependencies); 	 * Defaults to true, meaning if any of the dependencies has changed, this dependency is considered changed.  
			
				
				
			
		
	
		
		
			
				
					
						} 	 * When it is set false, it means if one of the dependencies has NOT changed, this dependency  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
						 * is considered NOT changed.  
			
		
	
		
		
			
				
					
						 */  
			
		
	
		
		
			
				
					
						public $dependOnAll = true;  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
						/** 	/**  
			
		
	
		
		
			
				
					
						 * @return CTypedList list of dependency objects 	 * 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()]].  
			
		
	
		
		
			
				
					
						 */ 	 */  
			
		
	
		
		
			
				
					
						public function getDependencies() 	public function __construct($dependencies = array() )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
						{ 	{  
			
		
	
		
		
			
				
					
							if($this->_dependencies===null) 		$this->dependencies = $dependencies;  
			
				
				
			
		
	
		
		
			
				
					
								$this->_dependencies=new CTypedList('ICacheDependency');  
			
		
	
		
		
			
				
					
							return $this->_dependencies;  
			
		
	
		
		
	
		
		
			
				
					
						} 	}  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
						/** 	/**  
			
		
	
		
		
			
				
					
						 * @param array $values list of dependency objects or configurations to be added to this chain. 	 * Evaluates the dependency by generating and saving the data related with dependency.  
			
				
				
			
		
	
		
		
			
				
					
						 * If a depedency is specified as a configuration, it must be an array that can be recognized  
			
		
	
		
		
			
				
					
						 * by {@link YiiBase::createComponent}.  
			
		
	
		
		
	
		
		
			
				
					
						 */ 	 */  
			
		
	
		
		
			
				
					
						public function setDependencies($values) 	public function evaluateDependency()  
			
				
				
			
		
	
		
		
			
				
					
						{  
			
		
	
		
		
			
				
					
							$dependencies=$this->getDependencies();  
			
		
	
		
		
			
				
					
							foreach($values as $value)  
			
		
	
		
		
	
		
		
			
				
					
						{ 	{  
			
		
	
		
		
			
				
					
								if(is_array($value)) 		foreach ($this->dependencies as $dependency) {  
			
				
				
			
		
	
		
		
			
				
					
									$value=Yii::createComponent($value); 			if (!$dependency instanceof Dependency) {  
			
				
				
			
		
	
		
		
			
				
					
								$dependencies->add($value); 				$dependency = \Yii::createObject($dependency);  
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
								}  
			
		
	
		
		
			
				
					
								$dependency->evalulateDependency();  
			
		
	
		
		
			
				
					
							} 		}  
			
		
	
		
		
			
				
					
						} 	}  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
						/** 	/**  
			
		
	
		
		
			
				
					
						 * Evaluates the dependency by generating and saving the data related with dependency. 	 * Generates the data needed to determine if dependency has been changed.  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
						 * This method does nothing in this class.  
			
		
	
		
		
			
				
					
						 * @return mixed the data needed to determine if dependency has been changed.  
			
		
	
		
		
			
				
					
						 */ 	 */  
			
		
	
		
		
			
				
					
						public function evaluateDependency() 	protected function generateDependencyData ()  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
						{ 	{  
			
		
	
		
		
			
				
					
							if($this->_dependencies!==null) 		return null;  
			
				
				
			
		
	
		
		
			
				
					
							{  
			
		
	
		
		
			
				
					
								foreach($this->_dependencies as $dependency)  
			
		
	
		
		
			
				
					
									$dependency->evaluateDependency();  
			
		
	
		
		
			
				
					
							}  
			
		
	
		
		
	
		
		
			
				
					
						} 	}  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
						/** 	/**  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -86,12 +79,16 @@ class ChainedDependency extends Dependency 
			
		
	
		
		
			
				
					
						 */ 	 */  
			
		
	
		
		
			
				
					
						public function getHasChanged() 	public function getHasChanged()  
			
		
	
		
		
			
				
					
						{ 	{  
			
		
	
		
		
			
				
					
							if($this->_dependencies!==null) 		foreach ($this->dependencies as $dependency) {  
			
				
				
			
		
	
		
		
			
				
					
							{ 			if (!$dependency instanceof Dependency) {  
			
				
				
			
		
	
		
		
			
				
					
								foreach($this->_dependencies as $dependency) 				$dependency = \Yii::createObject($dependency);  
			
				
				
			
		
	
		
		
			
				
					
									if($dependency->getHasChanged())  
			
		
	
		
		
			
				
					
										return true;  
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
								} 			}  
			
		
	
		
		
			
				
					
								if ($this->dependOnAll & &  $dependency->getHasChanged()) {  
			
		
	
		
		
			
				
					
									return true;  
			
		
	
		
		
			
				
					
								} elseif (!$this->dependOnAll & &  !$dependency->getHasChanged()) {  
			
		
	
		
		
			
				
					
									return false; 				return false;  
			
		
	
		
		
			
				
					
								} 			}  
			
		
	
		
		
			
				
					
							}  
			
		
	
		
		
			
				
					
							return !$this->dependOnAll;  
			
		
	
		
		
			
				
					
						}  
			
		
	
		
		
			
				
					
					} }