mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 02:26:17 +00:00
Ini/Php readers now read files with/without extension.
This commit is contained in:
parent
55c557d5a1
commit
be98491413
4 changed files with 31 additions and 3 deletions
|
@ -71,6 +71,12 @@ class IniReader implements ConfigReaderInterface {
|
|||
*/
|
||||
public function read($file) {
|
||||
$filename = $this->_path . $file;
|
||||
if (!file_exists($filename)) {
|
||||
$filename .= '.ini';
|
||||
if (!file_exists($filename)) {
|
||||
throw new ConfigureException(__('Could not load configuration files: %s or %s', substr($filename, 0, -4), $filename));
|
||||
}
|
||||
}
|
||||
$contents = parse_ini_file($filename, true);
|
||||
if (!empty($this->_section) && isset($contents[$this->_section])) {
|
||||
$values = $this->_parseNestedValues($contents[$this->_section]);
|
||||
|
|
|
@ -57,15 +57,21 @@ class PhpReader implements ConfigReaderInterface {
|
|||
if (strpos($key, '..') !== false) {
|
||||
throw new ConfigureException(__('Cannot load configuration files with ../ in them.'));
|
||||
}
|
||||
if (substr($key, -4) === '.php') {
|
||||
$key = substr($key, 0, -4);
|
||||
}
|
||||
list($plugin, $key) = pluginSplit($key);
|
||||
|
||||
if ($plugin) {
|
||||
$file = App::pluginPath($plugin) . 'config' . DS . $key . '.php';
|
||||
$file = App::pluginPath($plugin) . 'config' . DS . $key;
|
||||
} else {
|
||||
$file = $this->_path . $key . '.php';
|
||||
$file = $this->_path . $key;
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
throw new ConfigureException(__('Could not load configuration file: ') . $file);
|
||||
$file .= '.php';
|
||||
if (!file_exists($file)) {
|
||||
throw new ConfigureException(__('Could not load configuration files: %s or %s', substr($file, 0, -4), $file));
|
||||
}
|
||||
}
|
||||
include $file;
|
||||
if (!isset($config)) {
|
||||
|
|
|
@ -114,4 +114,15 @@ class IniReaderTest extends CakeTestCase {
|
|||
|
||||
$this->assertFalse($config['bools']['test_null']);
|
||||
}
|
||||
|
||||
/**
|
||||
* test read file without extension
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testReadingWithoutExtension() {
|
||||
$reader = new IniReader($this->path);
|
||||
$config = $reader->read('nested');
|
||||
$this->assertTrue($config['bools']['test_on']);
|
||||
}
|
||||
}
|
|
@ -38,6 +38,9 @@ class PhpReaderTest extends CakeTestCase {
|
|||
$values = $reader->read('var_test');
|
||||
$this->assertEquals('value', $values['Read']);
|
||||
$this->assertEquals('buried', $values['Deep']['Deeper']['Deepest']);
|
||||
|
||||
$values = $reader->read('var_test.php');
|
||||
$this->assertEquals('value', $values['Read']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +87,9 @@ class PhpReaderTest extends CakeTestCase {
|
|||
), true);
|
||||
$reader = new PhpReader($this->path);
|
||||
$result = $reader->read('TestPlugin.load');
|
||||
$this->assertTrue(isset($result['plugin_load']));
|
||||
|
||||
$result = $reader->read('TestPlugin.load.php');
|
||||
$this->assertTrue(isset($result['plugin_load']));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue