Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Zend\Config\Writer\PhpArray - quote strings as var_export would
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Schindler committed Jan 28, 2014
1 parent f92a07b commit d997fc4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 1 addition & 3 deletions library/Zend/Config/Writer/PhpArray.php
Expand Up @@ -76,12 +76,10 @@ protected function processIndented(array $config, array $arraySyntax, &$indentLe
. $this->processIndented($value, $arraySyntax, $indentLevel)
. str_repeat(self::INDENT_STRING, --$indentLevel) . $arraySyntax['close'] . ",\n";
}
} elseif (is_object($value)) {
} elseif (is_object($value) || is_string($value)) {
$arrayString .= var_export($value, true) . ",\n";
} elseif (is_bool($value)) {
$arrayString .= ($value ? 'true' : 'false') . ",\n";
} elseif (is_string($value)) {
$arrayString .= "'" . addslashes($value) . "',\n";
} elseif ($value === null) {
$arrayString .= "null,\n";
} else {
Expand Down
15 changes: 15 additions & 0 deletions tests/ZendTest/Config/Writer/PhpArrayTest.php
Expand Up @@ -84,6 +84,21 @@ public function testRenderWithBracketArraySyntax()
$this->assertEquals($expected, $configString);
}

public function testRenderWithQuotesInString()
{
$config = new Config(array('one' => 'Test with "double" quotes', 'two' => 'Test with \'single\' quotes'));

$configString = $this->writer->toString($config);

$expected = "<?php\n";
$expected .= "return array(\n";
$expected .= " 'one' => 'Test with \"double\" quotes',\n";
$expected .= " 'two' => 'Test with \\'single\\' quotes',\n";
$expected .= ");\n";

$this->assertEquals($expected, $configString);
}

public function testSetUseBracketArraySyntaxReturnsFluentInterface()
{
$this->assertSame($this->writer, $this->writer->setUseBracketArraySyntax(true));
Expand Down

0 comments on commit d997fc4

Please sign in to comment.