refactoring Configure::load() to load config files from plugins, tests and config files added

Signed-off-by: Mark Story <mark@mark-story.com>
This commit is contained in:
ceeram 2009-11-15 22:59:19 +01:00 committed by mark_story
parent e1d60368f6
commit 7a4793a20c
4 changed files with 36 additions and 1 deletions

View file

@ -201,8 +201,16 @@ class Configure extends Object {
*/
function load($fileName) {
$found = false;
$pluginPath = false;
if(strpos($fileName, '.') !== false) {
$plugin = explode('.', $fileName, 2);
$pluginPath = App::pluginPath($plugin[0]);
}
if (file_exists(CONFIGS . $fileName . '.php')) {
if ($pluginPath && file_exists($pluginPath . 'config' . DS . $plugin[1] . '.php')) {
include($pluginPath . 'config' . DS . $plugin[1] . '.php');
$found = true;
} elseif (file_exists(CONFIGS . $fileName . '.php')) {
include(CONFIGS . $fileName . '.php');
$found = true;
} elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) {

View file

@ -224,6 +224,27 @@ class ConfigureTest extends CakeTestCase {
$this->assertTrue($result === null);
}
/**
* testLoad method
*
* @access public
* @return void
*/
function testLoadPlugin() {
App::build(array('plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)), true);
$result = Configure::load('test_plugin.load');
$this->assertTrue($result === null);
$expected = '/test_app/plugins/test_plugin/config/load.php';
$config = Configure::read('plugin_load');
$this->assertEqual($config, $expected);
$result = Configure::load('test_plugin.more.load');
$this->assertTrue($result === null);
$expected = '/test_app/plugins/test_plugin/config/more.load.php';
$config = Configure::read('plugin_more_load');
$this->assertEqual($config, $expected);
}
/**
* testStore method
*

View file

@ -0,0 +1,3 @@
<?php
$config['plugin_load'] = '/test_app/plugins/test_plugin/config/load.php';
?>

View file

@ -0,0 +1,3 @@
<?php
$config['plugin_more_load'] = '/test_app/plugins/test_plugin/config/more.load.php';
?>