CGlobalStateCacheDependency.php 1.6 KB

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