1: <?php
2: /**
3: * CGlobalStateCacheDependency class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CGlobalStateCacheDependency represents a dependency based on a global state value.
13: *
14: * CGlobalStateCacheDependency checks if a global state is changed or not.
15: * If the global state is changed, the dependency is reported as changed.
16: * To specify which global state this dependency should check with,
17: * set {@link stateName} to the name of the global state.
18: *
19: * @author Qiang Xue <qiang.xue@gmail.com>
20: * @package system.caching.dependencies
21: * @since 1.0
22: */
23: class CGlobalStateCacheDependency extends CCacheDependency
24: {
25: /**
26: * @var string the name of the global state whose value is to check
27: * if the dependency has changed.
28: * @see CApplication::setGlobalState
29: */
30: public $stateName;
31:
32: /**
33: * Constructor.
34: * @param string $name the name of the global state
35: */
36: public function __construct($name=null)
37: {
38: $this->stateName=$name;
39: }
40:
41: /**
42: * Generates the data needed to determine if dependency has been changed.
43: * This method returns the value of the global state.
44: * @throws CException if {@link stateName} is empty
45: * @return mixed the data needed to determine if dependency has been changed.
46: */
47: protected function generateDependentData()
48: {
49: if($this->stateName!==null)
50: return Yii::app()->getGlobalState($this->stateName);
51: else
52: throw new CException(Yii::t('yii','CGlobalStateCacheDependency.stateName cannot be empty.'));
53: }
54: }
55: