Skip to content

Commit acbd4ac

Browse files
Merge branch '3.1'
* 3.1: [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 f79ccae + 6e4f331 commit acbd4ac

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
@@ -200,7 +200,6 @@ public function has($id)
200200
if ('service_container' === $id
201201
|| isset($this->aliases[$id])
202202
|| isset($this->services[$id])
203-
|| array_key_exists($id, $this->services)
204203
) {
205204
return true;
206205
}
@@ -247,7 +246,7 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
247246
$id = $this->aliases[$id];
248247
}
249248
// Re-use shared service instance if it exists.
250-
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
249+
if (isset($this->services[$id])) {
251250
return $this->services[$id];
252251
}
253252

@@ -269,10 +268,10 @@ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE
269268
}
270269

271270
$alternatives = array();
272-
foreach ($this->services as $key => $associatedService) {
273-
$lev = levenshtein($id, $key);
274-
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
275-
$alternatives[] = $key;
271+
foreach ($this->getServiceIds() as $knownId) {
272+
$lev = levenshtein($id, $knownId);
273+
if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) {
274+
$alternatives[] = $knownId;
276275
}
277276
}
278277

@@ -320,7 +319,7 @@ public function initialized($id)
320319
$id = $this->aliases[$id];
321320
}
322321

323-
return isset($this->services[$id]) || array_key_exists($id, $this->services);
322+
return isset($this->services[$id]);
324323
}
325324

326325
/**

ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
411411
return $service;
412412
}
413413

414-
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
414+
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
415415
return $this->get($this->aliasDefinitions[$id]);
416416
}
417417

@@ -749,7 +749,7 @@ public function setDefinition($id, Definition $definition)
749749
*/
750750
public function hasDefinition($id)
751751
{
752-
return array_key_exists(strtolower($id), $this->definitions);
752+
return isset($this->definitions[strtolower($id)]);
753753
}
754754

755755
/**
@@ -765,7 +765,7 @@ public function getDefinition($id)
765765
{
766766
$id = strtolower($id);
767767

768-
if (!array_key_exists($id, $this->definitions)) {
768+
if (!isset($this->definitions[$id])) {
769769
throw new ServiceNotFoundException($id);
770770
}
771771

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
}
@@ -866,6 +867,26 @@ public function compile()
866867
throw new LogicException('You cannot compile a dumped frozen container.');
867868
}
868869
870+
EOF;
871+
}
872+
873+
/**
874+
* Adds the isFrozen method for a frozen container.
875+
*
876+
* @return string
877+
*/
878+
private function addIsFrozenMethod()
879+
{
880+
return <<<EOF
881+
882+
/*{$this->docStar}
883+
* {@inheritdoc}
884+
*/
885+
public function isFrozen()
886+
{
887+
return true;
888+
}
889+
869890
EOF;
870891
}
871892

Tests/ContainerTest.php

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

184183
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)