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
*

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

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

src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class ValueExporter
2727
*/
2828
public function exportValue($value, $depth = 1, $deep = false)
2929
{
30+
if ($value instanceof \__PHP_Incomplete_Class) {
31+
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
32+
}
33+
3034
if (is_object($value)) {
3135
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
3236
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
@@ -35,10 +39,6 @@ public function exportValue($value, $depth = 1, $deep = false)
3539
return sprintf('Object(%s)', get_class($value));
3640
}
3741

38-
if ($value instanceof \__PHP_Incomplete_Class) {
39-
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
40-
}
41-
4242
if (is_array($value)) {
4343
if (empty($value)) {
4444
return '[]';

src/Symfony/Component/HttpKernel/EventListener/DumpListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\HttpKernel\EventListener;
1313

14+
use Symfony\Component\Console\ConsoleEvents;
1415
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15-
use Symfony\Component\HttpKernel\KernelEvents;
1616
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
1717
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
1818
use Symfony\Component\VarDumper\VarDumper;
@@ -50,6 +50,6 @@ public function configure()
5050
public static function getSubscribedEvents()
5151
{
5252
// Register early to have a working dump() as early as possible
53-
return array(KernelEvents::REQUEST => array('configure', 1024));
53+
return array(ConsoleEvents::COMMAND => array('configure', 1024));
5454
}
5555
}

src/Symfony/Component/HttpKernel/Tests/EventListener/DumpListenerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\Component\HttpKernel\Tests\EventListener;
1313

14+
use Symfony\Component\Console\ConsoleEvents;
1415
use Symfony\Component\HttpKernel\EventListener\DumpListener;
15-
use Symfony\Component\HttpKernel\KernelEvents;
1616
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
1717
use Symfony\Component\VarDumper\Cloner\Data;
1818
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
@@ -28,7 +28,7 @@ class DumpListenerTest extends \PHPUnit_Framework_TestCase
2828
public function testSubscribedEvents()
2929
{
3030
$this->assertSame(
31-
array(KernelEvents::REQUEST => array('configure', 1024)),
31+
array(ConsoleEvents::COMMAND => array('configure', 1024)),
3232
DumpListener::getSubscribedEvents()
3333
);
3434
}

src/Symfony/Component/VarDumper/Caster/CutStub.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ public function __construct($value)
3939

4040
case 'resource':
4141
case 'unknown type':
42+
case 'resource (closed)':
4243
$this->type = self::TYPE_RESOURCE;
4344
$this->handle = (int) $value;
44-
$this->class = @get_resource_type($value);
45+
if ('Unknown' === $this->class = @get_resource_type($value)) {
46+
$this->class = 'Closed';
47+
}
4548
$this->cut = -1;
4649
break;
4750

src/Symfony/Component/VarDumper/Cloner/VarCloner.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,13 @@ protected function doClone($var)
183183

184184
case 'resource':
185185
case 'unknown type':
186+
case 'resource (closed)':
186187
if (empty($resRefs[$h = (int) $v])) {
187188
$stub = new Stub();
188189
$stub->type = Stub::TYPE_RESOURCE;
189-
$stub->class = $zval['resource_type'] ?: get_resource_type($v);
190+
if ('Unknown' === $stub->class = $zval['resource_type'] ?: @get_resource_type($v)) {
191+
$stub->class = 'Closed';
192+
}
190193
$stub->value = $v;
191194
$stub->handle = $h;
192195
$a = $this->castResource($stub, 0 < $i);

src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function testClosedResource()
193193

194194
$this->assertStringMatchesFormat(
195195
<<<EOTXT
196-
Unknown resource @{$res}
196+
Closed resource @{$res}
197197
198198
EOTXT
199199
,

0 commit comments

Comments
 (0)