Skip to content

Commit 0552fbf

Browse files
Merge branch '2.7' into 2.8
* 2.7: [FrameworkBundle] Check for class existence before is_subclass_of Update GroupSequence.php Code enhancement and cleanup [DI] Add anti-regression test Revert "minor #19689 [DI] Cleanup array_key_exists (ro0NL)" [BrowserKit] Fix cookie expiration on 32 bit systems bumped Symfony version to 2.7.18 updated VERSION for 2.7.17 update CONTRIBUTORS for 2.7.17 updated CHANGELOG for 2.7.17 Update misleading comment about RFC4627
2 parents e0eeba7 + 383ddfb commit 0552fbf

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

Compiler/ServiceReferenceGraphEdge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(ServiceReferenceGraphNode $sourceNode, ServiceRefere
3939
/**
4040
* Returns the value of the edge.
4141
*
42-
* @return ServiceReferenceGraphNode
42+
* @return string
4343
*/
4444
public function getValue()
4545
{

Container.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public function has($id)
230230
if ('service_container' === $id
231231
|| isset($this->aliases[$id])
232232
|| isset($this->services[$id])
233+
|| array_key_exists($id, $this->services)
233234
) {
234235
return true;
235236
}
@@ -272,7 +273,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
272273
$id = $this->aliases[$id];
273274
}
274275
// Re-use shared service instance if it exists.
275-
if (isset($this->services[$id])) {
276+
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
276277
return $this->services[$id];
277278
}
278279

@@ -354,7 +355,7 @@ public function initialized($id)
354355
$id = $this->aliases[$id];
355356
}
356357

357-
return isset($this->services[$id]);
358+
return isset($this->services[$id]) || array_key_exists($id, $this->services);
358359
}
359360

360361
/**

ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
455455
return $service;
456456
}
457457

458-
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
458+
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
459459
return $this->get($this->aliasDefinitions[$id]);
460460
}
461461

@@ -803,7 +803,7 @@ public function setDefinition($id, Definition $definition)
803803
*/
804804
public function hasDefinition($id)
805805
{
806-
return isset($this->definitions[strtolower($id)]);
806+
return array_key_exists(strtolower($id), $this->definitions);
807807
}
808808

809809
/**
@@ -819,7 +819,7 @@ public function getDefinition($id)
819819
{
820820
$id = strtolower($id);
821821

822-
if (!isset($this->definitions[$id])) {
822+
if (!array_key_exists($id, $this->definitions)) {
823823
throw new ServiceNotFoundException($id);
824824
}
825825

Tests/ContainerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ public function testGetReturnsNullOnInactiveScope()
267267
$this->assertNull($sc->get('inactive', ContainerInterface::NULL_ON_INVALID_REFERENCE));
268268
}
269269

270+
/**
271+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
272+
* @expectedExcepionMessage You have requested a synthetic service ("request"). The DIC does not know how to construct this service.
273+
*/
274+
public function testGetSyntheticServiceAlwaysThrows()
275+
{
276+
require_once __DIR__.'/Fixtures/php/services9.php';
277+
278+
$container = new \ProjectServiceContainer();
279+
$container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE);
280+
}
281+
270282
public function testHas()
271283
{
272284
$sc = new ProjectServiceContainer();
@@ -344,14 +356,17 @@ public function testEnterLeaveCurrentScope()
344356
$container->addScope(new Scope('foo'));
345357

346358
$container->enterScope('foo');
359+
$container->set('foo', new \stdClass(), 'foo');
347360
$scoped1 = $container->get('scoped');
348361
$scopedFoo1 = $container->get('scoped_foo');
349362

350363
$container->enterScope('foo');
364+
$container->set('foo', new \stdClass(), 'foo');
351365
$scoped2 = $container->get('scoped');
352366
$scoped3 = $container->get('SCOPED');
353367
$scopedFoo2 = $container->get('scoped_foo');
354368

369+
$container->set('foo', null, 'foo');
355370
$container->leaveScope('foo');
356371
$scoped4 = $container->get('scoped');
357372
$scopedFoo3 = $container->get('scoped_foo');
@@ -734,6 +749,12 @@ protected function getScopedSynchronizedFooService()
734749
return $this->services['scoped_bar'] = $this->scopedServices['foo']['scoped_bar'] = new \stdClass();
735750
}
736751

752+
protected function synchronizeFooService()
753+
{
754+
// Typically get the service to pass it to a setter
755+
$this->get('foo');
756+
}
757+
737758
protected function synchronizeScopedSynchronizedFooService()
738759
{
739760
$this->synchronized = true;

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function testAddServiceInvalidServiceId()
169169

170170
/**
171171
* @dataProvider provideInvalidFactories
172-
* @expectedException Symfony\Component\DependencyInjection\Exception\RuntimeException
172+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
173173
* @expectedExceptionMessage Cannot dump definition
174174
*/
175175
public function testInvalidFactories($factory)

0 commit comments

Comments
 (0)