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
This commit is contained in:
commit
69fbdc93cf
@ -30,7 +30,7 @@ class DebugBundle extends Bundle
|
||||
// configuration for CLI mode is overridden in HTTP mode on
|
||||
// 'kernel.request' event
|
||||
VarDumper::setHandler(function ($var) use ($container) {
|
||||
$dumper = $container->get('var_dumper.cli_dumper');
|
||||
$dumper = $container->get('data_collector.dump');
|
||||
$cloner = $container->get('var_dumper.cloner');
|
||||
$handler = function ($var) use ($dumper, $cloner) {
|
||||
$dumper->dump($cloner->cloneVar($var));
|
||||
|
@ -22,7 +22,7 @@
|
||||
<service id="debug.dump_listener" class="Symfony\Component\HttpKernel\EventListener\DumpListener">
|
||||
<tag name="kernel.event_subscriber" />
|
||||
<argument type="service" id="var_dumper.cloner" />
|
||||
<argument type="service" id="data_collector.dump" />
|
||||
<argument type="service" id="var_dumper.cli_dumper" />
|
||||
</service>
|
||||
|
||||
<service id="var_dumper.cloner" class="Symfony\Component\VarDumper\Cloner\VarCloner" />
|
||||
|
@ -31,14 +31,14 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', array('CTFoo'));
|
||||
$ordered = $m->invoke(null, array('CTFoo'));
|
||||
|
||||
$this->assertEquals(
|
||||
array('TD', 'TC', 'TB', 'TA', 'TZ', 'CTFoo'),
|
||||
array_map(function ($class) { return $class->getName(); }, $ordered)
|
||||
);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', array('CTBar'));
|
||||
$ordered = $m->invoke(null, array('CTBar'));
|
||||
|
||||
$this->assertEquals(
|
||||
array('TD', 'TZ', 'TC', 'TB', 'TA', 'CTBar'),
|
||||
@ -62,7 +62,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
|
||||
$ordered = $m->invoke(null, $classes);
|
||||
|
||||
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
|
||||
}
|
||||
@ -120,7 +120,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
|
||||
$ordered = $m->invoke(null, $classes);
|
||||
|
||||
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
|
||||
}
|
||||
@ -162,7 +162,7 @@ class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$m = $r->getMethod('getOrderedClasses');
|
||||
$m->setAccessible(true);
|
||||
|
||||
$ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
|
||||
$ordered = $m->invoke(null, $classes);
|
||||
|
||||
$this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
|
||||
}
|
||||
|
@ -263,7 +263,10 @@ class FlattenException extends LegacyFlattenException
|
||||
if (++$count > 1e4) {
|
||||
return array('array', '*SKIPPED over 10000 entries*');
|
||||
}
|
||||
if (is_object($value)) {
|
||||
if ($value instanceof \__PHP_Incomplete_Class) {
|
||||
// is_object() returns false on PHP<=7.1
|
||||
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
|
||||
} elseif (is_object($value)) {
|
||||
$result[$key] = array('object', get_class($value));
|
||||
} elseif (is_array($value)) {
|
||||
if ($level > 10) {
|
||||
@ -277,9 +280,6 @@ class FlattenException extends LegacyFlattenException
|
||||
$result[$key] = array('boolean', $value);
|
||||
} elseif (is_resource($value)) {
|
||||
$result[$key] = array('resource', get_resource_type($value));
|
||||
} elseif ($value instanceof \__PHP_Incomplete_Class) {
|
||||
// Special case of object, is_object will return false
|
||||
$result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
|
||||
} else {
|
||||
$result[$key] = array('string', (string) $value);
|
||||
}
|
||||
|
@ -230,7 +230,6 @@ class Container implements IntrospectableContainerInterface, ResettableContainer
|
||||
if ('service_container' === $id
|
||||
|| isset($this->aliases[$id])
|
||||
|| isset($this->services[$id])
|
||||
|| array_key_exists($id, $this->services)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
@ -273,7 +272,7 @@ class Container implements IntrospectableContainerInterface, ResettableContainer
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
// Re-use shared service instance if it exists.
|
||||
if (isset($this->services[$id]) || array_key_exists($id, $this->services)) {
|
||||
if (isset($this->services[$id])) {
|
||||
return $this->services[$id];
|
||||
}
|
||||
|
||||
@ -295,10 +294,10 @@ class Container implements IntrospectableContainerInterface, ResettableContainer
|
||||
}
|
||||
|
||||
$alternatives = array();
|
||||
foreach ($this->services as $key => $associatedService) {
|
||||
$lev = levenshtein($id, $key);
|
||||
if ($lev <= strlen($id) / 3 || false !== strpos($key, $id)) {
|
||||
$alternatives[] = $key;
|
||||
foreach ($this->getServiceIds() as $knownId) {
|
||||
$lev = levenshtein($id, $knownId);
|
||||
if ($lev <= strlen($id) / 3 || false !== strpos($knownId, $id)) {
|
||||
$alternatives[] = $knownId;
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,7 +354,7 @@ class Container implements IntrospectableContainerInterface, ResettableContainer
|
||||
$id = $this->aliases[$id];
|
||||
}
|
||||
|
||||
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
||||
return isset($this->services[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -455,7 +455,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
return $service;
|
||||
}
|
||||
|
||||
if (!array_key_exists($id, $this->definitions) && isset($this->aliasDefinitions[$id])) {
|
||||
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
|
||||
return $this->get($this->aliasDefinitions[$id]);
|
||||
}
|
||||
|
||||
@ -803,7 +803,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
*/
|
||||
public function hasDefinition($id)
|
||||
{
|
||||
return array_key_exists(strtolower($id), $this->definitions);
|
||||
return isset($this->definitions[strtolower($id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -819,7 +819,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
||||
{
|
||||
$id = strtolower($id);
|
||||
|
||||
if (!array_key_exists($id, $this->definitions)) {
|
||||
if (!isset($this->definitions[$id])) {
|
||||
throw new ServiceNotFoundException($id);
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,7 @@ class PhpDumper extends Dumper
|
||||
if ($this->container->isFrozen()) {
|
||||
$code .= $this->addFrozenConstructor();
|
||||
$code .= $this->addFrozenCompile();
|
||||
$code .= $this->addIsFrozenMethod();
|
||||
} else {
|
||||
$code .= $this->addConstructor();
|
||||
}
|
||||
@ -977,6 +978,26 @@ EOF;
|
||||
throw new LogicException('You cannot compile a dumped frozen container.');
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the isFrozen method for a frozen container.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function addIsFrozenMethod()
|
||||
{
|
||||
return <<<EOF
|
||||
|
||||
/*{$this->docStar}
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFrozen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$sc = new ProjectServiceContainer();
|
||||
$sc->set('foo', $foo = new \stdClass());
|
||||
$sc->set('bar', $foo = new \stdClass());
|
||||
$sc->set('baz', $foo = new \stdClass());
|
||||
|
||||
try {
|
||||
|
@ -46,6 +46,14 @@ class ProjectServiceContainer extends Container
|
||||
throw new LogicException('You cannot compile a dumped frozen container.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFrozen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'test' service.
|
||||
*
|
||||
|
@ -50,6 +50,14 @@ class ProjectServiceContainer extends Container
|
||||
throw new LogicException('You cannot compile a dumped frozen container.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFrozen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'test' service.
|
||||
*
|
||||
|
@ -44,6 +44,14 @@ class ProjectServiceContainer extends Container
|
||||
throw new LogicException('You cannot compile a dumped frozen container.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFrozen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'bar' service.
|
||||
*
|
||||
|
@ -63,6 +63,14 @@ class ProjectServiceContainer extends Container
|
||||
throw new LogicException('You cannot compile a dumped frozen container.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isFrozen()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'bar' service.
|
||||
*
|
||||
|
@ -27,6 +27,10 @@ class ValueExporter
|
||||
*/
|
||||
public function exportValue($value, $depth = 1, $deep = false)
|
||||
{
|
||||
if ($value instanceof \__PHP_Incomplete_Class) {
|
||||
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
|
||||
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
|
||||
@ -35,10 +39,6 @@ class ValueExporter
|
||||
return sprintf('Object(%s)', get_class($value));
|
||||
}
|
||||
|
||||
if ($value instanceof \__PHP_Incomplete_Class) {
|
||||
return sprintf('__PHP_Incomplete_Class(%s)', $this->getClassNameFromIncomplete($value));
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
if (empty($value)) {
|
||||
return '[]';
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\EventListener;
|
||||
|
||||
use Symfony\Component\Console\ConsoleEvents;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
||||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
@ -50,6 +50,6 @@ class DumpListener implements EventSubscriberInterface
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
// Register early to have a working dump() as early as possible
|
||||
return array(KernelEvents::REQUEST => array('configure', 1024));
|
||||
return array(ConsoleEvents::COMMAND => array('configure', 1024));
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\EventListener;
|
||||
|
||||
use Symfony\Component\Console\ConsoleEvents;
|
||||
use Symfony\Component\HttpKernel\EventListener\DumpListener;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
|
||||
use Symfony\Component\VarDumper\Cloner\Data;
|
||||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;
|
||||
@ -28,7 +28,7 @@ class DumpListenerTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSubscribedEvents()
|
||||
{
|
||||
$this->assertSame(
|
||||
array(KernelEvents::REQUEST => array('configure', 1024)),
|
||||
array(ConsoleEvents::COMMAND => array('configure', 1024)),
|
||||
DumpListener::getSubscribedEvents()
|
||||
);
|
||||
}
|
||||
|
@ -39,9 +39,12 @@ class CutStub extends Stub
|
||||
|
||||
case 'resource':
|
||||
case 'unknown type':
|
||||
case 'resource (closed)':
|
||||
$this->type = self::TYPE_RESOURCE;
|
||||
$this->handle = (int) $value;
|
||||
$this->class = @get_resource_type($value);
|
||||
if ('Unknown' === $this->class = @get_resource_type($value)) {
|
||||
$this->class = 'Closed';
|
||||
}
|
||||
$this->cut = -1;
|
||||
break;
|
||||
|
||||
|
@ -183,10 +183,13 @@ class VarCloner extends AbstractCloner
|
||||
|
||||
case 'resource':
|
||||
case 'unknown type':
|
||||
case 'resource (closed)':
|
||||
if (empty($resRefs[$h = (int) $v])) {
|
||||
$stub = new Stub();
|
||||
$stub->type = Stub::TYPE_RESOURCE;
|
||||
$stub->class = $zval['resource_type'] ?: get_resource_type($v);
|
||||
if ('Unknown' === $stub->class = $zval['resource_type'] ?: @get_resource_type($v)) {
|
||||
$stub->class = 'Closed';
|
||||
}
|
||||
$stub->value = $v;
|
||||
$stub->handle = $h;
|
||||
$a = $this->castResource($stub, 0 < $i);
|
||||
|
@ -193,7 +193,7 @@ EOTXT
|
||||
|
||||
$this->assertStringMatchesFormat(
|
||||
<<<EOTXT
|
||||
Unknown resource @{$res}
|
||||
Closed resource @{$res}
|
||||
|
||||
EOTXT
|
||||
,
|
||||
|
Reference in New Issue
Block a user