Skip to content

Commit e0acca6

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 298a680 + 69fbdc9 commit e0acca6

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
@@ -28,14 +28,14 @@ public function testTraitDependencies()
2828
$m = $r->getMethod('getOrderedClasses');
2929
$m->setAccessible(true);
3030

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

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

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

4040
$this->assertEquals(
4141
array('TD', 'TZ', 'TC', 'TB', 'TA', 'CTBar'),
@@ -59,7 +59,7 @@ public function testClassReordering(array $classes)
5959
$m = $r->getMethod('getOrderedClasses');
6060
$m->setAccessible(true);
6161

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

6464
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
6565
}
@@ -116,7 +116,7 @@ public function testClassWithTraitsReordering(array $classes)
116116
$m = $r->getMethod('getOrderedClasses');
117117
$m->setAccessible(true);
118118

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

121121
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
122122
}
@@ -155,7 +155,7 @@ public function testFixClassWithTraitsOrdering()
155155
$m = $r->getMethod('getOrderedClasses');
156156
$m->setAccessible(true);
157157

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

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ private function flattenArgs($args, $level = 0, &$count = 0)
222222
if (++$count > 1e4) {
223223
return array('array', '*SKIPPED over 10000 entries*');
224224
}
225-
if (is_object($value)) {
225+
if ($value instanceof \__PHP_Incomplete_Class) {
226+
// is_object() returns false on PHP<=7.1
227+
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
228+
} elseif (is_object($value)) {
226229
$result[$key] = array('object', get_class($value));
227230
} elseif (is_array($value)) {
228231
if ($level > 10) {
@@ -236,9 +239,6 @@ private function flattenArgs($args, $level = 0, &$count = 0)
236239
$result[$key] = array('boolean', $value);
237240
} elseif (is_resource($value)) {
238241
$result[$key] = array('resource', get_resource_type($value));
239-
} elseif ($value instanceof \__PHP_Incomplete_Class) {
240-
// Special case of object, is_object will return false
241-
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
242242
} else {
243243
$result[$key] = array('string', (string) $value);
244244
}

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

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

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

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

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

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

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

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

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 \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
@@ -188,7 +188,7 @@ public function testClosedResource()
188188

189189
$this->assertStringMatchesFormat(
190190
<<<EOTXT
191-
Unknown resource @{$res}
191+
Closed resource @{$res}
192192
193193
EOTXT
194194
,

0 commit comments

Comments
 (0)