Skip to content

Commit c400875

Browse files
committed
Merge branch '2.0' into 2.1
* 2.0: [DependencyInjection] Allow frozen containers to be dumped to graphviz Add dot character `.` to legal mime subtype regular expression [HttpFoundation] fixed the creation of sub-requests under some circumstancies (closes #6923, closes #6936)
2 parents e0af6f7 + ff9dae0 commit c400875

File tree

6 files changed

+75
-2
lines changed

6 files changed

+75
-2
lines changed

Dumper/GraphvizDumper.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\Component\DependencyInjection\Reference;
1616
use Symfony\Component\DependencyInjection\Parameter;
1717
use Symfony\Component\DependencyInjection\ContainerInterface;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
1820

1921
/**
2022
* GraphvizDumper dumps a service container as a graphviz file.
@@ -159,7 +161,7 @@ private function findNodes()
159161
{
160162
$nodes = array();
161163

162-
$container = clone $this->container;
164+
$container = $this->cloneContainer();
163165

164166
foreach ($container->getDefinitions() as $id => $definition) {
165167
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $this->container->getParameterBag()->resolveValue($definition->getClass())), 'attributes' => array_merge($this->options['node.definition'], array('style' => ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope() ? 'filled' : 'dotted')));
@@ -175,13 +177,31 @@ private function findNodes()
175177
}
176178

177179
if (!$container->hasDefinition($id)) {
178-
$nodes[$id] = array('class' => str_replace('\\', '\\\\', get_class($service)), 'attributes' => $this->options['node.instance']);
180+
$class = ('service_container' === $id) ? get_class($this->container) : get_class($service);
181+
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => $this->options['node.instance']);
179182
}
180183
}
181184

182185
return $nodes;
183186
}
184187

188+
private function cloneContainer()
189+
{
190+
$parameterBag = new ParameterBag($this->container->getParameterBag()->all());
191+
192+
$container = new ContainerBuilder($parameterBag);
193+
$container->setDefinitions($this->container->getDefinitions());
194+
$container->setAliases($this->container->getAliases());
195+
foreach ($this->container->getScopes() as $scope) {
196+
$container->addScope($scope);
197+
}
198+
foreach ($this->container->getExtensions() as $extension) {
199+
$container->registerExtension($extension);
200+
}
201+
202+
return $container;
203+
}
204+
185205
/**
186206
* Returns the start dot.
187207
*

Tests/Dumper/GraphvizDumperTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,18 @@ public function testDump()
5555
'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'),
5656
)), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services');
5757
}
58+
59+
public function testDumpWithFrozenContainer()
60+
{
61+
$container = include self::$fixturesPath.'/containers/container13.php';
62+
$dumper = new GraphvizDumper($container);
63+
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services13.dot')), $dumper->dump(), '->dump() dumps services');
64+
}
65+
66+
public function testDumpWithFrozenCustomClassContainer()
67+
{
68+
$container = include self::$fixturesPath.'/containers/container14.php';
69+
$dumper = new GraphvizDumper($container);
70+
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services');
71+
}
5872
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerBuilder;
4+
use Symfony\Component\DependencyInjection\Definition;
5+
6+
$container = new ContainerBuilder();
7+
$container->
8+
register('foo', 'FooClass')->
9+
addArgument(new Reference('bar'))
10+
;
11+
$container->compile();
12+
13+
return $container;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Container14;
4+
5+
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
7+
class ProjectServiceContainer extends ContainerBuilder
8+
{
9+
}
10+
11+
return new ProjectServiceContainer();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
digraph sc {
2+
ratio="compress"
3+
node [fontsize="11" fontname="Arial" shape="record"];
4+
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
5+
6+
node_foo [label="foo\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
7+
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
digraph sc {
2+
ratio="compress"
3+
node [fontsize="11" fontname="Arial" shape="record"];
4+
edge [fontsize="9" fontname="Arial" color="grey" arrowhead="open" arrowsize="0.5"];
5+
6+
node_service_container [label="service_container\nContainer14\\ProjectServiceContainer\n", shape=record, fillcolor="#9999ff", style="filled"];
7+
}

0 commit comments

Comments
 (0)