Skip to content

Commit 31536c3

Browse files
committed
merged 2.0
1 parent 268b618 commit 31536c3

File tree

6 files changed

+128
-10
lines changed

6 files changed

+128
-10
lines changed

src/Symfony/Component/Config/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
7272
}
7373
self::$loading[$resource] = true;
7474

75-
$ret = $loader->load($resource);
75+
$ret = $loader->load($resource, $type);
7676

7777
unset(self::$loading[$resource]);
7878

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,13 @@ private function addFrozenConstructor()
694694
*/
695695
public function __construct()
696696
{
697-
\$this->parameters = \$this->getDefaultParameters();
697+
EOF;
698+
699+
if ($this->container->getParameterBag()->all()) {
700+
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
701+
}
702+
703+
$code .= <<<EOF
698704
699705
\$this->services =
700706
\$this->scopedServices =

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ public function testDump()
4444
new PhpDumper($container);
4545
}
4646

47+
public function testDumpFrozenContainerWithNoParameter()
48+
{
49+
$container = new ContainerBuilder();
50+
$container->register('foo', 'stdClass');
51+
52+
$container->compile();
53+
54+
$dumper = new PhpDumper($container);
55+
56+
$dumpedString = $dumper->dump();
57+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services11.php', $dumpedString, '->dump() does not add getDefaultParameters() method call if container have no parameters.');
58+
$this->assertNotRegexp("/function getDefaultParameters\(/", $dumpedString, '->dump() does not add getDefaultParameters() method definition.');
59+
}
60+
4761
public function testDumpOptimizationString()
4862
{
4963
$definition = new Definition();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerInterface;
4+
use Symfony\Component\DependencyInjection\Container;
5+
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
6+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7+
use Symfony\Component\DependencyInjection\Exception\LogicException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\Reference;
10+
use Symfony\Component\DependencyInjection\Parameter;
11+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
12+
13+
/**
14+
* ProjectServiceContainer
15+
*
16+
* This class has been auto-generated
17+
* by the Symfony Dependency Injection Component.
18+
*/
19+
class ProjectServiceContainer extends Container
20+
{
21+
/**
22+
* Constructor.
23+
*/
24+
public function __construct()
25+
{
26+
$this->services =
27+
$this->scopedServices =
28+
$this->scopeStacks = array();
29+
30+
$this->set('service_container', $this);
31+
32+
$this->scopes = array();
33+
$this->scopeChildren = array();
34+
}
35+
36+
/**
37+
* Gets the 'foo' service.
38+
*
39+
* This service is shared.
40+
* This method always returns the same instance of the service.
41+
*
42+
* @return stdClass A stdClass instance.
43+
*/
44+
protected function getFooService()
45+
{
46+
return $this->services['foo'] = new \stdClass();
47+
}
48+
}

src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,26 @@ public function handle(GetResponseEvent $event)
7575

7676
if (null === $session || null === $token = $session->get('_security_'.$this->contextKey)) {
7777
$this->context->setToken(null);
78-
} else {
79-
if (null !== $this->logger) {
80-
$this->logger->debug('Read SecurityContext from the session');
81-
}
78+
return;
79+
}
8280

83-
$token = unserialize($token);
81+
$token = unserialize($token);
8482

85-
if (null !== $token) {
86-
$token = $this->refreshUser($token);
83+
if (null !== $this->logger) {
84+
$this->logger->debug('Read SecurityContext from the session');
85+
}
86+
87+
if ($token instanceof TokenInterface) {
88+
$token = $this->refreshUser($token);
89+
} elseif (null !== $token) {
90+
if (null !== $this->logger) {
91+
$this->logger->warn(sprintf('Session includes a "%s" where a security token is expected', is_object($value) ? get_class($value) : gettype($value)));
8792
}
8893

89-
$this->context->setToken($token);
94+
$token = null;
9095
}
96+
97+
$this->context->setToken($token);
9198
}
9299

93100
/**

src/Symfony/Component/Security/Tests/Http/Firewall/ContextListenerTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,47 @@ public function testOnKernelResponseWithoutSession()
125125

126126
$this->assertFalse($request->hasSession());
127127
}
128+
129+
/**
130+
* @dataProvider provideInvalidToken
131+
*/
132+
public function testInvalidTokenInSession($token)
133+
{
134+
$context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
135+
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
136+
->disableOriginalConstructor()
137+
->getMock();
138+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
139+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session')
140+
->disableOriginalConstructor()
141+
->getMock();
142+
143+
$event->expects($this->any())
144+
->method('getRequest')
145+
->will($this->returnValue($request));
146+
$request->expects($this->any())
147+
->method('hasPreviousSession')
148+
->will($this->returnValue(true));
149+
$request->expects($this->any())
150+
->method('getSession')
151+
->will($this->returnValue($session));
152+
$session->expects($this->any())
153+
->method('get')
154+
->with('_security_key123')
155+
->will($this->returnValue(serialize($token)));
156+
$context->expects($this->once())
157+
->method('setToken')
158+
->with(null);
159+
160+
$listener = new ContextListener($context, array(), 'key123');
161+
$listener->handle($event);
162+
}
163+
164+
public function provideInvalidToken()
165+
{
166+
return array(
167+
array(new \__PHP_Incomplete_Class()),
168+
array(null),
169+
);
170+
}
128171
}

0 commit comments

Comments
 (0)