mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Make load() and dump() more consistent with each other, create new PhpReader for default if not configured yet.
Fixes #2998
This commit is contained in:
parent
86a74e3887
commit
19ba09286d
1 changed files with 27 additions and 17 deletions
|
@ -261,15 +261,8 @@ class Configure {
|
|||
* @throws ConfigureException Will throw any exceptions the reader raises.
|
||||
*/
|
||||
public static function load($key, $config = 'default', $merge = true) {
|
||||
if (!isset(self::$_readers[$config])) {
|
||||
if ($config === 'default') {
|
||||
App::uses('PhpReader', 'Configure');
|
||||
self::$_readers[$config] = new PhpReader();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$values = self::$_readers[$config]->read($key);
|
||||
$reader = self::_getReader($config);
|
||||
$values = $reader->read($key);
|
||||
|
||||
if ($merge) {
|
||||
$keys = array_keys($values);
|
||||
|
@ -309,17 +302,34 @@ class Configure {
|
|||
* @throws ConfigureException if the adapter does not implement a `dump` method.
|
||||
*/
|
||||
public static function dump($key, $config = 'default', $keys = array()) {
|
||||
if (empty(self::$_readers[$config])) {
|
||||
throw new ConfigureException(__d('cake', 'There is no "%s" adapter.', $config));
|
||||
}
|
||||
if (!method_exists(self::$_readers[$config], 'dump')) {
|
||||
$reader = self::_getReader($config);
|
||||
if (!method_exists($reader, 'dump')) {
|
||||
throw new ConfigureException(__d('cake', 'The "%s" adapter, does not have a dump() method.', $config));
|
||||
}
|
||||
$values = self::$_values;
|
||||
if (!empty($keys) && is_array($keys)) {
|
||||
$values = array_intersect_key($values, array_flip($keys));
|
||||
}
|
||||
return (bool)self::$_readers[$config]->dump($key, $values);
|
||||
return (bool)$reader->dump($key, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configured reader. Internally used by `Configure::load()` and `Configure::dump()`
|
||||
* Will create new PhpReader for default if not configured yet.
|
||||
*
|
||||
* @param string $config The name of the configured adapter
|
||||
* @return boolean success
|
||||
* @throws ConfigureException if the adapter is not configured
|
||||
*/
|
||||
protected static function _getReader($config) {
|
||||
if (!isset(self::$_readers[$config])) {
|
||||
if ($config !== 'default') {
|
||||
throw new ConfigureException(__d('cake', 'There is no "%s" adapter.', $config));
|
||||
}
|
||||
App::uses('PhpReader', 'Configure');
|
||||
self::config($config, new PhpReader());
|
||||
}
|
||||
return self::$_readers[$config];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue