FileDependency.php 1.36 KB
Newer Older
Qiang Xue committed
1 2 3
<?php
/**
 * @link http://www.yiiframework.com/
Qiang Xue committed
4
 * @copyright Copyright (c) 2008 Yii Software LLC
Qiang Xue committed
5 6 7
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
8 9
namespace yii\caching;

Qiang Xue committed
10
/**
Qiang Xue committed
11
 * FileDependency represents a dependency based on a file's last modification time.
Qiang Xue committed
12
 *
Qiang Xue committed
13 14
 * If th last modification time of the file specified via [[fileName]] is changed,
 * the dependency is considered as changed.
Qiang Xue committed
15 16
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
Qiang Xue committed
17
 * @since 2.0
Qiang Xue committed
18
 */
Qiang Xue committed
19
class FileDependency extends Dependency
Qiang Xue committed
20 21 22
{
	/**
	 * @var string the name of the file whose last modification time is used to
23
	 * check if the dependency has been changed.
Qiang Xue committed
24 25 26 27
	 */
	public $fileName;

	/**
28 29 30
	 * Constructor.
	 * @param string $fileName name of the file whose change is to be checked.
	 * @param array $config name-value pairs that will be used to initialize the object properties
Qiang Xue committed
31
	 */
32
	public function __construct($fileName = null, $config = array())
Qiang Xue committed
33
	{
34 35
		$this->fileName = $fileName;
		parent::__construct($config);
Qiang Xue committed
36 37 38 39 40
	}

	/**
	 * Generates the data needed to determine if dependency has been changed.
	 * This method returns the file's last modification time.
41
	 * @param Cache $cache the cache component that is currently evaluating this dependency
Qiang Xue committed
42 43
	 * @return mixed the data needed to determine if dependency has been changed.
	 */
44
	protected function generateDependencyData($cache)
Qiang Xue committed
45
	{
Qiang Xue committed
46
		return @filemtime($this->fileName);
Qiang Xue committed
47 48
	}
}