CFileCacheDependency.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * CFileCacheDependency 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. * CFileCacheDependency represents a dependency based on a file's last modification time.
  12. *
  13. * CFileCacheDependency performs dependency checking based on the
  14. * last modification time of the file specified via {@link fileName}.
  15. * The dependency is reported as unchanged if and only if the file's
  16. * last modification time remains unchanged.
  17. *
  18. * @author Qiang Xue <qiang.xue@gmail.com>
  19. * @package system.caching.dependencies
  20. * @since 1.0
  21. */
  22. class CFileCacheDependency extends CCacheDependency
  23. {
  24. /**
  25. * @var string the name of the file whose last modification time is used to
  26. * check if the dependency has been changed.
  27. */
  28. public $fileName;
  29. /**
  30. * Constructor.
  31. * @param string $fileName name of the file whose change is to be checked.
  32. */
  33. public function __construct($fileName=null)
  34. {
  35. $this->fileName=$fileName;
  36. }
  37. /**
  38. * Generates the data needed to determine if dependency has been changed.
  39. * This method returns the file's last modification time.
  40. * @throws CException if {@link fileName} is empty
  41. * @return mixed the data needed to determine if dependency has been changed.
  42. */
  43. protected function generateDependentData()
  44. {
  45. if($this->fileName!==null)
  46. return @filemtime($this->fileName);
  47. else
  48. throw new CException(Yii::t('yii','CFileCacheDependency.fileName cannot be empty.'));
  49. }
  50. }