Skip to content

Commit 6e4f331

Browse files
Merge branch '2.8' into 3.1
* 2.8: [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 d1524e5 + e0eeba7 commit 6e4f331

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
@@ -191,7 +191,6 @@ public function has($id)
191191
if ('service_container' === $id
192192
|| isset($this->aliases[$id])
193193
|| isset($this->services[$id])
194-
|| array_key_exists($id, $this->services)
195194
) {
196195
return true;
197196
}
@@ -234,7 +233,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
234233
$id = $this->aliases[$id];
235234
}
236235
// Re-use shared service instance if it exists.
237-
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
236+
if (isset($this->services[$id])) {
238237
return $this->services[$id];
239238
}
240239

@@ -256,10 +255,10 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
256255
}
257256

258257
$alternatives = array();
259-
foreach ($this->services as $key => $associatedService) {
260-
$lev = levenshtein($id, $key);
261-
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
262-
$alternatives[] = $key;
258+
foreach ($this->getServiceIds() as $knownId) {
259+
$lev = levenshtein($id, $knownId);
260+
if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) {
261+
$alternatives[] = $knownId;
263262
}
264263
}
265264

@@ -304,7 +303,7 @@ public function initialized($id)
304303
$id = $this->aliases[$id];
305304
}
306305

307-
return isset($this->services[$id]) || array_key_exists($id, $this->services);
306+
return isset($this->services[$id]);
308307
}
309308

310309
/**

ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
397397
return $service;
398398
}
399399

400-
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
400+
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
401401
return $this->get($this->aliasDefinitions[$id]);
402402
}
403403

@@ -733,7 +733,7 @@ public function setDefinition($id, Definition $definition)
733733
*/
734734
public function hasDefinition($id)
735735
{
736-
return array_key_exists(strtolower($id), $this->definitions);
736+
return isset($this->definitions[strtolower($id)]);
737737
}
738738

739739
/**
@@ -749,7 +749,7 @@ public function getDefinition($id)
749749
{
750750
$id = strtolower($id);
751751

752-
if (!array_key_exists($id, $this->definitions)) {
752+
if (!isset($this->definitions[$id])) {
753753
throw new ServiceNotFoundException($id);
754754
}
755755

Dumper/PhpDumper.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public function dump(array $options = array())
143143
if ($this->container->isFrozen()) {
144144
$code .= $this->addFrozenConstructor();
145145
$code .= $this->addFrozenCompile();
146+
$code .= $this->addIsFrozenMethod();
146147
} else {
147148
$code .= $this->addConstructor();
148149
}
@@ -865,6 +866,26 @@ public function compile()
865866
throw new LogicException('You cannot compile a dumped frozen container.');
866867
}
867868
869+
EOF;
870+
}
871+
872+
/**
873+
* Adds the isFrozen method for a frozen container.
874+
*
875+
* @return string
876+
*/
877+
private function addIsFrozenMethod()
878+
{
879+
return <<<EOF
880+
881+
/*{$this->docStar}
882+
* {@inheritdoc}
883+
*/
884+
public function isFrozen()
885+
{
886+
return true;
887+
}
888+
868889
EOF;
869890
}
870891

Tests/ContainerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ public function testGetThrowServiceNotFoundException()
177177
{
178178
$sc = new ProjectServiceContainer();
179179
$sc->set('foo', $foo = new \stdClass());
180-
$sc->set('bar', $foo = new \stdClass());
181180
$sc->set('baz', $foo = new \stdClass());
182181

183182
try {

Tests/Fixtures/php/services10.php

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

44+
/**
45+
* {@inheritdoc}
46+
*/
47+
public function isFrozen()
48+
{
49+
return true;
50+
}
51+
4452
/**
4553
* Gets the 'test' service.
4654
*

Tests/Fixtures/php/services12.php

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

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

Tests/Fixtures/php/services13.php

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

42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function isFrozen()
46+
{
47+
return true;
48+
}
49+
4250
/**
4351
* Gets the 'bar' service.
4452
*

Tests/Fixtures/php/services9_compiled.php

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

63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function isFrozen()
67+
{
68+
return true;
69+
}
70+
6371
/**
6472
* Gets the 'bar' service.
6573
*

0 commit comments

Comments
 (0)