system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CDirectoryCacheDependency

system.caching.dependencies
继承 class CDirectoryCacheDependency » CCacheDependency » CComponent
实现 ICacheDependency
可用自 1.0
源码 framework/caching/dependencies/CDirectoryCacheDependency.php
CDirectoryCacheDependency represents a dependency based on change of a directory.

CDirectoryCacheDependency performs dependency checking based on the modification time of the files contained in the specified directory. The directory being checked is specified via directory.

By default, all files under the specified directory and subdirectories will be checked. If the last modification time of any of them is changed or if different number of files are contained in a directory, the dependency is reported as changed. By specifying recursiveLevel, one can limit the checking to a certain depth of the directory.

Note, dependency checking for a directory is expensive because it involves accessing modification time of multiple files under the directory.

公共属性

隐藏继承的属性

属性类型描述被定义在
dependentData mixed the data used to determine if dependency has been changed. CCacheDependency
directory string the directory whose change is used to determine if the dependency has been changed. CDirectoryCacheDependency
hasChanged boolean whether the dependency has changed. CCacheDependency
namePattern string the regular expression matching valid file/directory names. CDirectoryCacheDependency
recursiveLevel integer the depth of the subdirectories to be recursively checked. CDirectoryCacheDependency
reuseDependentData boolean Whether this dependency is reusable or not. CCacheDependency

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CDirectoryCacheDependency
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateDependency() Evaluates the dependency by generating and saving the data related with dependency. CCacheDependency
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getDependentData() Returns the data used to determine if dependency has been changed. This data is available after evaluateDependency is called. CCacheDependency
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getHasChanged() Returns whether the dependency has changed. CCacheDependency
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent
resetReusableData() Resets cached data for reusable dependencies. CCacheDependency

受保护的方法

隐藏继承的方法

方法描述被定义在
generateDependentData() Generates the data needed to determine if dependency has been changed. CDirectoryCacheDependency
generateTimestamps() Determines the last modification time for files under the directory. CDirectoryCacheDependency
validateDirectory() Checks to see if the specified subdirectory should be checked for dependency. CDirectoryCacheDependency
validateFile() Checks to see if the file should be checked for dependency. CDirectoryCacheDependency

属性详情

directory 属性
public string $directory;

the directory whose change is used to determine if the dependency has been changed. If any of the files under the directory is changed, the dependency is considered as changed.

namePattern 属性
public string $namePattern;

the regular expression matching valid file/directory names. Only the matching files or directories will be checked for changes. Defaults to null, meaning all files/directories will qualify.

recursiveLevel 属性
public integer $recursiveLevel;

the depth of the subdirectories to be recursively checked. If the value is less than 0, it means unlimited depth. If the value is 0, it means checking the files directly under the specified directory.

方法详情

__construct() 方法
public void __construct(string $directory=NULL)
$directory string the directory to be checked
源码: framework/caching/dependencies/CDirectoryCacheDependency.php#55 (显示)
public function __construct($directory=null)
{
    
$this->directory=$directory;
}

Constructor.

generateDependentData() 方法
protected mixed generateDependentData()
{return} mixed the data needed to determine if dependency has been changed.
源码: framework/caching/dependencies/CDirectoryCacheDependency.php#66 (显示)
protected function generateDependentData()
{
    if(
$this->directory!==null)
        return 
$this->generateTimestamps($this->directory);
    else
        throw new 
CException(Yii::t('yii','CDirectoryCacheDependency.directory cannot be empty.'));
}

Generates the data needed to determine if dependency has been changed. This method returns the modification timestamps for files under the directory.

generateTimestamps() 方法
protected array generateTimestamps(string $directory, integer $level=0)
$directory string the directory name
$level integer level of the recursion
{return} array list of file modification time indexed by the file path
源码: framework/caching/dependencies/CDirectoryCacheDependency.php#82 (显示)
protected function generateTimestamps($directory,$level=0)
{
    if((
$dir=@opendir($directory))===false)
        throw new 
CException(Yii::t('yii','"{path}" is not a valid directory.',
            array(
'{path}'=>$directory)));
    
$timestamps=array();
    while((
$file=readdir($dir))!==false)
    {
        
$path=$directory.DIRECTORY_SEPARATOR.$file;
        if(
$file==='.' || $file==='..')
            continue;
        if(
$this->namePattern!==null && !preg_match($this->namePattern,$file))
            continue;
        if(
is_file($path))
        {
            if(
$this->validateFile($path))
                
$timestamps[$path]=filemtime($path);
        }
        else
        {
            if((
$this->recursiveLevel<|| $level<$this->recursiveLevel) && $this->validateDirectory($path))
                
$timestamps=array_merge($timestamps$this->generateTimestamps($path,$level+1));
        }
    }
    
closedir($dir);
    return 
$timestamps;
}

Determines the last modification time for files under the directory. This method may go recursively into subdirectories if recursiveLevel is not 0.

validateDirectory() 方法
protected boolean validateDirectory(string $directory)
$directory string the name of the subdirectory that may be checked for dependency.
{return} boolean whether this subdirectory should be checked.
源码: framework/caching/dependencies/CDirectoryCacheDependency.php#131 (显示)
protected function validateDirectory($directory)
{
    return 
true;
}

Checks to see if the specified subdirectory should be checked for dependency. This method is invoked when dependency of the whole directory is being checked. By default, it always returns true, meaning the subdirectory should be checked. You may override this method to check only certain subdirectories.

validateFile() 方法
protected boolean validateFile(string $fileName)
$fileName string the name of the file that may be checked for dependency.
{return} boolean whether this file should be checked.
源码: framework/caching/dependencies/CDirectoryCacheDependency.php#118 (显示)
protected function validateFile($fileName)
{
    return 
true;
}

Checks to see if the file should be checked for dependency. This method is invoked when dependency of the whole directory is being checked. By default, it always returns true, meaning the file should be checked. You may override this method to check only certain files.