Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Cache_Backend_File Class Reference

A slight extension to Zend's File backend to add support for our 'namespace' option. More...

List of all members.

Public Member Functions

 __construct (array $options=array())
 Extend parent to add the 'namespace' option.
 setOption ($name, $value)
 Extends parent to work the 'namespace' option into the existing 'file_name_prefix' option.

Detailed Description

A slight extension to Zend's File backend to add support for our 'namespace' option.

We implemented namespace support by mapping the 'namespace' option over to the existing 'file_name_prefix'.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Constructor & Destructor Documentation

P4Cms_Cache_Backend_File::__construct ( array $  options = array())

Extend parent to add the 'namespace' option.

Parameters:
array$optionsassociative array of options
    {
        $this->_options['namespace'] = false;
        return parent::__construct($options);
    }

Member Function Documentation

P4Cms_Cache_Backend_File::setOption ( name,
value 
)

Extends parent to work the 'namespace' option into the existing 'file_name_prefix' option.

Parameters:
string$namethe option name
mixed$valuethe options value
    {   
        // if we aren't touching a related setting let parent handle it
        if ($name != 'namespace' && $name != 'file_name_prefix') {
             parent::setOption($name, $value);
             return;
        }
        
        // pull out references to the namespace and file_name_prefix
        // then calculate our current namespaced based suffix.
        $namespace =& $this->_options['namespace'];
        $prefix    =& $this->_options['file_name_prefix'];
        $suffix    =  $namespace ? ('_' . md5($namespace)) : '';

        // strip the current namespace based suffix from the file
        // name prefix if its present
        if (substr($prefix, strlen($suffix) * -1) == $suffix) {
            $prefix = substr($prefix, 0, strlen($prefix) - strlen($suffix));
        }

        // let parent update the namespace/file_name_prefix
        parent::setOption($name, $value);

        // namespace may have changed; re-calculate suffix and
        // tack it onto our file_name_prefix
        $suffix = $namespace ? ('_' . md5($namespace)) : '';
        $this->_options['file_name_prefix'] = $prefix . $suffix;
    }

The documentation for this class was generated from the following file: