Skip to content

Commit 69fbdc9

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 909649f + 5e5e1db commit 69fbdc9

File tree

18 files changed

+90
-33
lines changed

18 files changed

+90
-33
lines changed

src/Symfony/Bundle/DebugBundle/DebugBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function boot()
3030
// configuration for CLI mode is overridden in HTTP mode on
3131
// 'kernel.request' event
3232
VarDumper::setHandler(function ($var) use ($container) {
33-
$dumper = $container->get('var_dumper.cli_dumper');
33+
$dumper = $container->get('data_collector.dump');
3434
$cloner = $container->get('var_dumper.cloner');
3535
$handler = function ($var) use ($dumper, $cloner) {
3636
$dumper->dump($cloner->cloneVar($var));

src/Symfony/Bundle/DebugBundle/Resources/config/services.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener">
2323
<tag name="kernel.event_subscriber" />
2424
<argument type="service" id="var_dumper.cloner" />
25-
<argument type="service" id="data_collector.dump" />
25+
<argument type="service" id="var_dumper.cli_dumper" />
2626
</service>
2727

2828
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" />

src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public function testTraitDependencies()
3131
$m = $r->getMethod('getOrderedClasses');
3232
$m->setAccessible(true);
3333

34-
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', array('CTFoo'));
34+
$ordered = $m->invoke(null, array('CTFoo'));
3535

3636
$this->assertEquals(
3737
array('TD', 'TC', 'TB', 'TA', 'TZ', 'CTFoo'),
3838
array_map(function ($class) { return $class->getName(); }, $ordered)
3939
);
4040

41-
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', array('CTBar'));
41+
$ordered = $m->invoke(null, array('CTBar'));
4242

4343
$this->assertEquals(
4444
array('TD', 'TZ', 'TC', 'TB', 'TA', 'CTBar'),
@@ -62,7 +62,7 @@ public function testClassReordering(array $classes)
6262
$m = $r->getMethod('getOrderedClasses');
6363
$m->setAccessible(true);
6464

65-
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
65+
$ordered = $m->invoke(null, $classes);
6666

6767
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
6868
}
@@ -120,7 +120,7 @@ public function testClassWithTraitsReordering(array $classes)
120120
$m = $r->getMethod('getOrderedClasses');
121121
$m->setAccessible(true);
122122

123-
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
123+
$ordered = $m->invoke(null, $classes);
124124

125125
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
126126
}
@@ -162,7 +162,7 @@ public function testFixClassWithTraitsOrdering()
162162
$m = $r->getMethod('getOrderedClasses');
163163
$m->setAccessible(true);
164164

165-
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
165+
$ordered = $m->invoke(null, $classes);
166166

167167
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
168168
}

src/Symfony/Component/Debug/Exception/FlattenException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ private function flattenArgs($args, $level = 0, &$count = 0)
263263
if (++$count > 1e4) {
264264
return array('array', '*SKIPPED over 10000 entries*');
265265
}
266-
if (is_object($value)) {
266+
if ($value instanceof \__PHP_Incomplete_Class) {
267+
// is_object() returns false on PHP<=7.1
268+
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
269+
} elseif (is_object($value)) {
267270
$result[$key] = array('object', get_class($value));
268271
} elseif (is_array($value)) {
269272
if ($level > 10) {
@@ -277,9 +280,6 @@ private function flattenArgs($args, $level = 0, &$count = 0)
277280
$result[$key] = array('boolean', $value);
278281
} elseif (is_resource($value)) {
279282
$result[$key] = array('resource', get_resource_type($value));
280-
} elseif ($value instanceof \__PHP_Incomplete_Class) {
281-
// Special case of object, is_object will return false
282-
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
283283
} else {
284284
$result[$key] = array('string', (string) $value);
285285
}

src/Symfony/Component/DependencyInjection/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
/**

src/Symfony/Component/DependencyInjection/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

src/Symfony/Component/DependencyInjection/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

src/Symfony/Component/DependencyInjection/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 {

src/Symfony/Component/DependencyInjection/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
*

src/Symfony/Component/DependencyInjection/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
*

0 commit comments

Comments
 (0)