mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding the ability to load cache engine classes from plugins and app libs.
Also enabled the ability for App cache classes to override core ones. Test cases added. Removed unnecessary subclassing of Object.
This commit is contained in:
parent
3c349dd15c
commit
b6978ab25f
2 changed files with 47 additions and 17 deletions
|
@ -74,20 +74,6 @@ class Cache {
|
|||
return $instance[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find and include a file for a cache engine and returns object instance
|
||||
*
|
||||
* @param $name Name of the engine (without 'Engine')
|
||||
* @return mixed $engine object or null
|
||||
* @access private
|
||||
*/
|
||||
function __loadEngine($name) {
|
||||
if (!class_exists($name . 'Engine')) {
|
||||
require LIBS . DS . 'cache' . DS . strtolower($name) . '.php';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache configuration to use
|
||||
*
|
||||
|
@ -146,10 +132,15 @@ class Cache {
|
|||
* @static
|
||||
*/
|
||||
function engine($name = 'File', $settings = array()) {
|
||||
$cacheClass = $name . 'Engine';
|
||||
$plugin = null;
|
||||
$class = $name;
|
||||
if (strpos($name, '.') !== false) {
|
||||
list($plugin, $class) = explode('.', $name);
|
||||
}
|
||||
$cacheClass = $class . 'Engine';
|
||||
$_this =& Cache::getInstance();
|
||||
if (!isset($_this->_Engine[$name])) {
|
||||
if ($_this->__loadEngine($name) === false) {
|
||||
if ($_this->__loadEngine($class, $plugin) === false) {
|
||||
return false;
|
||||
}
|
||||
$_this->_Engine[$name] =& new $cacheClass();
|
||||
|
@ -165,6 +156,25 @@ class Cache {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to find and include a file for a cache engine and returns object instance
|
||||
*
|
||||
* @param $name Name of the engine (without 'Engine')
|
||||
* @return mixed $engine object or null
|
||||
* @access private
|
||||
*/
|
||||
function __loadEngine($name, $plugin = null) {
|
||||
if ($plugin) {
|
||||
App::import('Lib', $plugin . '.cache' . DS . $name);
|
||||
} else {
|
||||
if (!App::import('Lib', 'cache' . DS . $name)) {
|
||||
App::import('Core', 'cache' . DS . $name);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Temporarily change settings to current config options. if no params are passed, resets settings if needed
|
||||
* Cache::write() will reset the configuration changes made
|
||||
|
@ -417,7 +427,7 @@ class Cache {
|
|||
* @package cake
|
||||
* @subpackage cake.cake.libs
|
||||
*/
|
||||
class CacheEngine extends Object {
|
||||
class CacheEngine {
|
||||
|
||||
/**
|
||||
* settings of current engine instance
|
||||
|
|
|
@ -71,6 +71,26 @@ class CacheTest extends CakeTestCase {
|
|||
$this->assertEqual($results, Cache::config('new'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test configuring CacheEngines in App/libs
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testConfigWithLibAndPluginEngines() {
|
||||
App::build(array(
|
||||
'libs' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'libs' . DS),
|
||||
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
|
||||
), true);
|
||||
|
||||
$settings = array('engine' => 'TestAppCache', 'path' => TMP, 'prefix' => 'cake_test_');
|
||||
$result = Cache::config('libEngine', $settings);
|
||||
$this->assertEqual($result, Cache::config('libEngine'));
|
||||
|
||||
$settings = array('engine' => 'TestPlugin.TestPluginCache', 'path' => TMP, 'prefix' => 'cake_test_');
|
||||
$result = Cache::config('pluginLibEngine', $settings);
|
||||
$this->assertEqual($result, Cache::config('pluginLibEngine'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testInvalidConfig method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue