2014-04-05 19:54:33 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\VarDumper\Caster;
|
|
|
|
|
2014-09-08 19:39:52 +01:00
|
|
|
use Symfony\Component\VarDumper\Cloner\Stub;
|
|
|
|
|
2014-04-05 19:54:33 +01:00
|
|
|
/**
|
|
|
|
* Casts SPL related classes to array representation.
|
|
|
|
*
|
|
|
|
* @author Nicolas Grekas <p@tchwork.com>
|
|
|
|
*/
|
|
|
|
class SplCaster
|
|
|
|
{
|
2014-09-08 19:39:52 +01:00
|
|
|
public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested)
|
2014-04-05 19:54:33 +01:00
|
|
|
{
|
2015-03-26 16:36:02 +00:00
|
|
|
$prefix = Caster::PREFIX_VIRTUAL;
|
2014-09-08 19:39:52 +01:00
|
|
|
$class = $stub->class;
|
2014-04-05 19:54:33 +01:00
|
|
|
$flags = $c->getFlags();
|
|
|
|
|
|
|
|
$b = array(
|
2015-03-26 16:36:02 +00:00
|
|
|
$prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
|
|
|
|
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
|
|
|
|
$prefix.'iteratorClass' => $c->getIteratorClass(),
|
|
|
|
$prefix.'storage' => $c->getArrayCopy(),
|
2014-04-05 19:54:33 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($class === 'ArrayObject') {
|
|
|
|
$a = $b;
|
|
|
|
} else {
|
|
|
|
if (!($flags & \ArrayObject::STD_PROP_LIST)) {
|
|
|
|
$c->setFlags(\ArrayObject::STD_PROP_LIST);
|
2015-03-26 16:36:02 +00:00
|
|
|
$a = Caster::castObject($c, new \ReflectionClass($class));
|
2014-04-05 19:54:33 +01:00
|
|
|
$c->setFlags($flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
$a += $b;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
2014-09-08 19:39:52 +01:00
|
|
|
public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested)
|
2014-04-05 19:54:33 +01:00
|
|
|
{
|
|
|
|
$a += array(
|
2015-03-26 16:36:02 +00:00
|
|
|
Caster::PREFIX_VIRTUAL.'heap' => iterator_to_array(clone $c),
|
2014-04-05 19:54:33 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
2014-09-08 19:39:52 +01:00
|
|
|
public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested)
|
2014-04-05 19:54:33 +01:00
|
|
|
{
|
2015-03-26 16:36:02 +00:00
|
|
|
$prefix = Caster::PREFIX_VIRTUAL;
|
2014-04-05 19:54:33 +01:00
|
|
|
$mode = $c->getIteratorMode();
|
|
|
|
$c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
|
|
|
|
|
|
|
|
$a += array(
|
2015-03-26 16:36:02 +00:00
|
|
|
$prefix.'mode' => new ConstStub((($mode & \SplDoublyLinkedList::IT_MODE_LIFO) ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO').' | '.(($mode & \SplDoublyLinkedList::IT_MODE_KEEP) ? 'IT_MODE_KEEP' : 'IT_MODE_DELETE'), $mode),
|
|
|
|
$prefix.'dllist' => iterator_to_array($c),
|
2014-04-05 19:54:33 +01:00
|
|
|
);
|
|
|
|
$c->setIteratorMode($mode);
|
|
|
|
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
2014-09-08 19:39:52 +01:00
|
|
|
public static function castFixedArray(\SplFixedArray $c, array $a, Stub $stub, $isNested)
|
2014-04-05 19:54:33 +01:00
|
|
|
{
|
|
|
|
$a += array(
|
2015-03-26 16:36:02 +00:00
|
|
|
Caster::PREFIX_VIRTUAL.'storage' => $c->toArray(),
|
2014-04-05 19:54:33 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
|
2014-09-08 19:39:52 +01:00
|
|
|
public static function castObjectStorage(\SplObjectStorage $c, array $a, Stub $stub, $isNested)
|
2014-04-05 19:54:33 +01:00
|
|
|
{
|
|
|
|
$storage = array();
|
2015-03-26 16:36:02 +00:00
|
|
|
unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967
|
2014-04-05 19:54:33 +01:00
|
|
|
|
|
|
|
foreach ($c as $obj) {
|
|
|
|
$storage[spl_object_hash($obj)] = array(
|
|
|
|
'object' => $obj,
|
|
|
|
'info' => $c->getInfo(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$a += array(
|
2015-03-26 16:36:02 +00:00
|
|
|
Caster::PREFIX_VIRTUAL.'storage' => $storage,
|
2014-04-05 19:54:33 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return $a;
|
|
|
|
}
|
|
|
|
}
|