Skip to content

SwooleRequestSnapshot

A Swoole HTTP request reduced to plain arrays.

ext-swoole is a suggest rather than a require, so the conversion logic has to be checkable and testable on a machine without the extension. Only SwooleRequestSnapshotFactory names \Swoole\Http\Request; everything downstream works off this.

final readonly class SwooleRequestSnapshot

SourceSwooleRequestSnapshot.php
PropertyTypeDescription
$cookiearrayreadonly.
$filesarrayreadonly.
$getarrayreadonly.
$headerarrayreadonly.
$postarrayreadonly.
$rawContentstringreadonly.
$serverarrayreadonly.

public function __construct(array<string, mixed> $server = [], array<string, string> $header = [], array<string, mixed> $get = [], array<string, mixed> $post = [], array<string, string> $cookie = [], array<string, mixed> $files = [], string $rawContent = ''): mixed

$_FILES-shaped.

ParameterTypeDescription
$serverarray``<``string``, ``mixed``>Swoole’s own $request->server — note the keys are LOWERCASE.
$headerarray``<``string``, ``string``>Lowercase header names.
$getarray``<``string``, ``mixed``>
$postarray``<``string``, ``mixed``>
$cookiearray``<``string``, ``string``>
$filesarray``<``string``, ``mixed``>$_FILES-shaped.
$rawContentstring

Returns mixed

MethodDescription
serverValue(string $key): ?stringReturns a server entry as a string, or null when it is absent or unusable.

public function serverValue(string $key): ?string

Returns a server entry as a string, or null when it is absent or unusable.

The key is Swoole’s own lowercase name (request_method, not REQUEST_METHOD). A non-scalar value answers null rather than being coerced, so a caller’s ?? default applies.

ParameterTypeDescription
$keystring

Returns ?``string