update
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Transport\Serialization\Normalizer;
|
||||
|
||||
use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
||||
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
|
||||
/**
|
||||
* This normalizer is only used in Debug/Dev/Messenger contexts.
|
||||
*
|
||||
* @author Pascal Luna <skalpa@zetareticuli.org>
|
||||
*/
|
||||
final class FlattenExceptionNormalizer implements DenormalizerInterface, NormalizerInterface
|
||||
{
|
||||
use NormalizerAwareTrait;
|
||||
|
||||
public function normalize(mixed $object, ?string $format = null, array $context = []): array
|
||||
{
|
||||
$normalized = [
|
||||
'message' => $object->getMessage(),
|
||||
'code' => $object->getCode(),
|
||||
'headers' => $object->getHeaders(),
|
||||
'class' => $object->getClass(),
|
||||
'file' => $object->getFile(),
|
||||
'line' => $object->getLine(),
|
||||
'previous' => null === $object->getPrevious() ? null : $this->normalize($object->getPrevious(), $format, $context),
|
||||
'status' => $object->getStatusCode(),
|
||||
'status_text' => $object->getStatusText(),
|
||||
'trace' => $object->getTrace(),
|
||||
'trace_as_string' => $object->getTraceAsString(),
|
||||
];
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
public function getSupportedTypes(?string $format): array
|
||||
{
|
||||
return [
|
||||
FlattenException::class => false,
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
|
||||
{
|
||||
return $data instanceof FlattenException && ($context[Serializer::MESSENGER_SERIALIZATION_CONTEXT] ?? false);
|
||||
}
|
||||
|
||||
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): FlattenException
|
||||
{
|
||||
$object = new FlattenException();
|
||||
|
||||
$object->setMessage($data['message']);
|
||||
$object->setCode($data['code']);
|
||||
$object->setStatusCode($data['status'] ?? 500);
|
||||
$object->setClass($data['class']);
|
||||
$object->setFile($data['file']);
|
||||
$object->setLine($data['line']);
|
||||
$object->setStatusText($data['status_text']);
|
||||
$object->setHeaders((array) $data['headers']);
|
||||
|
||||
if (isset($data['previous'])) {
|
||||
$object->setPrevious($this->denormalize($data['previous'], $type, $format, $context));
|
||||
}
|
||||
|
||||
$property = new \ReflectionProperty(FlattenException::class, 'trace');
|
||||
$property->setValue($object, (array) $data['trace']);
|
||||
|
||||
$property = new \ReflectionProperty(FlattenException::class, 'traceAsString');
|
||||
$property->setValue($object, $data['trace_as_string']);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
|
||||
{
|
||||
return FlattenException::class === $type && ($context[Serializer::MESSENGER_SERIALIZATION_CONTEXT] ?? false);
|
||||
}
|
||||
}
|
||||
123
projects/priceservice/vendor/symfony/messenger/Transport/Serialization/PhpSerializer.php
vendored
Normal file
123
projects/priceservice/vendor/symfony/messenger/Transport/Serialization/PhpSerializer.php
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Transport\Serialization;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
|
||||
use Symfony\Component\Messenger\Stamp\MessageDecodingFailedStamp;
|
||||
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
|
||||
|
||||
/**
|
||||
* @author Ryan Weaver<ryan@symfonycasts.com>
|
||||
*/
|
||||
class PhpSerializer implements SerializerInterface
|
||||
{
|
||||
private bool $acceptPhpIncompleteClass = false;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function acceptPhpIncompleteClass(): void
|
||||
{
|
||||
$this->acceptPhpIncompleteClass = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function rejectPhpIncompleteClass(): void
|
||||
{
|
||||
$this->acceptPhpIncompleteClass = false;
|
||||
}
|
||||
|
||||
public function decode(array $encodedEnvelope): Envelope
|
||||
{
|
||||
if (empty($encodedEnvelope['body'])) {
|
||||
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body", or maybe you should implement your own serializer.');
|
||||
}
|
||||
|
||||
if (!str_ends_with($encodedEnvelope['body'], '}')) {
|
||||
$encodedEnvelope['body'] = base64_decode($encodedEnvelope['body']);
|
||||
}
|
||||
|
||||
$serializeEnvelope = stripslashes($encodedEnvelope['body']);
|
||||
|
||||
return $this->safelyUnserialize($serializeEnvelope);
|
||||
}
|
||||
|
||||
public function encode(Envelope $envelope): array
|
||||
{
|
||||
$envelope = $envelope->withoutStampsOfType(NonSendableStampInterface::class);
|
||||
|
||||
$body = addslashes(serialize($envelope));
|
||||
|
||||
if (!preg_match('//u', $body)) {
|
||||
$body = base64_encode($body);
|
||||
}
|
||||
|
||||
return [
|
||||
'body' => $body,
|
||||
];
|
||||
}
|
||||
|
||||
private function safelyUnserialize(string $contents): Envelope
|
||||
{
|
||||
if ('' === $contents) {
|
||||
throw new MessageDecodingFailedException('Could not decode an empty message using PHP serialization.');
|
||||
}
|
||||
|
||||
if ($this->acceptPhpIncompleteClass) {
|
||||
$prevUnserializeHandler = ini_set('unserialize_callback_func', null);
|
||||
} else {
|
||||
$prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback');
|
||||
}
|
||||
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler) {
|
||||
if (__FILE__ === $file && !\in_array($type, [\E_DEPRECATED, \E_USER_DEPRECATED], true)) {
|
||||
throw new \ErrorException($msg, 0, $type, $file, $line);
|
||||
}
|
||||
|
||||
return $prevErrorHandler ? $prevErrorHandler($type, $msg, $file, $line, $context) : false;
|
||||
});
|
||||
|
||||
try {
|
||||
/** @var Envelope */
|
||||
$envelope = unserialize($contents);
|
||||
} catch (\Throwable $e) {
|
||||
if ($e instanceof MessageDecodingFailedException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw new MessageDecodingFailedException('Could not decode Envelope: '.$e->getMessage(), 0, $e);
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
ini_set('unserialize_callback_func', $prevUnserializeHandler);
|
||||
}
|
||||
|
||||
if (!$envelope instanceof Envelope) {
|
||||
throw new MessageDecodingFailedException('Could not decode message into an Envelope.');
|
||||
}
|
||||
|
||||
if ($envelope->getMessage() instanceof \__PHP_Incomplete_Class) {
|
||||
$envelope = $envelope->with(new MessageDecodingFailedStamp());
|
||||
}
|
||||
|
||||
return $envelope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function handleUnserializeCallback(string $class): never
|
||||
{
|
||||
throw new MessageDecodingFailedException(sprintf('Message class "%s" not found during decoding.', $class));
|
||||
}
|
||||
}
|
||||
181
projects/priceservice/vendor/symfony/messenger/Transport/Serialization/Serializer.php
vendored
Normal file
181
projects/priceservice/vendor/symfony/messenger/Transport/Serialization/Serializer.php
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Transport\Serialization;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\LogicException;
|
||||
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
|
||||
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
|
||||
use Symfony\Component\Messenger\Stamp\SerializedMessageStamp;
|
||||
use Symfony\Component\Messenger\Stamp\SerializerStamp;
|
||||
use Symfony\Component\Messenger\Stamp\StampInterface;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Symfony\Component\Serializer\Encoder\XmlEncoder;
|
||||
use Symfony\Component\Serializer\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
||||
use Symfony\Component\Serializer\Serializer as SymfonySerializer;
|
||||
use Symfony\Component\Serializer\SerializerInterface as SymfonySerializerInterface;
|
||||
|
||||
/**
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*/
|
||||
class Serializer implements SerializerInterface
|
||||
{
|
||||
public const MESSENGER_SERIALIZATION_CONTEXT = 'messenger_serialization';
|
||||
private const STAMP_HEADER_PREFIX = 'X-Message-Stamp-';
|
||||
|
||||
private SymfonySerializerInterface $serializer;
|
||||
private string $format;
|
||||
private array $context;
|
||||
|
||||
public function __construct(?SymfonySerializerInterface $serializer = null, string $format = 'json', array $context = [])
|
||||
{
|
||||
$this->serializer = $serializer ?? self::create()->serializer;
|
||||
$this->format = $format;
|
||||
$this->context = $context + [self::MESSENGER_SERIALIZATION_CONTEXT => true];
|
||||
}
|
||||
|
||||
public static function create(): self
|
||||
{
|
||||
if (!class_exists(SymfonySerializer::class)) {
|
||||
throw new LogicException(sprintf('The "%s" class requires Symfony\'s Serializer component. Try running "composer require symfony/serializer" or use "%s" instead.', __CLASS__, PhpSerializer::class));
|
||||
}
|
||||
|
||||
$encoders = [new XmlEncoder(), new JsonEncoder()];
|
||||
$normalizers = [new DateTimeNormalizer(), new ArrayDenormalizer(), new ObjectNormalizer()];
|
||||
$serializer = new SymfonySerializer($normalizers, $encoders);
|
||||
|
||||
return new self($serializer);
|
||||
}
|
||||
|
||||
public function decode(array $encodedEnvelope): Envelope
|
||||
{
|
||||
if (empty($encodedEnvelope['body']) || empty($encodedEnvelope['headers'])) {
|
||||
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body" and some "headers", or maybe you should implement your own serializer.');
|
||||
}
|
||||
|
||||
if (empty($encodedEnvelope['headers']['type'])) {
|
||||
throw new MessageDecodingFailedException('Encoded envelope does not have a "type" header.');
|
||||
}
|
||||
|
||||
$stamps = $this->decodeStamps($encodedEnvelope);
|
||||
$stamps[] = new SerializedMessageStamp($encodedEnvelope['body']);
|
||||
|
||||
$serializerStamp = $this->findFirstSerializerStamp($stamps);
|
||||
|
||||
$context = $this->context;
|
||||
if (null !== $serializerStamp) {
|
||||
$context = $serializerStamp->getContext() + $context;
|
||||
}
|
||||
|
||||
try {
|
||||
$message = $this->serializer->deserialize($encodedEnvelope['body'], $encodedEnvelope['headers']['type'], $this->format, $context);
|
||||
} catch (ExceptionInterface $e) {
|
||||
throw new MessageDecodingFailedException('Could not decode message: '.$e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
return new Envelope($message, $stamps);
|
||||
}
|
||||
|
||||
public function encode(Envelope $envelope): array
|
||||
{
|
||||
$context = $this->context;
|
||||
/** @var SerializerStamp|null $serializerStamp */
|
||||
if ($serializerStamp = $envelope->last(SerializerStamp::class)) {
|
||||
$context = $serializerStamp->getContext() + $context;
|
||||
}
|
||||
|
||||
/** @var SerializedMessageStamp|null $serializedMessageStamp */
|
||||
$serializedMessageStamp = $envelope->last(SerializedMessageStamp::class);
|
||||
|
||||
$envelope = $envelope->withoutStampsOfType(NonSendableStampInterface::class);
|
||||
|
||||
$headers = ['type' => $envelope->getMessage()::class] + $this->encodeStamps($envelope) + $this->getContentTypeHeader();
|
||||
|
||||
return [
|
||||
'body' => $serializedMessageStamp
|
||||
? $serializedMessageStamp->getSerializedMessage()
|
||||
: $this->serializer->serialize($envelope->getMessage(), $this->format, $context),
|
||||
'headers' => $headers,
|
||||
];
|
||||
}
|
||||
|
||||
private function decodeStamps(array $encodedEnvelope): array
|
||||
{
|
||||
$stamps = [];
|
||||
foreach ($encodedEnvelope['headers'] as $name => $value) {
|
||||
if (!str_starts_with($name, self::STAMP_HEADER_PREFIX)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$stamps[] = $this->serializer->deserialize($value, substr($name, \strlen(self::STAMP_HEADER_PREFIX)).'[]', $this->format, $this->context);
|
||||
} catch (ExceptionInterface $e) {
|
||||
throw new MessageDecodingFailedException('Could not decode stamp: '.$e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
if ($stamps) {
|
||||
$stamps = array_merge(...$stamps);
|
||||
}
|
||||
|
||||
return $stamps;
|
||||
}
|
||||
|
||||
private function encodeStamps(Envelope $envelope): array
|
||||
{
|
||||
if (!$allStamps = $envelope->all()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$headers = [];
|
||||
foreach ($allStamps as $class => $stamps) {
|
||||
$headers[self::STAMP_HEADER_PREFIX.$class] = $this->serializer->serialize($stamps, $this->format, $this->context);
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StampInterface[] $stamps
|
||||
*/
|
||||
private function findFirstSerializerStamp(array $stamps): ?SerializerStamp
|
||||
{
|
||||
foreach ($stamps as $stamp) {
|
||||
if ($stamp instanceof SerializerStamp) {
|
||||
return $stamp;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getContentTypeHeader(): array
|
||||
{
|
||||
$mimeType = $this->getMimeTypeForFormat();
|
||||
|
||||
return null === $mimeType ? [] : ['Content-Type' => $mimeType];
|
||||
}
|
||||
|
||||
private function getMimeTypeForFormat(): ?string
|
||||
{
|
||||
return match ($this->format) {
|
||||
'json' => 'application/json',
|
||||
'xml' => 'application/xml',
|
||||
'yml',
|
||||
'yaml' => 'application/x-yaml',
|
||||
'csv' => 'text/csv',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
48
projects/priceservice/vendor/symfony/messenger/Transport/Serialization/SerializerInterface.php
vendored
Normal file
48
projects/priceservice/vendor/symfony/messenger/Transport/Serialization/SerializerInterface.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Transport\Serialization;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
|
||||
|
||||
/**
|
||||
* @author Samuel Roze <samuel.roze@gmail.com>
|
||||
*/
|
||||
interface SerializerInterface
|
||||
{
|
||||
/**
|
||||
* Decodes an envelope and its message from an encoded-form.
|
||||
*
|
||||
* The `$encodedEnvelope` parameter is a key-value array that
|
||||
* describes the envelope and its content, that will be used by the different transports.
|
||||
*
|
||||
* The most common keys are:
|
||||
* - `body` (string) - the message body
|
||||
* - `headers` (string<string>) - a key/value pair of headers
|
||||
*
|
||||
* @throws MessageDecodingFailedException
|
||||
*/
|
||||
public function decode(array $encodedEnvelope): Envelope;
|
||||
|
||||
/**
|
||||
* Encodes an envelope content (message & stamps) to a common format understandable by transports.
|
||||
* The encoded array should only contain scalars and arrays.
|
||||
*
|
||||
* Stamps that implement NonSendableStampInterface should
|
||||
* not be encoded.
|
||||
*
|
||||
* The most common keys of the encoded array are:
|
||||
* - `body` (string) - the message body
|
||||
* - `headers` (string<string>) - a key/value pair of headers
|
||||
*/
|
||||
public function encode(Envelope $envelope): array;
|
||||
}
|
||||
Reference in New Issue
Block a user