class Connection
Same name in this branch
- 11.1.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection
- 11.1.x core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection
- 11.1.x core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection
- 11.1.x core/modules/mysql/src/Driver/Database/mysql/Connection.php \Drupal\mysql\Driver\Database\mysql\Connection
Forwards serialized Data clones to a server.
@author Maxime Steinhausser <maxime.steinhausser@gmail.com>
Hierarchy
- class \Symfony\Component\VarDumper\Server\Connection
Expanded class hierarchy of Connection
3 files declare their use of Connection
- DumpDataCollector.php in vendor/
symfony/ http-kernel/ DataCollector/ DumpDataCollector.php - DumpListener.php in vendor/
symfony/ http-kernel/ EventListener/ DumpListener.php - ServerDumper.php in vendor/
symfony/ var-dumper/ Dumper/ ServerDumper.php
5 string references to 'Connection'
- FileTransfer::__get in core/
lib/ Drupal/ Core/ FileTransfer/ FileTransfer.php - Implements the magic __get() method.
- FileTransfer::__isset in core/
lib/ Drupal/ Core/ FileTransfer/ FileTransfer.php - FileTransfer::__set in core/
lib/ Drupal/ Core/ FileTransfer/ FileTransfer.php - FileTransfer::__unset in core/
lib/ Drupal/ Core/ FileTransfer/ FileTransfer.php - StreamHandler::createStream in vendor/
guzzlehttp/ guzzle/ src/ Handler/ StreamHandler.php
File
-
vendor/
symfony/ var-dumper/ Server/ Connection.php, line 22
Namespace
Symfony\Component\VarDumper\ServerView source
class Connection {
private string $host;
/**
* @var resource|null
*/
private $socket;
/**
* @param string $host The server host
* @param ContextProviderInterface[] $contextProviders Context providers indexed by context name
*/
public function __construct(string $host, array $contextProviders = []) {
if (!str_contains($host, '://')) {
$host = 'tcp://' . $host;
}
$this->host = $host;
}
public function getContextProviders() : array {
return $this->contextProviders;
}
public function write(Data $data) : bool {
$socketIsFresh = !$this->socket;
if (!($this->socket = $this->socket ?: $this->createSocket())) {
return false;
}
$context = [
'timestamp' => microtime(true),
];
foreach ($this->contextProviders as $name => $provider) {
$context[$name] = $provider->getContext();
}
$context = array_filter($context);
$encodedPayload = base64_encode(serialize([
$data,
$context,
])) . "\n";
set_error_handler(static fn() => null);
try {
if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
return true;
}
if (!$socketIsFresh) {
stream_socket_shutdown($this->socket, \STREAM_SHUT_RDWR);
fclose($this->socket);
$this->socket = $this->createSocket();
}
if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
return true;
}
} finally {
restore_error_handler();
}
return false;
}
/**
* @return resource|null
*/
private function createSocket() {
set_error_handler(static fn() => null);
try {
return stream_socket_client($this->host, $errno, $errstr, 3) ?: null;
} finally {
restore_error_handler();
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Connection::$host | private | property | |
Connection::$socket | private | property | |
Connection::createSocket | private | function | |
Connection::getContextProviders | public | function | |
Connection::write | public | function | |
Connection::__construct | public | function |