Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merged branch Partugal/parameterBag (PR #4468)
Commits
-------

1227cc2 add escapeValue to ParameterBagInterface

Discussion
----------

add escapeValue to ParameterBagInterface

#4465

---------------------------------------------------------------------------

by travisbot at 2012-05-30T18:01:47Z

This pull request [fails](http://travis-ci.org/symfony/symfony/builds/1479725) (merged 1227cc2 into 49e213c).

---------------------------------------------------------------------------

by drak at 2012-05-31T02:42:44Z

@bschussek - there are a few form tests failing that seem to have been merged into master and thus all other unrelated PRs are failing their travis build checks. @fabpot
  • Loading branch information
fabpot committed Jun 26, 2012
2 parents fb3f771 + 1227cc2 commit d0e1547
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Expand Up @@ -253,6 +253,27 @@ public function isResolved()
return $this->resolved;
}

/**
* {@inheritDoc}
*/
public function escapeValue($value)
{
if (is_string($value)) {
return str_replace('%', '%%', $value);
}

if (is_array($value)) {
$result = array();
foreach ($value as $k => $v) {
$result[$k] = $this->escapeValue($v);
}

return $result;
}

return $value;
}

private function unescapeValue($value)
{
if (is_string($value)) {
Expand Down
Expand Up @@ -94,4 +94,13 @@ function resolve();
* @throws ParameterNotFoundException if a placeholder references a parameter that does not exist
*/
function resolveValue($value);

/**
* Escape parameter placeholders %
*
* @param mixed $value
*
* @return mixed
*/
function escapeValue($value);
}
Expand Up @@ -201,6 +201,22 @@ public function testResolveUnescapesValue()
$this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %foo %bar')), $bag->get('foo'), '->resolveValue() supports % escaping by doubling it');
}

/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::escapeValue
*/
public function testEscapeValue()
{
$bag = new ParameterBag();

$bag->add(array(
'foo' => $bag->escapeValue(array('bar' => array('ding' => 'I\'m a bar %foo %bar', 'zero' => null))),
'bar' => $bag->escapeValue('I\'m a %foo%'),
));

$this->assertEquals('I\'m a %%foo%%', $bag->get('bar'), '->escapeValue() escapes % by doubling it');
$this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %%foo %%bar', 'zero' => null)), $bag->get('foo'), '->escapeValue() escapes % by doubling it');
}

/**
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::resolve
* @dataProvider stringsWithSpacesProvider
Expand Down

0 comments on commit d0e1547

Please sign in to comment.