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