Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI] Add "force_parameters_escape" option to dumpers #34541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function process(ContainerBuilder $container)
{
$cache = new ConfigCache($container->getParameter('debug.container.dump'), true);
if (!$cache->isFresh()) {
$cache->write((new XmlDumper($container))->dump(), $container->getResources());
$cache->write((new XmlDumper($container))->dump([
'force_parameters_escape' => true,
]), $container->getResources());
}
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ext-xml": "*",
"symfony/cache": "~3.4.31|^4.3.4",
"symfony/class-loader": "~3.2",
"symfony/dependency-injection": "^3.4.24|^4.2.5",
"symfony/dependency-injection": "^3.4.36|^4.3.9",
"symfony/config": "^3.4.31|^4.3.4",
"symfony/debug": "~2.8|~3.0|~4.0",
"symfony/event-dispatcher": "~3.4|~4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function dump(array $options = [])
$container->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$container->setAttribute('xsi:schemaLocation', 'http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd');

$this->addParameters($container);
$this->addParameters($container, isset($options['force_parameters_escape']) ? $options['force_parameters_escape'] : false);
$this->addServices($container);

$this->document->appendChild($container);
Expand All @@ -59,14 +59,17 @@ public function dump(array $options = [])
return $this->container->resolveEnvPlaceholders($xml);
}

private function addParameters(\DOMElement $parent)
/**
* @param bool $forceEscape
*/
private function addParameters(\DOMElement $parent, $forceEscape)
{
$data = $this->container->getParameterBag()->all();
if (!$data) {
return;
}

if ($this->container->isCompiled()) {
if ($this->container->isCompiled() || $forceEscape) {
$data = $this->escape($data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function dump(array $options = [])
$this->dumper = new YmlDumper();
}

return $this->container->resolveEnvPlaceholders($this->addParameters()."\n".$this->addServices());
return $this->container->resolveEnvPlaceholders($this->addParameters(isset($options['force_parameters_escape']) ? $options['force_parameters_escape'] : false)."\n".$this->addServices());
}

/**
Expand Down Expand Up @@ -212,15 +212,17 @@ private function addServices()
/**
* Adds parameters.
*
* @param bool $forceEscape
*
* @return string
*/
private function addParameters()
private function addParameters($forceEscape)
{
if (!$this->container->getParameterBag()->all()) {
return '';
}

$parameters = $this->prepareParameters($this->container->getParameterBag()->all(), $this->container->isCompiled());
$parameters = $this->prepareParameters($this->container->getParameterBag()->all(), $this->container->isCompiled() || $forceEscape);

return $this->dumper->dump(['parameters' => $parameters], 2);
}
Expand Down