FileDependency.php 1.35 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
namespace yii\caching;
9

10
use Yii;
11
use yii\base\InvalidConfigException;
Qiang Xue committed
12

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

30

31 32 33
    /**
     * Generates the data needed to determine if dependency has been changed.
     * This method returns the file's last modification time.
34 35
     * @param Cache $cache the cache component that is currently evaluating this dependency
     * @return mixed the data needed to determine if dependency has been changed.
36 37 38 39 40 41 42 43
     * @throws InvalidConfigException if [[fileName]] is not set
     */
    protected function generateDependencyData($cache)
    {
        if ($this->fileName === null) {
            throw new InvalidConfigException('FileDependency::fileName must be set');
        }

44
        return @filemtime(Yii::getAlias($this->fileName));
45
    }
Qiang Xue committed
46
}