您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FileDependency.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\caching;
  8. use Yii;
  9. use yii\base\InvalidConfigException;
  10. /**
  11. * FileDependency represents a dependency based on a file's last modification time.
  12. *
  13. * If the last modification time of the file specified via [[fileName]] is changed,
  14. * the dependency is considered as changed.
  15. *
  16. * @author Qiang Xue <qiang.xue@gmail.com>
  17. * @since 2.0
  18. */
  19. class FileDependency extends Dependency
  20. {
  21. /**
  22. * @var string the file path or path alias whose last modification time is used to
  23. * check if the dependency has been changed.
  24. */
  25. public $fileName;
  26. /**
  27. * Generates the data needed to determine if dependency has been changed.
  28. * This method returns the file's last modification time.
  29. * @param Cache $cache the cache component that is currently evaluating this dependency
  30. * @return mixed the data needed to determine if dependency has been changed.
  31. * @throws InvalidConfigException if [[fileName]] is not set
  32. */
  33. protected function generateDependencyData($cache)
  34. {
  35. if ($this->fileName === null) {
  36. throw new InvalidConfigException('FileDependency::fileName must be set');
  37. }
  38. return @filemtime(Yii::getAlias($this->fileName));
  39. }
  40. }