Skip to content

Commit e0eeba7

Browse files
Merge branch '2.7' into 2.8
* 2.7: [ClassLoader] Fix tests [Debug][HttpKernel][VarDumper] Prepare for committed 7.2 changes [DependencyInjection] PhpDumper::isFrozen inconsistency [DI] Cleanup array_key_exists include dynamic services in list of alternatives [Debug] Swap dumper services at bootstrap
2 parents adf2d92 + 31adf72 commit e0eeba7

File tree

8 files changed

+62
-11
lines changed

8 files changed

+62
-11
lines changed

Container.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ 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)
234233
) {
235234
return true;
236235
}
@@ -273,7 +272,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
273272
$id = $this->aliases[$id];
274273
}
275274
// Re-use shared service instance if it exists.
276-
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
275+
if (isset($this->services[$id])) {
277276
return $this->services[$id];
278277
}
279278

@@ -295,10 +294,10 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
295294
}
296295

297296
$alternatives = array();
298-
foreach ($this->services as $key => $associatedService) {
299-
$lev = levenshtein($id, $key);
300-
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
301-
$alternatives[] = $key;
297+
foreach ($this->getServiceIds() as $knownId) {
298+
$lev = levenshtein($id, $knownId);
299+
if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) {
300+
$alternatives[] = $knownId;
302301
}
303302
}
304303

@@ -355,7 +354,7 @@ public function initialized($id)
355354
$id = $this->aliases[$id];
356355
}
357356

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

361360
/**

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 (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
458+
if (!isset($this->definitions[$id]) && 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 array_key_exists(strtolower($id), $this->definitions);
806+
return isset($this->definitions[strtolower($id)]);
807807
}
808808

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

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

Dumper/PhpDumper.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public function dump(array $options = array())
144144
if ($this->container->isFrozen()) {
145145
$code .= $this->addFrozenConstructor();
146146
$code .= $this->addFrozenCompile();
147+
$code .= $this->addIsFrozenMethod();
147148
} else {
148149
$code .= $this->addConstructor();
149150
}
@@ -977,6 +978,26 @@ public function compile()
977978
throw new LogicException('You cannot compile a dumped frozen container.');
978979
}
979980
981+
EOF;
982+
}
983+
984+
/**
985+
* Adds the isFrozen method for a frozen container.
986+
*
987+
* @return string
988+
*/
989+
private function addIsFrozenMethod()
990+
{
991+
return <<<EOF
992+
993+
/*{$this->docStar}
994+
* {@inheritdoc}
995+
*/
996+
public function isFrozen()
997+
{
998+
return true;
999+
}
1000+
9801001
EOF;
9811002
}
9821003

Tests/ContainerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ public function testGetThrowServiceNotFoundException()
227227
{
228228
$sc = new ProjectServiceContainer();
229229
$sc->set('foo', $foo = new \stdClass());
230-
$sc->set('bar', $foo = new \stdClass());
231230
$sc->set('baz', $foo = new \stdClass());
232231

233232
try {

Tests/Fixtures/php/services10.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ public function compile()
4646
throw new LogicException('You cannot compile a dumped frozen container.');
4747
}
4848

49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function isFrozen()
53+
{
54+
return true;
55+
}
56+
4957
/**
5058
* Gets the 'test' service.
5159
*

Tests/Fixtures/php/services12.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ public function compile()
5050
throw new LogicException('You cannot compile a dumped frozen container.');
5151
}
5252

53+
/**
54+
* {@inheritdoc}
55+
*/
56+
public function isFrozen()
57+
{
58+
return true;
59+
}
60+
5361
/**
5462
* Gets the 'test' service.
5563
*

Tests/Fixtures/php/services13.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public function compile()
4444
throw new LogicException('You cannot compile a dumped frozen container.');
4545
}
4646

47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function isFrozen()
51+
{
52+
return true;
53+
}
54+
4755
/**
4856
* Gets the 'bar' service.
4957
*

Tests/Fixtures/php/services9_compiled.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public function compile()
6363
throw new LogicException('You cannot compile a dumped frozen container.');
6464
}
6565

66+
/**
67+
* {@inheritdoc}
68+
*/
69+
public function isFrozen()
70+
{
71+
return true;
72+
}
73+
6674
/**
6775
* Gets the 'bar' service.
6876
*

0 commit comments

Comments
 (0)