mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Make file extension optional for Configure reader adapter's dump function.
This commit is contained in:
parent
76f93178a8
commit
18c5a4aee5
4 changed files with 24 additions and 0 deletions
|
@ -142,6 +142,7 @@ class IniReader implements ConfigReaderInterface {
|
|||
* Dumps the state of Configure data into an ini formatted string.
|
||||
*
|
||||
* @param string $filename The filename on $this->_path to save into.
|
||||
* Extension ".ini" will be automatically appended if not included in filename.
|
||||
* @param array $data The data to convert to ini file.
|
||||
* @return int Bytes saved.
|
||||
*/
|
||||
|
@ -159,6 +160,10 @@ class IniReader implements ConfigReaderInterface {
|
|||
}
|
||||
}
|
||||
$contents = join("\n", $result);
|
||||
|
||||
if (substr($filename, -4) !== '.ini') {
|
||||
$filename .= '.ini';
|
||||
}
|
||||
return file_put_contents($this->_path . $filename, $contents);
|
||||
}
|
||||
|
||||
|
|
|
@ -92,11 +92,16 @@ class PhpReader implements ConfigReaderInterface {
|
|||
* be used saved into a file and loaded later.
|
||||
*
|
||||
* @param string $filename The filename to create on $this->_path.
|
||||
* Extension ".php" will be automatically appended if not included in filename.
|
||||
* @param array $data Data to dump.
|
||||
* @return int Bytes saved.
|
||||
*/
|
||||
public function dump($filename, $data) {
|
||||
$contents = '<?php' . "\n" . '$config = ' . var_export($data, true) . ';';
|
||||
|
||||
if (substr($filename, -4) !== '.php') {
|
||||
$filename .= '.php';
|
||||
}
|
||||
return file_put_contents($this->_path . $filename, $contents);
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,13 @@ INI;
|
|||
unlink($file);
|
||||
|
||||
$this->assertTextEquals($expected, $result);
|
||||
|
||||
$result = $reader->dump('test', $this->testData);
|
||||
$this->assertTrue($result > 0);
|
||||
|
||||
$contents = file_get_contents($file);
|
||||
$this->assertTextEquals($expected, $contents);
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,6 +151,13 @@ PHP;
|
|||
|
||||
unlink($file);
|
||||
$this->assertTextEquals($expected, $contents);
|
||||
|
||||
$result = $reader->dump('test', $this->testData);
|
||||
$this->assertTrue($result > 0);
|
||||
|
||||
$contents = file_get_contents($file);
|
||||
$this->assertTextEquals($expected, $contents);
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue