ALPHA 3.0.2

This commit is contained in:
TheGamecraft
2018-09-05 11:35:41 -04:00
parent 4dbdc8fd19
commit 8ef8057bfa
771 changed files with 9284 additions and 5857 deletions

View File

@@ -29,30 +29,12 @@ class SplCaster
public static function castArrayObject(\ArrayObject $c, array $a, Stub $stub, $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
$class = $stub->class;
$flags = $c->getFlags();
return self::castSplArray($c, $a, $stub, $isNested);
}
$b = array(
$prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
$prefix.'iteratorClass' => new ClassStub($c->getIteratorClass()),
$prefix.'storage' => $c->getArrayCopy(),
);
if ('ArrayObject' === $class) {
$a = $b;
} else {
if (!($flags & \ArrayObject::STD_PROP_LIST)) {
$c->setFlags(\ArrayObject::STD_PROP_LIST);
$a = Caster::castObject($c, $class);
$c->setFlags($flags);
}
$a += $b;
}
return $a;
public static function castArrayIterator(\ArrayIterator $c, array $a, Stub $stub, $isNested)
{
return self::castSplArray($c, $a, $stub, $isNested);
}
public static function castHeap(\Iterator $c, array $a, Stub $stub, $isNested)
@@ -186,7 +168,7 @@ class SplCaster
$clone = clone $c;
foreach ($clone as $obj) {
$storage[spl_object_hash($obj)] = array(
$storage[] = array(
'object' => $obj,
'info' => $clone->getInfo(),
);
@@ -205,4 +187,27 @@ class SplCaster
return $a;
}
private static function castSplArray($c, array $a, Stub $stub, $isNested)
{
$prefix = Caster::PREFIX_VIRTUAL;
$class = $stub->class;
$flags = $c->getFlags();
if (!($flags & \ArrayObject::STD_PROP_LIST)) {
$c->setFlags(\ArrayObject::STD_PROP_LIST);
$a = Caster::castObject($c, $class);
$c->setFlags($flags);
}
$a += array(
$prefix.'flag::STD_PROP_LIST' => (bool) ($flags & \ArrayObject::STD_PROP_LIST),
$prefix.'flag::ARRAY_AS_PROPS' => (bool) ($flags & \ArrayObject::ARRAY_AS_PROPS),
);
if ($c instanceof \ArrayObject) {
$a[$prefix.'iteratorClass'] = new ClassStub($c->getIteratorClass());
}
$a[$prefix.'storage'] = $c->getArrayCopy();
return $a;
}
}

View File

@@ -95,6 +95,7 @@ abstract class AbstractCloner implements ClonerInterface
'AMQPEnvelope' => array('Symfony\Component\VarDumper\Caster\AmqpCaster', 'castEnvelope'),
'ArrayObject' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayObject'),
'ArrayIterator' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castArrayIterator'),
'SplDoublyLinkedList' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castDoublyLinkedList'),
'SplFileInfo' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFileInfo'),
'SplFileObject' => array('Symfony\Component\VarDumper\Caster\SplCaster', 'castFileObject'),

View File

@@ -164,7 +164,7 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface
*/
protected function dumpLine($depth)
{
call_user_func($this->lineDumper, $this->line, $depth, $this->indentPad);
\call_user_func($this->lineDumper, $this->line, $depth, $this->indentPad);
$this->line = '';
}

View File

@@ -13,6 +13,7 @@ namespace Symfony\Component\VarDumper\Dumper;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;
use Symfony\Component\VarDumper\Server\Connection;
/**
* ServerDumper forwards serialized Data clones to a server.
@@ -21,10 +22,8 @@ use Symfony\Component\VarDumper\Dumper\ContextProvider\ContextProviderInterface;
*/
class ServerDumper implements DataDumperInterface
{
private $host;
private $connection;
private $wrappedDumper;
private $contextProviders;
private $socket;
/**
* @param string $host The server host
@@ -33,83 +32,22 @@ class ServerDumper implements DataDumperInterface
*/
public function __construct(string $host, DataDumperInterface $wrappedDumper = null, array $contextProviders = array())
{
if (false === strpos($host, '://')) {
$host = 'tcp://'.$host;
}
$this->host = $host;
$this->connection = new Connection($host, $contextProviders);
$this->wrappedDumper = $wrappedDumper;
$this->contextProviders = $contextProviders;
}
public function getContextProviders(): array
{
return $this->contextProviders;
return $this->connection->getContextProviders();
}
/**
* {@inheritdoc}
*/
public function dump(Data $data, $output = null): void
public function dump(Data $data)
{
set_error_handler(array(self::class, 'nullErrorHandler'));
$failed = false;
try {
if (!$this->socket = $this->socket ?: $this->createSocket()) {
$failed = true;
return;
}
} finally {
restore_error_handler();
if ($failed && $this->wrappedDumper) {
$this->wrappedDumper->dump($data);
}
if (!$this->connection->write($data) && $this->wrappedDumper) {
$this->wrappedDumper->dump($data);
}
set_error_handler(array(self::class, 'nullErrorHandler'));
$context = array('timestamp' => time());
foreach ($this->contextProviders as $name => $provider) {
$context[$name] = $provider->getContext();
}
$context = array_filter($context);
$encodedPayload = base64_encode(serialize(array($data, $context)))."\n";
$failed = false;
try {
$retry = 3;
while ($retry > 0 && $failed = (-1 === stream_socket_sendto($this->socket, $encodedPayload))) {
stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
if ($failed = !$this->socket = $this->createSocket()) {
break;
}
--$retry;
}
} finally {
restore_error_handler();
if ($failed && $this->wrappedDumper) {
$this->wrappedDumper->dump($data);
}
}
}
private static function nullErrorHandler()
{
// noop
}
private function createSocket()
{
$socket = stream_socket_client($this->host, $errno, $errstr, 1, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT);
if ($socket) {
stream_set_blocking($socket, false);
}
return $socket;
}
}

0
vendor/symfony/var-dumper/Resources/bin/var-dump-server vendored Normal file → Executable file
View File

View File

@@ -22,14 +22,6 @@ a {
a:hover {
text-decoration: underline;
}
code {
color: #cc2255;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
margin-right: 5px;
padding: 0 3px;
}
.text-small {
font-size: 12px !important;
}
@@ -60,6 +52,12 @@ article > header > .row > h2 {
article > header > .row > h2 > code {
white-space: nowrap;
user-select: none;
color: #cc2255;
background-color: #f7f7f9;
border: 1px solid #e1e1e8;
border-radius: 3px;
margin-right: 5px;
padding: 0 3px;
}
article > header > .row > time.col {
flex: 0;

View File

@@ -163,4 +163,45 @@ EOTXT;
$this->assertDumpMatchesFormat('%ADateTime%A', $var);
}
public function testCastArrayObject()
{
$var = new \ArrayObject(array(123));
$var->foo = 234;
$expected = <<<EOTXT
ArrayObject {
+"foo": 234
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
iteratorClass: "ArrayIterator"
storage: array:1 [
0 => 123
]
}
EOTXT;
$this->assertDumpEquals($expected, $var);
}
public function testArrayIterator()
{
$var = new MyArrayIterator(array(234));
$expected = <<<EOTXT
Symfony\Component\VarDumper\Tests\Caster\MyArrayIterator {
-foo: 123
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
storage: array:1 [
0 => 234
]
}
EOTXT;
$this->assertDumpEquals($expected, $var);
}
}
class MyArrayIterator extends \ArrayIterator
{
private $foo = 123;
}

View File

@@ -55,26 +55,24 @@ class ServerDumperTest extends TestCase
$dumped = null;
$process = $this->getServerProcess();
$process->start(function ($type, $buffer) use ($process, &$dumped) {
$process->start(function ($type, $buffer) use ($process, &$dumped, $dumper, $data) {
if (Process::ERR === $type) {
$process->stop();
$this->fail();
} elseif ("READY\n" === $buffer) {
$dumper->dump($data);
} else {
$dumped .= $buffer;
}
});
sleep(3);
$dumper->dump($data);
$process->wait();
$this->assertTrue($process->isSuccessful());
$this->assertStringMatchesFormat(<<<'DUMP'
(3) "foo"
[
"timestamp" => %d
"timestamp" => %d.%d
"foo_provider" => [
(3) "foo"
]

View File

@@ -29,6 +29,8 @@ $server = new DumpServer(getenv('VAR_DUMPER_SERVER'));
$server->start();
echo "READY\n";
$server->listen(function (Data $data, array $context, $clientId) {
dump((string) $data, $context, $clientId);