mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-24 19:59:10 -04:00
ALPHA 3.0.2
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user