Final Class Yiisoft\VarDumper\Handler\StreamHandler
| Inheritance | Yiisoft\VarDumper\Handler\StreamHandler |
|---|---|
| Implements | Yiisoft\VarDumper\HandlerInterface |
Uses stream ({@link https://www.php.net/manual/en/intro.stream.php}) for writing variable's data. Requires "sockets" PHP extension when {@see StreamHandler::$uri} is a {@see Socket} instance.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\VarDumper\Handler\StreamHandler | |
| __destruct() | Yiisoft\VarDumper\Handler\StreamHandler | |
| handle() | Encodes {@param $variable} with {@see self::$encoder} and sends the result to the stream. | Yiisoft\VarDumper\Handler\StreamHandler |
| withEncoder() | Yiisoft\VarDumper\Handler\StreamHandler |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| SOCKET_PROTOCOLS | [ 'udp', 'udg', 'tcp', 'unix', ] | Yiisoft\VarDumper\Handler\StreamHandler |
Method Details
| public mixed __construct ( mixed|resource|string $uri = 'udp://127.0.0.1:8890' ) | ||
| $uri | mixed|resource|string | |
public function __construct(
mixed $uri = 'udp://127.0.0.1:8890'
) {
if (!is_string($uri) && !is_resource($uri) && !$uri instanceof Socket) {
throw new InvalidArgumentException(
sprintf(
'Argument $uri must be either a string, a resource or a Socket instance, "%s" given.',
get_debug_type($uri)
)
);
}
$this->uri = $uri;
}
| public mixed __destruct ( ) |
public function __destruct()
{
if (!is_string($this->uri) || !is_resource($this->stream)) {
return;
}
fclose($this->stream);
}
Encodes {@param $variable} with {@see self::$encoder} and sends the result to the stream.
| public void handle ( mixed $variable, integer $depth, boolean $highlight = false ) | ||
| $variable | mixed | |
| $depth | integer | |
| $highlight | boolean | |
public function handle(mixed $variable, int $depth, bool $highlight = false): void
{
$data = ($this->encoder ?? '\json_encode')($variable);
if (!is_string($data)) {
throw new RuntimeException(
sprintf(
'Encoder must return a string, "%s" returned.',
get_debug_type($data)
)
);
}
if (!is_resource($this->stream) && !$this->stream instanceof Socket) {
$this->initializeStream();
}
if (!$this->writeToStream($data)) {
$this->initializeStream();
if (!$this->writeToStream($data)) {
throw new RuntimeException('Cannot write a stream.');
}
}
}
| public Yiisoft\VarDumper\Handler\StreamHandler withEncoder ( callable $encoder ) | ||
| $encoder | callable |
Encoder that will be used to encode variable before sending it to the stream. |
public function withEncoder(callable $encoder): static
{
$new = clone $this;
$new->encoder = $encoder;
return $new;
}
Signup or Login in order to comment.