Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab93dd8

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 c14fff0 + e0acca6 commit ab93dd8

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

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

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

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

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

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

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

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

123123
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
124124
}
@@ -157,7 +157,7 @@ public function testFixClassWithTraitsOrdering()
157157
$m = $r->getMethod('getOrderedClasses');
158158
$m->setAccessible(true);
159159

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

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

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) {
@@ -240,9 +243,6 @@ private function flattenArgs($args, $level = 0, &$count = 0)
240243
$result[$key] = array('float', $value);
241244
} elseif (is_resource($value)) {
242245
$result[$key] = array('resource', get_resource_type($value));
243-
} elseif ($value instanceof \__PHP_Incomplete_Class) {
244-
// Special case of object, is_object will return false
245-
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
246246
} else {
247247
$result[$key] = array('string', (string) $value);
248248
}

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

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

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
}
@@ -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

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

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)