Merge remote branch 'origin/2.0' into 2.0-class-loading

Conflicts:
	lib/Cake/config/ini_file.php
This commit is contained in:
José Lorenzo Rodríguez 2010-12-06 09:42:52 -04:30
commit 5dddb362ec
24 changed files with 568 additions and 171 deletions

View file

@ -211,7 +211,6 @@ class FixtureTask extends BakeTask {
$this->_Schema = new CakeSchema();
$data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection));
if (!isset($data['tables'][$useTable])) {
$this->err('Could not find your selected table ' . $useTable);
return false;

View file

@ -0,0 +1,109 @@
<?php
/**
* IniReader
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake
* @subpackage cake.libs.config
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Ini file configuration parser. Since IniReader uses parse_ini_file underneath,
* you should be aware that this class shares the same behavior, especially with
* regards to boolean and null values.
*
* In addition to the native parse_ini_file features, IniReader also allows you
* to create nested array structures through usage of . delimited names. This allows
* you to create nested arrays structures in an ini config file. For example:
*
* `db.password = secret` would turn into `array('db' => array('password' => 'secret'))`
*
* You can nest properties as deeply as needed using .'s. IniReader also manipulates
* how the special ini values of 'yes', 'no', 'on', 'off', 'null' are handled.
* These values will be converted to their boolean equivalents.
*
* @package cake.config
* @see http://php.net/parse_ini_file
*/
class IniReader implements ConfigReaderInterface {
/**
* The path to read ini files from.
*
* @var array
*/
protected $_path;
/**
* The section to read, if null all sections will be read.
*
* @var string
*/
protected $_section;
/**
* Build and construct a new ini file parser. The parser can be used to read
* ini files that are on the filesystem.
*
* @param string $path Path to load ini config files from.
* @param string $section Only get one section.
*/
public function __construct($path, $section = null) {
$this->_path = $path;
$this->_section = $section;
}
/**
* Read an ini file and return the results as an array.
*
* @param string $file Name of the file to read.
* @return array
*/
public function read($file) {
$filename = $this->_path . $file;
$contents = parse_ini_file($filename, true);
if (!empty($this->_section) && isset($contents[$this->_section])) {
$values = $this->_parseNestedValues($contents[$this->_section]);
} else {
$values = array();
foreach ($contents as $section => $attribs) {
$values[$section] = $this->_parseNestedValues($attribs);
}
}
return $values;
}
/**
* parses nested values out of keys.
*
* @param array $values Values to be exploded.
* @return array Array of values exploded
*/
protected function _parseNestedValues($values) {
foreach ($values as $key => $value) {
if ($value === '1') {
$value = true;
}
if ($value === '') {
$value = false;
}
if (strpos($key, '.') !== false) {
$values = Set::insert($values, $key, $value);
} else {
$values[$key] = $value;
}
}
return $values;
}
}

View file

@ -0,0 +1,79 @@
<?php
/**
* PhpReader file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* PHP Reader allows Configure to load configuration values from
* files containing simple PHP arrays.
*
* @package cake.libs.config
*/
class PhpReader implements ConfigReaderInterface {
/**
* The path this reader finds files on.
*
* @var string
*/
protected $_path = null;
/**
* Constructor for PHP Config file reading.
*
* @param string $path The path to read config files from. Defaults to CONFIGS
*/
public function __construct($path = CONFIGS) {
$this->_path = $path;
}
/**
* Read a config file and return its contents.
*
* Keys with `.` will be treated as values in plugins. Instead of reading from
* the initialized path, plugin keys will be located using App::pluginPath().
*
*
* @param string $key The identifier to read from. If the key has a . it will be treated
* as a plugin prefix.
* @return array Parsed configuration values.
* @throws RuntimeException when files don't exist or they don't contain `$config`.
* InvalidArgumentException when files contain '..' as this could lead to abusive reads.
*/
public function read($key) {
if (strpos($key, '..') !== false) {
throw new InvalidArgumentException(__('Cannot load configuration files with ../ in them.'));
}
list($plugin, $key) = pluginSplit($key);
if ($plugin) {
$file = App::pluginPath($plugin) . 'config' . DS . $key . '.php';
} else {
$file = $this->_path . $key . '.php';
}
if (!file_exists($file)) {
throw new RuntimeException(__('Could not load configuration file: ') . $file);
}
include $file;
if (!isset($config)) {
throw new RuntimeException(
sprintf(__('No variable $config found in %s.php'), $file)
);
}
return $config;
}
}

View file

@ -43,7 +43,6 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
*/
function tearDown() {
parent::tearDown();
ConsoleErrorHandler::$stderr = null;
}
/**
@ -52,7 +51,7 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
* @return void
*/
function testHandleError() {
$content = '<error>Notice Error:</error> This is a notice error in [/some/file, line 275]';
$content = "<error>Notice Error:</error> This is a notice error in [/some/file, line 275]\n";
ConsoleErrorHandler::$stderr->expects($this->once())->method('write')
->with($content);

View file

@ -84,7 +84,7 @@ class ApiShellTest extends CakeTestCase {
$this->Shell->expects($this->at(2))->method('out')->with($expected);
$this->Shell->args = array('controller');
$this->Shell->paths['controller'] = CAKE_CORE_INCLUDE_PATH . DS . LIBS . 'controller' . DS;
$this->Shell->paths['controller'] = LIBS . 'controller' . DS;
$this->Shell->main();
}
}

View file

@ -25,12 +25,12 @@ App::import('Shell', 'Shell', false);
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
/**
* TestShell class
* ShellTestShell class
*
* @package cake
* @subpackage cake.tests.cases.console.libs
*/
class TestShell extends Shell {
class ShellTestShell extends Shell {
/**
* name property
@ -38,7 +38,7 @@ class TestShell extends Shell {
* @var name
* @access public
*/
public $name = 'TestShell';
public $name = 'ShellTestShell';
/**
* stopped property
@ -133,7 +133,7 @@ class ShellTest extends CakeTestCase {
$output = $this->getMock('ConsoleOutput', array(), array(), '', false);
$error = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Shell = new TestShell($output, $error, $in);
$this->Shell = new ShellTestShell($output, $error, $in);
}
/**
@ -142,7 +142,7 @@ class ShellTest extends CakeTestCase {
* @return void
*/
public function testConstruct() {
$this->assertEqual($this->Shell->name, 'TestShell');
$this->assertEqual($this->Shell->name, 'ShellTestShell');
$this->assertType('ConsoleInput', $this->Shell->stdin);
$this->assertType('ConsoleOutput', $this->Shell->stdout);
$this->assertType('ConsoleOutput', $this->Shell->stderr);

View file

@ -70,7 +70,7 @@ class ProjectTaskTest extends CakeTestCase {
* @return void
*/
protected function _setupTestProject() {
$skel = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
$skel = CAKE . 'console' . DS . 'templates' . DS . 'skel';
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
}
@ -256,7 +256,7 @@ class ProjectTaskTest extends CakeTestCase {
* @return void
*/
public function testExecute() {
$this->Task->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . DS . 'console' . DS. 'templates' . DS . 'skel';
$this->Task->params['skel'] = CAKE . DS . 'console' . DS. 'templates' . DS . 'skel';
$this->Task->params['working'] = TMP . 'tests' . DS;
$path = $this->Task->path . 'bake_test_app';
@ -264,7 +264,7 @@ class ProjectTaskTest extends CakeTestCase {
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
$this->Task->execute();
$this->assertTrue(is_dir($path), 'No project dir %s');
$this->assertTrue(is_dir($path), 'No project dir');
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir ');
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir ');
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir');

View file

@ -88,7 +88,7 @@ class TemplateTaskTest extends CakeTestCase {
* @return void
*/
public function testFindingInstalledThemesForBake() {
$consoleLibs = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS;
$consoleLibs = CAKE . 'console' . DS;
$this->Task->initialize();
$this->assertEqual($this->Task->templatePaths, array('default' => $consoleLibs . 'templates' . DS . 'default' . DS));
}

View file

@ -34,9 +34,10 @@ class AllConfigureTest extends PHPUnit_Framework_TestSuite {
* @return void
*/
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite('All Configure, App and ClassRegistry related tests');
$suite = new CakeTestSuite('All Configure, App and ClassRegistry related tests');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'configure.test.php');
$suite->addTestDirectory(CORE_TEST_CASES . DS . 'libs' . DS . 'config');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'app.test.php');
$suite->addTestFile(CORE_TEST_CASES . DS . 'libs' . DS . 'class_registry.test.php');
return $suite;

View file

@ -211,9 +211,9 @@ class AppImportTest extends CakeTestCase {
$this->assertTrue($file);
$this->assertTrue(class_exists('Shell'));
$file = App::import('Lib', 'cache/Apc');
$file = App::import('Lib', 'config/PhpReader');
$this->assertTrue($file);
$this->assertTrue(class_exists('ApcEngine'));
$this->assertTrue(class_exists('PhpReader'));
$file = App::import('Model', 'SomeRandomModelThatDoesNotExist', false);
$this->assertFalse($file);

View file

@ -20,8 +20,7 @@
if (!class_exists('Cache')) {
require LIBS . 'cache.php';
}
App::import('Core', 'cache/Memcache');
require_once LIBS . 'cache' . DS . 'memcache.php';
class TestMemcacheEngine extends MemcacheEngine {
/**

View file

@ -1,6 +1,6 @@
<?php
/**
* IniFileTest
* IniReaderTest
*
* PHP 5
*
@ -17,9 +17,9 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'config/IniFile');
App::import('Core', 'config/IniReader');
class IniFileTest extends CakeTestCase {
class IniReaderTest extends CakeTestCase {
/**
* The test file that will be read.
@ -35,7 +35,7 @@ class IniFileTest extends CakeTestCase {
*/
function setup() {
parent::setup();
$this->file = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS . 'acl.ini.php';
$this->path = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS;
}
/**
@ -44,7 +44,8 @@ class IniFileTest extends CakeTestCase {
* @return void
*/
function testConstruct() {
$config = new IniFile($this->file);
$reader = new IniReader($this->path);
$config = $reader->read('acl.ini.php');
$this->assertTrue(isset($config['admin']));
$this->assertTrue(isset($config['paul']['groups']));
@ -57,32 +58,45 @@ class IniFileTest extends CakeTestCase {
* @return void
*/
function testReadingOnlyOneSection() {
$config = new IniFile($this->file, 'admin');
$reader = new IniReader($this->path, 'admin');
$config = $reader->read('acl.ini.php');
$this->assertTrue(isset($config['groups']));
$this->assertEquals('administrators', $config['groups']);
}
/**
* test getting all the values as an array
* test that names with .'s get exploded into arrays.
*
* @return void
*/
function testAsArray() {
$config = new IniFile($this->file);
$content = $config->asArray();
function testReadingValuesWithDots() {
$reader = new IniReader($this->path);
$config = $reader->read('nested.ini');
$this->assertTrue(isset($content['admin']['groups']));
$this->assertTrue(isset($content['paul']['groups']));
$this->assertTrue(isset($config['database']['db']['username']));
$this->assertEquals('mark', $config['database']['db']['username']);
$this->assertEquals(3, $config['nesting']['one']['two']['three']);
}
/**
* test that values cannot be modified
* test boolean reading
*
* @expectedException LogicException
* @return void
*/
function testNoModification() {
$config = new IniFile($this->file);
$config['admin'] = 'something';
function testBooleanReading() {
$reader = new IniReader($this->path);
$config = $reader->read('nested.ini');
$this->assertTrue($config['bools']['test_on']);
$this->assertFalse($config['bools']['test_off']);
$this->assertTrue($config['bools']['test_yes']);
$this->assertFalse($config['bools']['test_no']);
$this->assertTrue($config['bools']['test_true']);
$this->assertFalse($config['bools']['test_false']);
$this->assertFalse($config['bools']['test_null']);
}
}

View file

@ -0,0 +1,91 @@
<?php
/**
* PhpConfigReaderTest
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.cases
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'config/PhpReader');
class PhpReaderTest extends CakeTestCase {
/**
* setup
*
* @return void
*/
function setUp() {
parent::setUp();
$this->path = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config'. DS;
}
/**
* test reading files
*
* @return void
*/
function testRead() {
$reader = new PhpReader($this->path);
$values = $reader->read('var_test');
$this->assertEquals('value', $values['Read']);
$this->assertEquals('buried', $values['Deep']['Deeper']['Deepest']);
}
/**
* Test an exception is thrown by reading files that don't exist.
*
* @expectedException RuntimeException
* @return void
*/
function testReadWithNonExistantFile() {
$reader = new PhpReader($this->path);
$reader->read('fake_values');
}
/**
* test reading an empty file.
*
* @expectedException RuntimeException
* @return void
*/
function testReadEmptyFile() {
$reader = new PhpReader($this->path);
$reader->read('empty');
}
/**
* test reading keys with ../ doesn't work
*
* @expectedException InvalidArgumentException
* @return void
*/
function testReadWithDots() {
$reader = new PhpReader($this->path);
$reader->read('../empty');
}
/**
* test reading from plugins
*
* @return void
*/
function testReadPluginValue() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
), true);
$reader = new PhpReader($this->path);
$result = $reader->read('TestPlugin.load');
$this->assertTrue(isset($result['plugin_load']));
}
}

View file

@ -19,6 +19,7 @@
* @since CakePHP(tm) v 1.2.0.5432
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'config/PhpReader');
/**
* ConfigureTest
@ -70,6 +71,7 @@ class ConfigureTest extends CakeTestCase {
}
Configure::write('debug', $this->_debug);
Configure::write('Cache.disable', $this->_cacheDisable);
Configure::drop('test');
}
/**
@ -184,18 +186,26 @@ class ConfigureTest extends CakeTestCase {
/**
* testLoad method
*
* @access public
* @expectedException RuntimeException
* @return void
*/
function testLoadExceptionOnNonExistantFile() {
Configure::config('test', new PhpReader());
$result = Configure::load('non_existing_configuration_file', 'test');
}
/**
* test load
*
* @return void
*/
function testLoad() {
$result = Configure::load('non_existing_configuration_file');
$this->assertFalse($result);
Configure::config('test', new PhpReader(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS));
$result = Configure::load('config');
$result = Configure::load('var_test', 'test');
$this->assertTrue($result);
$result = Configure::load('../../index');
$this->assertFalse($result);
$this->assertEquals('value', Configure::read('Read'));
}
/**
@ -206,13 +216,15 @@ class ConfigureTest extends CakeTestCase {
*/
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');
Configure::config('test', new PhpReader());
$result = Configure::load('test_plugin.load', 'test');
$this->assertTrue($result);
$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');
$result = Configure::load('test_plugin.more.load', 'test');
$this->assertTrue($result);
$expected = '/test_app/plugins/test_plugin/config/more.load.php';
$config = Configure::read('plugin_more_load');
@ -225,25 +237,39 @@ class ConfigureTest extends CakeTestCase {
* @access public
* @return void
*/
function testStoreAndLoad() {
function testStoreAndRestore() {
Configure::write('Cache.disable', false);
$expected = array('data' => 'value with backslash \, \'singlequote\' and "doublequotes"');
Configure::store('SomeExample', 'test', $expected);
Configure::write('Testing', 'yummy');
$this->assertTrue(Configure::store('store_test', 'default'));
Configure::load('test');
$config = Configure::read('SomeExample');
$this->assertEqual($config, $expected);
Configure::delete('Testing');
$this->assertNull(Configure::read('Testing'));
$expected = array(
'data' => array('first' => 'value with backslash \, \'singlequote\' and "doublequotes"', 'second' => 'value2'),
'data2' => 'value'
);
Configure::store('AnotherExample', 'test_config', $expected);
Configure::restore('store_test', 'default');
$this->assertEquals('yummy', Configure::read('Testing'));
Configure::load('test_config');
$config = Configure::read('AnotherExample');
$this->assertEqual($config, $expected);
Cache::delete('store_test', 'default');
}
/**
* test that store and restore only store/restore the provided data.
*
* @return void
*/
function testStoreAndRestoreWithData() {
Configure::write('Cache.disable', false);
Configure::write('testing', 'value');
Configure::store('store_test', 'default', array('store_test' => 'one'));
Configure::delete('testing');
$this->assertNull(Configure::read('store_test'), 'Calling store with data shouldnt modify runtime.');
Configure::restore('store_test', 'default');
$this->assertEquals('one', Configure::read('store_test'));
$this->assertNull(Configure::read('testing'), 'Values that were not stored are not restored.');
Cache::delete('store_test', 'default');
}
/**
@ -256,5 +282,35 @@ class ConfigureTest extends CakeTestCase {
$result = Configure::version();
$this->assertTrue(version_compare($result, '1.2', '>='));
}
/**
* test adding new readers.
*
* @return void
*/
function testReaderSetup() {
$reader = new PhpReader();
Configure::config('test', $reader);
$configured = Configure::configured();
$this->assertTrue(in_array('test', $configured));
$this->assertTrue(Configure::configured('test'));
$this->assertFalse(Configure::configured('fake_garbage'));
$this->assertTrue(Configure::drop('test'));
$this->assertFalse(Configure::drop('test'), 'dropping things that do not exist should return false.');
}
/**
* test reader() throwing exceptions on missing interface.
*
* @expectedException Exception
* @return void
*/
function testReaderExceptionOnIncorrectClass() {
$reader = new StdClass();
Configure::config('test', $reader);
}
}

View file

@ -347,7 +347,7 @@ class ScaffoldViewTest extends CakeTestCase {
$this->assertEqual($result, $expected);
$result = $ScaffoldView->testGetFilename('error');
$expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp';
$expected = CAKE . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp';
$this->assertEqual($result, $expected);
$Controller = new ScaffoldMockController($this->request);

View file

@ -0,0 +1,2 @@
<?php
//do nothing this is an empty file.

View file

@ -0,0 +1,17 @@
; Test file for testing ini files with . syntax
[database]
db.username = mark
db.password = secret
[nesting]
one.two.three = 3
a.b.c.d = On
[bools]
test_on = on
test_off = off
test_yes = yes
test_no = no
test_true = true
test_false = false
test_null = null

View file

@ -0,0 +1,9 @@
<?php
$config = array(
'Read' => 'value',
'Deep' => array(
'Deeper' => array(
'Deepest' => 'buried'
)
)
);

View file

@ -662,9 +662,9 @@ class IniAcl extends Object implements AclInterface {
* @return array INI section structure
*/
public function readConfigFile($filename) {
App::import('Core', 'config/IniFile');
$iniFile = new IniFile($filename);
return $iniFile->asArray();
App::import('Core', 'config/IniReader');
$iniFile = new IniReader(dirname($filename) . DS);
return $iniFile->read(basename($filename));
}
/**

View file

@ -473,9 +473,10 @@ class Controller extends Object {
} else {
$id = $this->passedArgs['0'];
}
$plugin = $this->plugin ? $this->plugin . '.' : null;
if ($this->uses === false) {
$this->loadModel($this->modelClass, $id);
$this->loadModel($plugin . $this->modelClass, $id);
} elseif ($this->uses) {
$uses = is_array($this->uses) ? $this->uses : array($this->uses);
list($plugin, $modelClassName) = pluginSplit($uses[0]);

View file

@ -40,6 +40,14 @@ class Configure {
'debug' => 0
);
/**
* Configured reader classes, used to load config files from resources
*
* @var array
* @see Configure::load()
*/
protected static $_readers = array();
/**
* Initializes configure and runs the bootstrap process.
* Bootstrapping includes the following steps:
@ -55,13 +63,19 @@ class Configure {
*/
public static function bootstrap($boot = true) {
if ($boot) {
self::write('App', array('base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => WEBROOT_DIR, 'www_root' => WWW_ROOT));
self::write('App', array(
'base' => false,
'baseUrl' => false,
'dir' => APP_DIR,
'webroot' => WEBROOT_DIR,
'www_root' => WWW_ROOT
));
if (!include(CONFIGS . 'core.php')) {
trigger_error(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", CONFIGS), E_USER_ERROR);
}
if (Configure::read('Cache.disable') !== true) {
if (empty(self::$_values['Cache']['disable'])) {
$cache = Cache::config('default');
if (empty($cache['settings'])) {
@ -76,7 +90,7 @@ class Configure {
$prefix = $cache['settings']['prefix'];
}
if (Configure::read('debug') >= 1) {
if (self::$_values['debug'] >= 1) {
$duration = '+10 seconds';
} else {
$duration = '+999 days';
@ -167,13 +181,11 @@ class Configure {
}
}
if (isset($config['debug']) || isset($config['log'])) {
if (function_exists('ini_set')) {
if (self::$_values['debug']) {
ini_set('display_errors', 1);
} else {
ini_set('display_errors', 0);
}
if (isset($config['debug']) && function_exists('ini_set')) {
if (self::$_values['debug']) {
ini_set('display_errors', 1);
} else {
ini_set('display_errors', 0);
}
}
return true;
@ -250,59 +262,77 @@ class Configure {
}
/**
* Loads a file from app/config/configure_file.php.
* Add a new reader to Configure. Readers allow you to read configuration
* files in various formats/storage locations. CakePHP comes with two built-in readers
* PhpReader and IniReader. You can also implement your own reader classes in your application.
*
* Config file variables should be formated like:
* `$config['name'] = 'value';`
* These will be used to create dynamic Configure vars. load() is also used to
* load stored config files created with Configure::store()
* To add a new reader to Configure:
*
* - To load config files from app/config use `Configure::load('configure_file');`.
* - To load config files from a plugin `Configure::load('plugin.configure_file');`.
* `Configure::config('ini', new IniReader());`
*
* @param string $name The name of the reader being configured. This alias is used later to
* read values from a specific reader.
* @param ConfigReaderInterface $reader The reader to append.
* @return void
*/
public static function config($name, ConfigReaderInterface $reader) {
self::$_readers[$name] = $reader;
}
/**
* Gets the names of the configured reader objects.
*
* @return array Array of the configured reader objects.
*/
public static function configured($name = null) {
if ($name) {
return isset(self::$_readers[$name]);
}
return array_keys(self::$_readers);
}
/**
* Remove a configured reader. This will unset the reader
* and make any future attempts to use it cause an Exception.
*
* @param string $name Name of the reader to drop.
* @return boolean Success
*/
public static function drop($name) {
if (!isset(self::$_readers[$name])) {
return false;
}
unset(self::$_readers[$name]);
return true;
}
/**
* Loads stored configuration information from a resource. You can add
* config file resource readers with `Configure::config()`.
*
* Loaded configuration infomration will be merged with the current
* runtime configuration. You can load configuration files from plugins
* by preceeding the filename with the plugin name.
*
* `Configure::load('Users.user', 'default')`
*
* Would load the 'user' config file using the default config reader. You can load
* app config files by giving the name of the resource you want loaded.
*
* `Configure::load('setup', 'default');`
*
* @link http://book.cakephp.org/view/929/load
* @param string $fileName name of file to load, extension must be .php and only the name
* should be used, not the extenstion
* @return mixed false if file not found, void if load successful
* @param string $key name of configuration resource to load.
* @param string $config Name of the configured reader to use to read the resource identfied by $key.
* @return mixed false if file not found, void if load successful.
* @throws Exception Will throw any exceptions the reader raises.
*/
public static function load($fileName) {
$found = $plugin = $pluginPath = false;
list($plugin, $fileName) = pluginSplit($fileName);
if ($plugin) {
$pluginPath = App::pluginPath($plugin);
}
$pos = strpos($fileName, '..');
if ($pos === false) {
if ($pluginPath && file_exists($pluginPath . 'config' . DS . $fileName . '.php')) {
include($pluginPath . 'config' . DS . $fileName . '.php');
$found = true;
} elseif (file_exists(CONFIGS . $fileName . '.php')) {
include(CONFIGS . $fileName . '.php');
$found = true;
} elseif (file_exists(CACHE . 'persistent' . DS . $fileName . '.php')) {
include(CACHE . 'persistent' . DS . $fileName . '.php');
$found = true;
} else {
foreach (App::core('cake') as $key => $path) {
if (file_exists($path . DS . 'config' . DS . $fileName . '.php')) {
include($path . DS . 'config' . DS . $fileName . '.php');
$found = true;
break;
}
}
}
}
if (!$found) {
public static function load($key, $config = 'default') {
if (!isset(self::$_readers[$config])) {
return false;
}
if (!isset($config)) {
trigger_error(__('Configure::load() - no variable $config found in %s.php', $fileName), E_USER_WARNING);
return false;
}
return self::write($config);
$values = self::$_readers[$config]->read($key);
return self::write($values);
}
/**
@ -322,62 +352,52 @@ class Configure {
}
/**
* Used to write a config file to disk.
* Used to write runtime configuration into Cache. Stored runtime configuration can be
* restored using `Configure::restore()`. These methods can be used to enable configuration managers
* frontends, or other GUI type interfaces for configuration.
*
* {{{
* Configure::store('Model', 'class_paths', array('Users' => array(
* 'path' => 'users', 'plugin' => true
* )));
* }}}
*
* @param string $type Type of config file to write, ex: Models, Controllers, Helpers, Components
* @param string $name file name.
* @param array $data array of values to store.
* @return void
* @param string $name The storage name for the saved configuration.
* @param string $cacheConfig The cache configuration to save into. Defaults to 'default'
* @param array $data Either an array of data to store, or leave empty to store all values.
* @return boolean Success
*/
public static function store($type, $name, $data = array()) {
$write = true;
$content = '';
foreach ($data as $key => $value) {
$content .= "\$config['$type']['$key'] = " . var_export($value, true) . ";\n";
public static function store($name, $cacheConfig = 'default', $data = null) {
if ($data === null) {
$data = self::$_values;
}
if (is_null($type)) {
$write = false;
}
self::__writeConfig($content, $name, $write);
return Cache::write($name, $data, $cacheConfig);
}
/**
* Creates a cached version of a configuration file.
* Appends values passed from Configure::store() to the cached file
* Restores configuration data stored in the Cache into configure. Restored
* values will overwrite existing ones.
*
* @param string $content Content to write on file
* @param string $name Name to use for cache file
* @param boolean $write true if content should be written, false otherwise
* @return void
* @access private
* @param string $name Name of the stored config file to load.
* @param string $cacheConfig Name of the Cache configuration to read from.
* @return boolean Success.
*/
private static function __writeConfig($content, $name, $write = true) {
$file = CACHE . 'persistent' . DS . $name . '.php';
if (self::read('debug') > 0) {
$expires = "+10 seconds";
} else {
$expires = "+999 days";
}
$cache = cache('persistent' . DS . $name . '.php', null, $expires);
if ($cache === null) {
cache('persistent' . DS . $name . '.php', "<?php\n\$config = array();\n", $expires);
}
if ($write === true) {
$fileClass = new SplFileObject($file, 'a');
if ($fileClass->isWritable()) {
$fileClass->fwrite($content);
}
public static function restore($name, $cacheConfig = 'default') {
$values = Cache::read($name, $cacheConfig);
if ($values) {
return self::write($values);
}
return false;
}
}
/**
* An interface for creating objects compatible with Configure::load()
*
* @package cake.libs
*/
interface ConfigReaderInterface {
/**
* Read method is used for reading configuration information from sources.
* These sources can either be static resources like files, or dynamic ones like
* a database, or other datasource.
*
* @param string $key
* @return array An array of data to merge into the runtime configuration
*/
function read($key);
}

View file

@ -1077,7 +1077,11 @@ class Multibyte {
if ($range === false) {
return null;
}
Configure::load('unicode' . DS . 'casefolding' . DS . $range);
if (!Configure::configured('_cake_core_')) {
App::import('Core', 'config/PhpReader');
Configure::config('_cake_core_', new PhpReader(CAKE . 'config' . DS));
}
Configure::load('unicode' . DS . 'casefolding' . DS . $range, '_cake_core_');
self::$__caseFold[$range] = Configure::read($range);
Configure::delete($range);
}

View file

@ -295,9 +295,6 @@ class CakeSchema extends Object {
$systemTables = array(
'aros', 'acos', 'aros_acos', Configure::read('Session.table'), 'i18n'
);
if (get_class($Object) === 'AppModel') {
continue;
}
if (in_array($table, $systemTables)) {
$tables[$Object->table] = $this->__columns($Object);
$tables[$Object->table]['indexes'] = $db->index($Object);

View file

@ -17,7 +17,7 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (Configure::read() == 0):
$this->cakeError('error404');
throw new NotFoundException();
endif;
?>
<h2><?php echo __('Release Notes for CakePHP %s.', Configure::version()); ?></h2>