Skip to content
This repository has been archived by the owner on Feb 5, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8 from pamil/escaped-parameters
Browse files Browse the repository at this point in the history
Support escaped values in parameter bag
  • Loading branch information
pamil authored Feb 16, 2017
2 parents 465cc7c + 3d542e3 commit d40f5c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/ContainerBasedContainerAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ public function getService($id)
*/
public function getParameters()
{
$parameterBag = $this->container->getParameterBag();
if (!$this->container->isFrozen()) {
$parameterBag = clone $this->container->getParameterBag();
$parameterBag = clone $parameterBag;
$parameterBag->resolve();

return $parameterBag->all();
// Values are automatically unescaped during resolving, need to revert it
$parameterBag->add(array_map(function ($unescapedValue) use ($parameterBag) {
return $parameterBag->escapeValue($unescapedValue);
}, $parameterBag->all()));
}

return $this->container->getParameterBag()->all();
return $parameterBag->all();
}
}
16 changes: 16 additions & 0 deletions tests/CrossContainerProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ public function it_resolves_cross_container_parameters_in_service_definition_arr
static::assertSame(['parameter' => '42'], $baseContainer->get('array_object')->getArrayCopy());
}

/**
* @test
*/
public function it_resolves_cross_container_escaped_parameters()
{
$externalContainer = new ContainerBuilder();
$externalContainer->setParameter('parameter', '%%s?%%s');

$baseContainer = new ContainerBuilder();
$baseContainer->setParameter('parameter', '%__external__.parameter%');

$this->buildContainerWithDependencies($baseContainer, ['external' => $externalContainer]);

static::assertSame('%s?%s', $baseContainer->getParameter('parameter'));
}

/**
* @param ContainerBuilder $baseContainer
* @param ContainerBuilder[] $externalContainers
Expand Down

0 comments on commit d40f5c7

Please sign in to comment.