FileDependency.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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\base\InvalidConfigException;
  9. /**
  10. * FileDependency represents a dependency based on a file's last modification time.
  11. *
  12. * If th last modification time of the file specified via [[fileName]] is changed,
  13. * the dependency is considered as changed.
  14. *
  15. * @author Qiang Xue <[email protected]>
  16. * @since 2.0
  17. */
  18. class FileDependency extends Dependency
  19. {
  20. /**
  21. * @var string the name of the file whose last modification time is used to
  22. * check if the dependency has been changed.
  23. */
  24. public $fileName;
  25. /**
  26. * Generates the data needed to determine if dependency has been changed.
  27. * This method returns the file's last modification time.
  28. * @param Cache $cache the cache component that is currently evaluating this dependency
  29. * @return mixed the data needed to determine if dependency has been changed.
  30. * @throws InvalidConfigException if [[fileName]] is not set
  31. */
  32. protected function generateDependencyData($cache)
  33. {
  34. if ($this->fileName === null) {
  35. throw new InvalidConfigException('FileDependency::fileName must be set');
  36. }
  37. return @filemtime($this->fileName);
  38. }
  39. }