Upgrade to KH 3.1.3.1

This commit is contained in:
Deon George
2011-05-13 16:00:25 +10:00
parent 8013aadc4c
commit 6d256839fc
675 changed files with 22771 additions and 24111 deletions

View File

@@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Cache_Wincache extends Kohana_Cache_Wincache {}

View File

@@ -67,8 +67,8 @@
* * Kohana 3.0.x
* * PHP 5.2.4 or greater
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @version 2.0
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
@@ -138,7 +138,7 @@ abstract class Kohana_Cache {
}
/**
* @var Kohana_Config
* @var Config
*/
protected $_config;
@@ -253,4 +253,4 @@ abstract class Kohana_Cache {
return str_replace(array('/', '\\', ' '), '_', $id);
}
}
// End Kohana_Cache
// End Kohana_Cache

View File

@@ -30,8 +30,8 @@
* * PHP 5.2.4 or greater
* * APC PHP extension
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
* @license http://kohanaphp.com/license
@@ -71,7 +71,9 @@ class Kohana_Cache_Apc extends Cache {
*/
public function get($id, $default = NULL)
{
return (($data = apc_fetch($this->_sanitize_id($id))) === FALSE) ? $default : $data;
$data = apc_fetch($this->_sanitize_id($id), $success);
return $success ? $data : $default;
}
/**
@@ -130,4 +132,4 @@ class Kohana_Cache_Apc extends Cache {
{
return apc_clear_cache('user');
}
}
}

View File

@@ -30,8 +30,8 @@
* * PHP 5.2.4 or greater
* * Eaccelerator PHP extension
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
* @license http://kohanaphp.com/license
@@ -130,4 +130,4 @@ class Kohana_Cache_Eaccelerator extends Cache {
{
return eaccelerator_clean();
}
}
}

View File

@@ -1,3 +1,11 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Kohana_Cache_Exception extends Kohana_Exception {}
/**
* Kohana Cache Exception
*
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Cache_Exception extends Kohana_Exception {}

View File

@@ -32,20 +32,14 @@
* * Kohana 3.0.x
* * PHP 5.2.4 or greater
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Cache_File extends Cache implements Kohana_Cache_GarbageCollect {
// !!! NOTICE !!!
// THIS CONSTANT IS USED BY THE FILE CACHE CLASS
// INTERNALLY. USE THE CONFIGURATION FILE TO
// REDEFINE THE CACHE DIRECTORY.
const CACHE_DIR = 'cache/.kohana_cache';
/**
* Creates a hashed filename based on the string. This is used
* to create shorter unique IDs for each cache filename.
@@ -80,17 +74,18 @@ class Kohana_Cache_File extends Cache implements Kohana_Cache_GarbageCollect {
try
{
$directory = Arr::get($this->_config, 'cache_dir', APPPATH.Cache_File::CACHE_DIR);
$this->_cache_dir = new RecursiveDirectoryIterator($directory);
$directory = Arr::get($this->_config, 'cache_dir', Kohana::$cache_dir);
$this->_cache_dir = new SplFileInfo($directory);
}
// PHP < 5.3 exception handle
catch (ErrorException $e)
{
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
}
// PHP >= 5.3 exception handle
catch (UnexpectedValueException $e)
{
if ( ! mkdir($directory, 0777, TRUE))
{
throw new Kohana_Cache_Exception('Failed to create the defined cache directory : :directory', array(':directory' => $directory));
}
chmod($directory, 0777);
$this->_cache_dir = new RecursiveDirectoryIterator($directory);
$this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
}
// If the defined directory is a file, get outta here
@@ -138,7 +133,7 @@ class Kohana_Cache_File extends Cache implements Kohana_Cache_GarbageCollect {
$file = new SplFileInfo($directory.$filename);
// If file does not exist
if ( ! $file->getRealPath())
if ( ! $file->isFile())
{
// Return default value
return $default;
@@ -233,7 +228,7 @@ class Kohana_Cache_File extends Cache implements Kohana_Cache_GarbageCollect {
$type = gettype($data);
// Serialize the data
$data = json_encode((object) array(
$data = json_encode( (object) array(
'payload' => ($type === 'string') ? $data : serialize($data),
'expiry' => time() + $lifetime,
'type' => $type
@@ -366,7 +361,7 @@ class Kohana_Cache_File extends Cache implements Kohana_Cache_GarbageCollect {
}
}
// Else, is directory
else if ($file->isDir())
elseif ($file->isDir())
{
// Create new DirectoryIterator
$files = new DirectoryIterator($file->getPathname());
@@ -378,7 +373,7 @@ class Kohana_Cache_File extends Cache implements Kohana_Cache_GarbageCollect {
$name = $files->getFilename();
// If the name is not a dot
if ($name != '.' and $name != '..')
if ($name != '.' AND $name != '..' AND substr($file->getFilename(), 0, 1) == '.')
{
// Create new file resource
$fp = new SplFileInfo($files->getRealPath());
@@ -442,4 +437,27 @@ class Kohana_Cache_File extends Cache implements Kohana_Cache_GarbageCollect {
{
return $this->_cache_dir->getRealPath().DIRECTORY_SEPARATOR.$filename[0].$filename[1].DIRECTORY_SEPARATOR;
}
/**
* Makes the cache directory if it doesn't exist. Simply a wrapper for
* `mkdir` to ensure DRY principles
*
* @see http://php.net/manual/en/function.mkdir.php
* @param string directory
* @param string mode
* @param string recursive
* @param string context
* @return SplFileInfo
* @throws Kohana_Cache_Exception
*/
protected function _make_directory($directory, $mode = 0777, $recursive = FALSE, $context = NULL)
{
if ( ! mkdir($directory, $mode, $recursive, $context))
{
throw new Kohana_Cache_Exception('Failed to create the defined cache directory : :directory', array(':directory' => $directory));
}
chmod($directory, $mode);
return new SplFileInfo($directory);;
}
}

View File

@@ -4,8 +4,8 @@
* of their own, such as [Cache_File] and [Cache_Sqlite]. Memory based
* cache systems clean their own caches periodically.
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @version 2.0
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
@@ -20,4 +20,4 @@ interface Kohana_Cache_GarbageCollect {
* @return void
*/
public function garbage_collect();
}
}

View File

@@ -24,6 +24,7 @@
* 'timeout' => 1,
* 'retry_interval' => 15,
* 'status' => TRUE,
* 'instant_death' => TRUE,
* 'failure_callback' => array('className', 'classMethod')
* ),
* // Second memcache server
@@ -72,8 +73,8 @@
* * Memcache (plus Memcached-tags for native tagging support)
* * Zlib
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @version 2.0
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
@@ -98,6 +99,13 @@ class Kohana_Cache_Memcache extends Cache {
*/
protected $_flags;
/**
* The default configuration for the memcached server
*
* @var array
*/
protected $_default_config = array();
/**
* Constructs the memcache Kohana_Cache object
*
@@ -127,22 +135,23 @@ class Kohana_Cache_Memcache extends Cache {
}
// Setup default server configuration
$config = array(
'host' => 'localhost',
'port' => 11211,
'persistent' => FALSE,
'weight' => 1,
'timeout' => 1,
'retry_interval' => 15,
'status' => TRUE,
'failure_callback' => array($this, '_failed_request'),
$this->_default_config = array(
'host' => 'localhost',
'port' => 11211,
'persistent' => FALSE,
'weight' => 1,
'timeout' => 1,
'retry_interval' => 15,
'status' => TRUE,
'instant_death' => TRUE,
'failure_callback' => array($this, '_failed_request'),
);
// Add the memcache servers to the pool
foreach ($servers as $server)
{
// Merge the defined config with defaults
$server += $config;
$server += $this->_default_config;
if ( ! $this->_memcache->addServer($server['host'], $server['port'], $server['persistent'], $server['weight'], $server['timeout'], $server['retry_interval'], $server['status'], $server['failure_callback']))
{
@@ -276,7 +285,7 @@ class Kohana_Cache_Memcache extends Cache {
* @return void|boolean
* @since 3.0.8
*/
protected function _failed_request($hostname, $port)
public function _failed_request($hostname, $port)
{
if ( ! $this->_config['instant_death'])
return;
@@ -287,8 +296,12 @@ class Kohana_Cache_Memcache extends Cache {
// Get host settings from configuration
foreach ($this->_config['servers'] as $server)
{
// Merge the defaults, since they won't always be set
$server += $this->_default_config;
// We're looking at the failed server
if ($hostname == $server['host'] and $port == $server['port'])
{
// Server to disable, since it failed
$host = $server;
continue;
}
@@ -303,7 +316,7 @@ class Kohana_Cache_Memcache extends Cache {
$host['port'],
$host['timeout'],
$host['retry_interval'],
FALSE,
FALSE, // Server is offline
array($this, '_failed_request'
));
}

View File

@@ -2,8 +2,8 @@
/**
* See [Kohana_Cache_Memcache]
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @version 2.0
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
@@ -11,7 +11,7 @@
*/
class Kohana_Cache_MemcacheTag extends Cache_Memcache implements Kohana_Cache_Tagging {
/**
/**
* Constructs the memcache object
*
* @param array configuration
@@ -19,12 +19,12 @@ class Kohana_Cache_MemcacheTag extends Cache_Memcache implements Kohana_Cache_Ta
*/
protected function __construct(array $config)
{
parent::__construct($config);
if ( ! method_exists($this->_memcache, 'tag_add'))
{
throw new Kohana_Cache_Exception('Memcached-tags PHP plugin not present. Please see http://code.google.com/p/memcached-tags/ for more information');
}
parent::__construct($config);
}
/**
@@ -73,4 +73,4 @@ class Kohana_Cache_MemcacheTag extends Cache_Memcache implements Kohana_Cache_Ta
{
throw new Kohana_Cache_Exception('Memcached-tags does not support finding by tag');
}
}
}

View File

@@ -4,8 +4,8 @@
*
* Requires SQLite3 and PDO
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
* @license http://kohanaphp.com/license
@@ -195,16 +195,16 @@ class Kohana_Cache_Sqlite extends Cache implements Kohana_Cache_Tagging, Kohana_
$data = serialize($data);
// Normalise tags
$tags = (NULL === $tags) ? NULL : '<'.implode('>,<', $tags).'>';
$tags = (NULL === $tags) ? NULL : ('<'.implode('>,<', $tags).'>');
// Setup lifetime
if ($lifetime === NULL)
{
$lifetime = (0 === Arr::get('default_expire', NULL)) ? 0 : Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE) + time();
$lifetime = (0 === Arr::get('default_expire', NULL)) ? 0 : (Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE) + time());
}
else
{
$lifetime = (0 === $lifetime) ? 0 : $lifetime + time();
$lifetime = (0 === $lifetime) ? 0 : ($lifetime + time());
}
// Prepare statement
@@ -333,4 +333,4 @@ class Kohana_Cache_Sqlite extends Cache implements Kohana_Cache_Tagging, Kohana_
return (bool) $statement->fetchAll();
}
}
}

View File

@@ -2,8 +2,8 @@
/**
* Kohana Cache Tagging Interface
*
* @package Kohana
* @category Cache
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
* @license http://kohanaphp.com/license
@@ -39,4 +39,4 @@ interface Kohana_Cache_Tagging {
* @return array
*/
public function find($tag);
}
}

View File

@@ -0,0 +1,140 @@
<?php defined('SYSPATH') or die('No direct script access.');
/**
* [Kohana Cache](api/Kohana_Cache) Wincache driver. Provides an opcode based
* driver for the Kohana Cache library.
*
* ### Configuration example
*
* Below is an example of an _wincache_ server configuration.
*
* return array(
* 'wincache' => array( // Driver group
* 'driver' => 'wincache', // using wincache driver
* ),
* )
*
* 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.
*
* #### General cache group configuration settings
*
* Below are the settings available to all types of cache driver.
*
* Name | Required | Description
* -------------- | -------- | ---------------------------------------------------------------
* driver | __YES__ | (_string_) The driver type to use
*
* ### System requirements
*
* * Windows XP SP3 with IIS 5.1 and » FastCGI Extension
* * Windows Server 2003 with IIS 6.0 and » FastCGI Extension
* * Windows Vista SP1 with IIS 7.0 and FastCGI Module
* * Windows Server 2008 with IIS 7.0 and FastCGI Module
* * Windows 7 with IIS 7.5 and FastCGI Module
* * Windows Server 2008 R2 with IIS 7.5 and FastCGI Module
* * PHP 5.2.X, Non-thread-safe build
* * PHP 5.3 X86, Non-thread-safe VC9 build
*
* @package Kohana/Cache
* @category Base
* @author Kohana Team
* @copyright (c) 2009-2010 Kohana Team
* @license http://kohanaphp.com/license
*/
class Kohana_Cache_Wincache extends Cache {
/**
* Check for existence of the wincache extension This method cannot be invoked externally. The driver must
* be instantiated using the `Cache::instance()` method.
*
* @param array configuration
* @throws Kohana_Cache_Exception
*/
protected function __construct(array $config)
{
if ( ! extension_loaded('wincache'))
{
throw new Kohana_Cache_Exception('PHP wincache extension is not available.');
}
parent::__construct($config);
}
/**
* Retrieve a cached value entry by id.
*
* // Retrieve cache entry from wincache group
* $data = Cache::instance('wincache')->get('foo');
*
* // Retrieve cache entry from wincache group and return 'bar' if miss
* $data = Cache::instance('wincache')->get('foo', 'bar');
*
* @param string id of cache to entry
* @param string default value to return if cache miss
* @return mixed
* @throws Kohana_Cache_Exception
*/
public function get($id, $default = NULL)
{
$data = wincache_ucache_get($this->_sanitize_id($id), $success);
return $success ? $data : $default;
}
/**
* Set a value to cache with id and lifetime
*
* $data = 'bar';
*
* // Set 'bar' to 'foo' in wincache group, using default expiry
* Cache::instance('wincache')->set('foo', $data);
*
* // Set 'bar' to 'foo' in wincache group for 30 seconds
* Cache::instance('wincache')->set('foo', $data, 30);
*
* @param string id of cache entry
* @param string data to set to cache
* @param integer lifetime in seconds
* @return boolean
*/
public function set($id, $data, $lifetime = NULL)
{
if ($lifetime === NULL)
{
$lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
}
return wincache_ucache_set($this->_sanitize_id($id), $data, $lifetime);
}
/**
* Delete a cache entry based on id
*
* // Delete 'foo' entry from the wincache group
* Cache::instance('wincache')->delete('foo');
*
* @param string id to remove from cache
* @return boolean
*/
public function delete($id)
{
return wincache_ucache_delete($this->_sanitize_id($id));
}
/**
* Delete all cache entries.
*
* Beware of using this method when
* using shared memory cache systems, as it will wipe every
* entry within the system for all clients.
*
* // Delete all cache entries in the wincache group
* Cache::instance('wincache')->delete_all();
*
* @return boolean
*/
public function delete_all()
{
return wincache_ucache_clear();
}
}