Skip to content

Commit 3483972

Browse files
committed
Merge branch '2.1' into 2.2
* 2.1: added support for the X-Forwarded-For header (closes #6982, closes #7000) fixed the IP address in HttpCache when calling the backend [EventDispatcher] Added assertion. [EventDispathcer] Fix removeListener [DependencyInjection] Add clone for resources which were introduced in 2.1 [DependencyInjection] Allow frozen containers to be dumped to graphviz Fix 'undefined index' error, when entering scope recursively [Security] fixed session creation on login (closes #7011) 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 5be179b + b120ead commit 3483972

File tree

8 files changed

+112
-4
lines changed

8 files changed

+112
-4
lines changed

Container.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,10 @@ public function enterScope($name)
338338
unset($this->scopedServices[$name]);
339339

340340
foreach ($this->scopeChildren[$name] as $child) {
341-
$services[$child] = $this->scopedServices[$child];
342-
unset($this->scopedServices[$child]);
341+
if (isset($this->scopedServices[$child])) {
342+
$services[$child] = $this->scopedServices[$child];
343+
unset($this->scopedServices[$child]);
344+
}
343345
}
344346

345347
// update global map

Dumper/GraphvizDumper.php

Lines changed: 23 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,32 @@ 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+
$container->setResources($this->container->getResources());
196+
foreach ($this->container->getScopes() as $scope) {
197+
$container->addScope($scope);
198+
}
199+
foreach ($this->container->getExtensions() as $extension) {
200+
$container->registerExtension($extension);
201+
}
202+
203+
return $container;
204+
}
205+
185206
/**
186207
* Returns the start dot.
187208
*

Tests/ContainerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,38 @@ public function testEnterLeaveScopeWithChildScopes()
261261
$this->assertFalse($container->has('a'));
262262
}
263263

264+
public function testEnterScopeRecursivelyWithInactiveChildScopes()
265+
{
266+
$container = new Container();
267+
$container->addScope(new Scope('foo'));
268+
$container->addScope(new Scope('bar', 'foo'));
269+
270+
$this->assertFalse($container->isScopeActive('foo'));
271+
272+
$container->enterScope('foo');
273+
274+
$this->assertTrue($container->isScopeActive('foo'));
275+
$this->assertFalse($container->isScopeActive('bar'));
276+
$this->assertFalse($container->has('a'));
277+
278+
$a = new \stdClass();
279+
$container->set('a', $a, 'foo');
280+
281+
$services = $this->getField($container, 'scopedServices');
282+
$this->assertTrue(isset($services['foo']['a']));
283+
$this->assertSame($a, $services['foo']['a']);
284+
285+
$this->assertTrue($container->has('a'));
286+
$container->enterScope('foo');
287+
288+
$services = $this->getField($container, 'scopedServices');
289+
$this->assertFalse(isset($services['a']));
290+
291+
$this->assertTrue($container->isScopeActive('foo'));
292+
$this->assertFalse($container->isScopeActive('bar'));
293+
$this->assertFalse($container->has('a'));
294+
}
295+
264296
public function testLeaveScopeNotActive()
265297
{
266298
$container = new Container();

Tests/Dumper/GraphvizDumperTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,18 @@ public function testDump()
4848
'node.missing' => array('fillcolor' => 'red', 'style' => 'empty'),
4949
)), str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services10-1.dot')), '->dump() dumps services');
5050
}
51+
52+
public function testDumpWithFrozenContainer()
53+
{
54+
$container = include self::$fixturesPath.'/containers/container13.php';
55+
$dumper = new GraphvizDumper($container);
56+
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services13.dot')), $dumper->dump(), '->dump() dumps services');
57+
}
58+
59+
public function testDumpWithFrozenCustomClassContainer()
60+
{
61+
$container = include self::$fixturesPath.'/containers/container14.php';
62+
$dumper = new GraphvizDumper($container);
63+
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services14.dot')), $dumper->dump(), '->dump() dumps services');
64+
}
5165
}
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)