2010-08-21 04:43:03 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
|
|
/**
|
|
|
|
* [Kohana Cache](api/Kohana_Cache) File driver. Provides a file based
|
|
|
|
* driver for the Kohana Cache library. This is one of the slowest
|
|
|
|
* caching methods.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* ### Configuration example
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* Below is an example of a _file_ server configuration.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* return array(
|
|
|
|
* 'file' => array( // File driver group
|
|
|
|
* 'driver' => 'file', // using File driver
|
|
|
|
* 'cache_dir' => APPPATH.'cache/.kohana_cache', // Cache location
|
|
|
|
* ),
|
|
|
|
* )
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* In cases where only one cache group is required, if the group is named `default` there is
|
|
|
|
* no need to pass the group name when instantiating a cache instance.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* #### General cache group configuration settings
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* Below are the settings available to all types of cache driver.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* Name | Required | Description
|
|
|
|
* -------------- | -------- | ---------------------------------------------------------------
|
|
|
|
* driver | __YES__ | (_string_) The driver type to use
|
|
|
|
* cache_dir | __NO__ | (_string_) The cache directory to use for this cache instance
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* ### System requirements
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* * Kohana 3.0.x
|
|
|
|
* * PHP 5.2.4 or greater
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2011-05-13 06:00:25 +00:00
|
|
|
* @package Kohana/Cache
|
|
|
|
* @category Base
|
2010-08-21 04:43:03 +00:00
|
|
|
* @author Kohana Team
|
2012-11-09 12:18:50 +00:00
|
|
|
* @copyright (c) 2009-2012 Kohana Team
|
2010-08-21 04:43:03 +00:00
|
|
|
* @license http://kohanaphp.com/license
|
|
|
|
*/
|
2012-11-09 12:18:50 +00:00
|
|
|
class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
|
2010-08-21 04:43:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a hashed filename based on the string. This is used
|
|
|
|
* to create shorter unique IDs for each cache filename.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Create the cache filename
|
|
|
|
* $filename = Cache_File::filename($this->_sanitize_id($id));
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $string string to hash into filename
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected static function filename($string)
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
return sha1($string).'.cache';
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string the caching directory
|
|
|
|
*/
|
|
|
|
protected $_cache_dir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs the file cache driver. This method cannot be invoked externally. The file cache driver must
|
|
|
|
* be instantiated using the `Cache::instance()` method.
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param array $config config
|
|
|
|
* @throws Cache_Exception
|
2010-08-21 04:43:03 +00:00
|
|
|
*/
|
|
|
|
protected function __construct(array $config)
|
|
|
|
{
|
|
|
|
// Setup parent
|
|
|
|
parent::__construct($config);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-05-13 06:00:25 +00:00
|
|
|
$directory = Arr::get($this->_config, 'cache_dir', Kohana::$cache_dir);
|
|
|
|
$this->_cache_dir = new SplFileInfo($directory);
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
2011-05-13 06:00:25 +00:00
|
|
|
// PHP < 5.3 exception handle
|
|
|
|
catch (ErrorException $e)
|
|
|
|
{
|
|
|
|
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
|
|
|
|
}
|
|
|
|
// PHP >= 5.3 exception handle
|
2010-08-21 04:43:03 +00:00
|
|
|
catch (UnexpectedValueException $e)
|
|
|
|
{
|
2011-05-13 06:00:25 +00:00
|
|
|
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the defined directory is a file, get outta here
|
|
|
|
if ($this->_cache_dir->isFile())
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception('Unable to create cache directory as a file already exists : :resource', array(':resource' => $this->_cache_dir->getRealPath()));
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the read status of the directory
|
|
|
|
if ( ! $this->_cache_dir->isReadable())
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception('Unable to read from the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the write status of the directory
|
|
|
|
if ( ! $this->_cache_dir->isWritable())
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception('Unable to write to the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a cached value entry by id.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Retrieve cache entry from file group
|
|
|
|
* $data = Cache::instance('file')->get('foo');
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Retrieve cache entry from file group and return 'bar' if miss
|
|
|
|
* $data = Cache::instance('file')->get('foo', 'bar');
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $id id of cache to entry
|
|
|
|
* @param string $default default value to return if cache miss
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return mixed
|
2012-11-09 12:18:50 +00:00
|
|
|
* @throws Cache_Exception
|
2010-08-21 04:43:03 +00:00
|
|
|
*/
|
|
|
|
public function get($id, $default = NULL)
|
|
|
|
{
|
|
|
|
$filename = Cache_File::filename($this->_sanitize_id($id));
|
|
|
|
$directory = $this->_resolve_directory($filename);
|
|
|
|
|
|
|
|
// Wrap operations in try/catch to handle notices
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Open file
|
|
|
|
$file = new SplFileInfo($directory.$filename);
|
|
|
|
|
|
|
|
// If file does not exist
|
2011-05-13 06:00:25 +00:00
|
|
|
if ( ! $file->isFile())
|
2010-08-21 04:43:03 +00:00
|
|
|
{
|
|
|
|
// Return default value
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
// Open the file and parse data
|
|
|
|
$created = $file->getMTime();
|
|
|
|
$data = $file->openFile();
|
|
|
|
$lifetime = $data->fgets();
|
|
|
|
|
|
|
|
// If we're at the EOF at this point, corrupted!
|
|
|
|
if ($data->eof())
|
|
|
|
{
|
|
|
|
throw new Cache_Exception(__METHOD__.' corrupted cache file!');
|
|
|
|
}
|
2010-08-21 04:43:03 +00:00
|
|
|
|
2012-11-09 12:18:50 +00:00
|
|
|
$cache = '';
|
|
|
|
|
|
|
|
while ($data->eof() === FALSE)
|
|
|
|
{
|
|
|
|
$cache .= $data->fgets();
|
|
|
|
}
|
2010-08-21 04:43:03 +00:00
|
|
|
|
|
|
|
// Test the expiry
|
2012-11-09 12:18:50 +00:00
|
|
|
if (($created + (int) $lifetime) < time())
|
2010-08-21 04:43:03 +00:00
|
|
|
{
|
|
|
|
// Delete the file
|
|
|
|
$this->_delete_file($file, NULL, TRUE);
|
|
|
|
return $default;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
return unserialize($cache);
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-09 12:18:50 +00:00
|
|
|
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
catch (ErrorException $e)
|
|
|
|
{
|
|
|
|
// Handle ErrorException caused by failed unserialization
|
|
|
|
if ($e->getCode() === E_NOTICE)
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception(__METHOD__.' failed to unserialize cached object with message : '.$e->getMessage());
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise throw the exception
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a value to cache with id and lifetime
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* $data = 'bar';
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Set 'bar' to 'foo' in file group, using default expiry
|
|
|
|
* Cache::instance('file')->set('foo', $data);
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Set 'bar' to 'foo' in file group for 30 seconds
|
|
|
|
* Cache::instance('file')->set('foo', $data, 30);
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $id id of cache entry
|
|
|
|
* @param string $data data to set to cache
|
|
|
|
* @param integer $lifetime lifetime in seconds
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function set($id, $data, $lifetime = NULL)
|
|
|
|
{
|
|
|
|
$filename = Cache_File::filename($this->_sanitize_id($id));
|
|
|
|
$directory = $this->_resolve_directory($filename);
|
|
|
|
|
|
|
|
// If lifetime is NULL
|
|
|
|
if ($lifetime === NULL)
|
|
|
|
{
|
|
|
|
// Set to the default expiry
|
|
|
|
$lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open directory
|
|
|
|
$dir = new SplFileInfo($directory);
|
|
|
|
|
|
|
|
// If the directory path is not a directory
|
|
|
|
if ( ! $dir->isDir())
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
// Create the directory
|
2010-08-21 04:43:03 +00:00
|
|
|
if ( ! mkdir($directory, 0777, TRUE))
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception(__METHOD__.' unable to create directory : :directory', array(':directory' => $directory));
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// chmod to solve potential umask issues
|
|
|
|
chmod($directory, 0777);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open file to inspect
|
|
|
|
$resouce = new SplFileInfo($directory.$filename);
|
|
|
|
$file = $resouce->openFile('w');
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
$data = $lifetime."\n".serialize($data);
|
|
|
|
$file->fwrite($data, strlen($data));
|
|
|
|
return (bool) $file->fflush();
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
catch (ErrorException $e)
|
|
|
|
{
|
|
|
|
// If serialize through an error exception
|
|
|
|
if ($e->getCode() === E_NOTICE)
|
|
|
|
{
|
|
|
|
// Throw a caching error
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception(__METHOD__.' failed to serialize data for caching with message : '.$e->getMessage());
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Else rethrow the error exception
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a cache entry based on id
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Delete 'foo' entry from the file group
|
|
|
|
* Cache::instance('file')->delete('foo');
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $id id to remove from cache
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function delete($id)
|
|
|
|
{
|
|
|
|
$filename = Cache_File::filename($this->_sanitize_id($id));
|
|
|
|
$directory = $this->_resolve_directory($filename);
|
|
|
|
|
|
|
|
return $this->_delete_file(new SplFileInfo($directory.$filename), NULL, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all cache entries.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* Beware of using this method when
|
|
|
|
* using shared memory cache systems, as it will wipe every
|
|
|
|
* entry within the system for all clients.
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Delete all cache entries in the file group
|
|
|
|
* Cache::instance('file')->delete_all();
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function delete_all()
|
|
|
|
{
|
|
|
|
return $this->_delete_file($this->_cache_dir, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Garbage collection method that cleans any expired
|
|
|
|
* cache entries from the cache.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function garbage_collect()
|
|
|
|
{
|
|
|
|
$this->_delete_file($this->_cache_dir, TRUE, FALSE, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes files recursively and returns FALSE on any errors
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Delete a file or folder whilst retaining parent directory and ignore all errors
|
|
|
|
* $this->_delete_file($folder, TRUE, TRUE);
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param SplFileInfo $file file
|
|
|
|
* @param boolean $retain_parent_directory retain the parent directory
|
|
|
|
* @param boolean $ignore_errors ignore_errors to prevent all exceptions interrupting exec
|
|
|
|
* @param boolean $only_expired only expired files
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return boolean
|
2012-11-09 12:18:50 +00:00
|
|
|
* @throws Cache_Exception
|
2010-08-21 04:43:03 +00:00
|
|
|
*/
|
|
|
|
protected function _delete_file(SplFileInfo $file, $retain_parent_directory = FALSE, $ignore_errors = FALSE, $only_expired = FALSE)
|
|
|
|
{
|
|
|
|
// Allow graceful error handling
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// If is file
|
|
|
|
if ($file->isFile())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
// Handle ignore files
|
|
|
|
if (in_array($file->getFilename(), $this->config('ignore_on_delete')))
|
|
|
|
{
|
|
|
|
$delete = FALSE;
|
|
|
|
}
|
2010-08-21 04:43:03 +00:00
|
|
|
// If only expired is not set
|
2012-11-09 12:18:50 +00:00
|
|
|
elseif ($only_expired === FALSE)
|
2010-08-21 04:43:03 +00:00
|
|
|
{
|
|
|
|
// We want to delete the file
|
|
|
|
$delete = TRUE;
|
|
|
|
}
|
|
|
|
// Otherwise...
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Assess the file expiry to flag it for deletion
|
|
|
|
$json = $file->openFile('r')->current();
|
|
|
|
$data = json_decode($json);
|
|
|
|
$delete = $data->expiry < time();
|
|
|
|
}
|
|
|
|
|
2012-11-09 12:18:50 +00:00
|
|
|
// If the delete flag is set delete file
|
2010-08-21 04:43:03 +00:00
|
|
|
if ($delete === TRUE)
|
2012-11-09 12:18:50 +00:00
|
|
|
return unlink($file->getRealPath());
|
|
|
|
else
|
|
|
|
return FALSE;
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
catch (ErrorException $e)
|
|
|
|
{
|
|
|
|
// Catch any delete file warnings
|
|
|
|
if ($e->getCode() === E_WARNING)
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception(__METHOD__.' failed to delete file : :file', array(':file' => $file->getRealPath()));
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Else, is directory
|
2011-05-13 06:00:25 +00:00
|
|
|
elseif ($file->isDir())
|
2010-08-21 04:43:03 +00:00
|
|
|
{
|
|
|
|
// Create new DirectoryIterator
|
|
|
|
$files = new DirectoryIterator($file->getPathname());
|
|
|
|
|
|
|
|
// Iterate over each entry
|
|
|
|
while ($files->valid())
|
|
|
|
{
|
|
|
|
// Extract the entry name
|
|
|
|
$name = $files->getFilename();
|
|
|
|
|
|
|
|
// If the name is not a dot
|
2012-11-09 12:18:50 +00:00
|
|
|
if ($name != '.' AND $name != '..')
|
2010-08-21 04:43:03 +00:00
|
|
|
{
|
|
|
|
// Create new file resource
|
|
|
|
$fp = new SplFileInfo($files->getRealPath());
|
|
|
|
// Delete the file
|
|
|
|
$this->_delete_file($fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move the file pointer on
|
|
|
|
$files->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If set to retain parent directory, return now
|
|
|
|
if ($retain_parent_directory)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Remove the files iterator
|
|
|
|
// (fixes Windows PHP which has permission issues with open iterators)
|
|
|
|
unset($files);
|
|
|
|
|
|
|
|
// Try to remove the parent directory
|
|
|
|
return rmdir($file->getRealPath());
|
|
|
|
}
|
|
|
|
catch (ErrorException $e)
|
|
|
|
{
|
|
|
|
// Catch any delete directory warnings
|
|
|
|
if ($e->getCode() === E_WARNING)
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception(__METHOD__.' failed to delete directory : :directory', array(':directory' => $file->getRealPath()));
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
2012-11-09 12:18:50 +00:00
|
|
|
throw $e;
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-09 12:18:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// We get here if a file has already been deleted
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|
|
|
|
// Catch all exceptions
|
|
|
|
catch (Exception $e)
|
|
|
|
{
|
|
|
|
// If ignore_errors is on
|
|
|
|
if ($ignore_errors === TRUE)
|
|
|
|
{
|
|
|
|
// Return
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
// Throw exception
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves the cache directory real path from the filename
|
2012-11-09 12:18:50 +00:00
|
|
|
*
|
2010-08-21 04:43:03 +00:00
|
|
|
* // Get the realpath of the cache folder
|
|
|
|
* $realpath = $this->_resolve_directory($filename);
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @param string $filename filename to resolve
|
2010-08-21 04:43:03 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function _resolve_directory($filename)
|
|
|
|
{
|
|
|
|
return $this->_cache_dir->getRealPath().DIRECTORY_SEPARATOR.$filename[0].$filename[1].DIRECTORY_SEPARATOR;
|
|
|
|
}
|
2011-05-13 06:00:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the cache directory if it doesn't exist. Simply a wrapper for
|
|
|
|
* `mkdir` to ensure DRY principles
|
|
|
|
*
|
2012-11-09 12:18:50 +00:00
|
|
|
* @link http://php.net/manual/en/function.mkdir.php
|
|
|
|
* @param string $directory
|
|
|
|
* @param integer $mode
|
|
|
|
* @param boolean $recursive
|
|
|
|
* @param resource $context
|
2011-05-13 06:00:25 +00:00
|
|
|
* @return SplFileInfo
|
2012-11-09 12:18:50 +00:00
|
|
|
* @throws Cache_Exception
|
2011-05-13 06:00:25 +00:00
|
|
|
*/
|
|
|
|
protected function _make_directory($directory, $mode = 0777, $recursive = FALSE, $context = NULL)
|
|
|
|
{
|
|
|
|
if ( ! mkdir($directory, $mode, $recursive, $context))
|
|
|
|
{
|
2012-11-09 12:18:50 +00:00
|
|
|
throw new Cache_Exception('Failed to create the defined cache directory : :directory', array(':directory' => $directory));
|
2011-05-13 06:00:25 +00:00
|
|
|
}
|
|
|
|
chmod($directory, $mode);
|
|
|
|
|
2012-11-09 12:18:50 +00:00
|
|
|
return new SplFileInfo($directory);
|
2011-05-13 06:00:25 +00:00
|
|
|
}
|
2010-08-21 04:43:03 +00:00
|
|
|
}
|