Initial Drupal 11 with DDEV setup
This commit is contained in:
26
vendor/symfony/serializer/NameConverter/AdvancedNameConverterInterface.php
vendored
Normal file
26
vendor/symfony/serializer/NameConverter/AdvancedNameConverterInterface.php
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
<?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\Serializer\NameConverter;
|
||||
|
||||
/**
|
||||
* Gives access to the class, the format and the context in the property name converters.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*
|
||||
* @deprecated since Symfony 7.2, use NameConverterInterface instead
|
||||
*/
|
||||
interface AdvancedNameConverterInterface extends NameConverterInterface
|
||||
{
|
||||
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string;
|
||||
|
||||
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string;
|
||||
}
|
||||
80
vendor/symfony/serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php
vendored
Normal file
80
vendor/symfony/serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
<?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\Serializer\NameConverter;
|
||||
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedPropertyException;
|
||||
|
||||
/**
|
||||
* CamelCase to Underscore name converter.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
* @author Aurélien Pillevesse <aurelienpillevesse@hotmail.fr>
|
||||
*/
|
||||
class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
|
||||
{
|
||||
/**
|
||||
* Require all properties to be written in snake_case.
|
||||
*/
|
||||
public const REQUIRE_SNAKE_CASE_PROPERTIES = 'require_snake_case_properties';
|
||||
|
||||
/**
|
||||
* @param string[]|null $attributes The list of attributes to rename or null for all attributes
|
||||
* @param bool $lowerCamelCase Use lowerCamelCase style
|
||||
*/
|
||||
public function __construct(
|
||||
private ?array $attributes = null,
|
||||
private bool $lowerCamelCase = true,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string|null $class
|
||||
* @param string|null $format
|
||||
* @param array<string, mixed> $context
|
||||
*/
|
||||
public function normalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
|
||||
{
|
||||
if (null === $this->attributes || \in_array($propertyName, $this->attributes, true)) {
|
||||
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
|
||||
}
|
||||
|
||||
return $propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string|null $class
|
||||
* @param string|null $format
|
||||
* @param array<string, mixed> $context
|
||||
*/
|
||||
public function denormalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
|
||||
{
|
||||
$class = 1 < \func_num_args() ? func_get_arg(1) : null;
|
||||
$format = 2 < \func_num_args() ? func_get_arg(2) : null;
|
||||
$context = 3 < \func_num_args() ? func_get_arg(3) : [];
|
||||
|
||||
if (($context[self::REQUIRE_SNAKE_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) {
|
||||
throw new UnexpectedPropertyException($propertyName);
|
||||
}
|
||||
|
||||
$camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]), $propertyName);
|
||||
|
||||
if ($this->lowerCamelCase) {
|
||||
$camelCasedName = lcfirst($camelCasedName);
|
||||
}
|
||||
|
||||
if (null === $this->attributes || \in_array($camelCasedName, $this->attributes, true)) {
|
||||
return $camelCasedName;
|
||||
}
|
||||
|
||||
return $propertyName;
|
||||
}
|
||||
}
|
||||
155
vendor/symfony/serializer/NameConverter/MetadataAwareNameConverter.php
vendored
Normal file
155
vendor/symfony/serializer/NameConverter/MetadataAwareNameConverter.php
vendored
Normal file
@ -0,0 +1,155 @@
|
||||
<?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\Serializer\NameConverter;
|
||||
|
||||
use Symfony\Component\Serializer\Exception\LogicException;
|
||||
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
||||
|
||||
/**
|
||||
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
|
||||
*/
|
||||
final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
|
||||
{
|
||||
/**
|
||||
* @var array<string, array<string, string|null>>
|
||||
*/
|
||||
private static array $normalizeCache = [];
|
||||
|
||||
/**
|
||||
* @var array<string, array<string, string|null>>
|
||||
*/
|
||||
private static array $denormalizeCache = [];
|
||||
|
||||
/**
|
||||
* @var array<string, array<string, string>>
|
||||
*/
|
||||
private static array $attributesMetadataCache = [];
|
||||
|
||||
public function __construct(
|
||||
private readonly ClassMetadataFactoryInterface $metadataFactory,
|
||||
private readonly ?NameConverterInterface $fallbackNameConverter = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
if (null === $class) {
|
||||
return $this->normalizeFallback($propertyName, $class, $format, $context);
|
||||
}
|
||||
|
||||
if (!\array_key_exists($class, self::$normalizeCache) || !\array_key_exists($propertyName, self::$normalizeCache[$class])) {
|
||||
self::$normalizeCache[$class][$propertyName] = $this->getCacheValueForNormalization($propertyName, $class);
|
||||
}
|
||||
|
||||
return self::$normalizeCache[$class][$propertyName] ?? $this->normalizeFallback($propertyName, $class, $format, $context);
|
||||
}
|
||||
|
||||
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
if (null === $class) {
|
||||
return $this->denormalizeFallback($propertyName, $class, $format, $context);
|
||||
}
|
||||
|
||||
$cacheKey = $this->getCacheKey($class, $context);
|
||||
if (!\array_key_exists($cacheKey, self::$denormalizeCache) || !\array_key_exists($propertyName, self::$denormalizeCache[$cacheKey])) {
|
||||
self::$denormalizeCache[$cacheKey][$propertyName] = $this->getCacheValueForDenormalization($propertyName, $class, $context);
|
||||
}
|
||||
|
||||
return self::$denormalizeCache[$cacheKey][$propertyName] ?? $this->denormalizeFallback($propertyName, $class, $format, $context);
|
||||
}
|
||||
|
||||
private function getCacheValueForNormalization(string $propertyName, string $class): ?string
|
||||
{
|
||||
if (!$this->metadataFactory->hasMetadataFor($class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$attributesMetadata = $this->metadataFactory->getMetadataFor($class)->getAttributesMetadata();
|
||||
if (!\array_key_exists($propertyName, $attributesMetadata)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null !== $attributesMetadata[$propertyName]->getSerializedName() && null !== $attributesMetadata[$propertyName]->getSerializedPath()) {
|
||||
throw new LogicException(\sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $propertyName, $class));
|
||||
}
|
||||
|
||||
return $attributesMetadata[$propertyName]->getSerializedName() ?? null;
|
||||
}
|
||||
|
||||
private function normalizeFallback(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
return $this->fallbackNameConverter ? $this->fallbackNameConverter->normalize($propertyName, $class, $format, $context) : $propertyName;
|
||||
}
|
||||
|
||||
private function getCacheValueForDenormalization(string $propertyName, string $class, array $context): ?string
|
||||
{
|
||||
$cacheKey = $this->getCacheKey($class, $context);
|
||||
if (!\array_key_exists($cacheKey, self::$attributesMetadataCache)) {
|
||||
self::$attributesMetadataCache[$cacheKey] = $this->getCacheValueForAttributesMetadata($class, $context);
|
||||
}
|
||||
|
||||
return self::$attributesMetadataCache[$cacheKey][$propertyName] ?? null;
|
||||
}
|
||||
|
||||
private function denormalizeFallback(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
return $this->fallbackNameConverter ? $this->fallbackNameConverter->denormalize($propertyName, $class, $format, $context) : $propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getCacheValueForAttributesMetadata(string $class, array $context): array
|
||||
{
|
||||
if (!$this->metadataFactory->hasMetadataFor($class)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$classMetadata = $this->metadataFactory->getMetadataFor($class);
|
||||
|
||||
$cache = [];
|
||||
foreach ($classMetadata->getAttributesMetadata() as $name => $metadata) {
|
||||
if (null === $metadata->getSerializedName()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null !== $metadata->getSerializedName() && null !== $metadata->getSerializedPath()) {
|
||||
throw new LogicException(\sprintf('Found SerializedName and SerializedPath attributes on property "%s" of class "%s".', $name, $class));
|
||||
}
|
||||
|
||||
$metadataGroups = $metadata->getGroups();
|
||||
$contextGroups = (array) ($context[AbstractNormalizer::GROUPS] ?? []);
|
||||
|
||||
if ($contextGroups && !$metadataGroups) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($metadataGroups && !array_intersect($metadataGroups, $contextGroups) && !\in_array('*', $contextGroups, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cache[$metadata->getSerializedName()] = $name;
|
||||
}
|
||||
|
||||
return $cache;
|
||||
}
|
||||
|
||||
private function getCacheKey(string $class, array $context): string
|
||||
{
|
||||
if (isset($context['cache_key'])) {
|
||||
return $class.'-'.$context['cache_key'];
|
||||
}
|
||||
|
||||
return $class.hash('xxh128', serialize($context[AbstractNormalizer::GROUPS] ?? []));
|
||||
}
|
||||
}
|
||||
38
vendor/symfony/serializer/NameConverter/NameConverterInterface.php
vendored
Normal file
38
vendor/symfony/serializer/NameConverter/NameConverterInterface.php
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
<?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\Serializer\NameConverter;
|
||||
|
||||
/**
|
||||
* Defines the interface for property name converters.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
interface NameConverterInterface
|
||||
{
|
||||
/**
|
||||
* Converts a property name to its normalized value.
|
||||
*
|
||||
* @param class-string|null $class
|
||||
* @param string|null $format
|
||||
* @param array<string, mixed> $context
|
||||
*/
|
||||
public function normalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string;
|
||||
|
||||
/**
|
||||
* Converts a property name to its denormalized value.
|
||||
*
|
||||
* @param class-string|null $class
|
||||
* @param string|null $format
|
||||
* @param array<string, mixed> $context
|
||||
*/
|
||||
public function denormalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string;
|
||||
}
|
||||
78
vendor/symfony/serializer/NameConverter/SnakeCaseToCamelCaseNameConverter.php
vendored
Normal file
78
vendor/symfony/serializer/NameConverter/SnakeCaseToCamelCaseNameConverter.php
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
<?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\Serializer\NameConverter;
|
||||
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedPropertyException;
|
||||
|
||||
/**
|
||||
* Underscore to camelCase name converter.
|
||||
*
|
||||
* @author Kévin Dunglas <kevin@dunglas.dev>
|
||||
*/
|
||||
final readonly class SnakeCaseToCamelCaseNameConverter implements NameConverterInterface
|
||||
{
|
||||
/**
|
||||
* Require all properties to be written in camelCase.
|
||||
*/
|
||||
public const REQUIRE_CAMEL_CASE_PROPERTIES = 'require_camel_case_properties';
|
||||
|
||||
/**
|
||||
* @param string[]|null $attributes The list of attributes to rename or null for all attributes
|
||||
* @param bool $lowerCamelCase Use lowerCamelCase style
|
||||
*/
|
||||
public function __construct(
|
||||
private ?array $attributes = null,
|
||||
private bool $lowerCamelCase = true,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string|null $class
|
||||
* @param array<string, mixed> $context
|
||||
*/
|
||||
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
if (null !== $this->attributes && !\in_array($propertyName, $this->attributes, true)) {
|
||||
return $propertyName;
|
||||
}
|
||||
|
||||
$camelCasedName = preg_replace_callback(
|
||||
'/(^|_|\.)+(.)/',
|
||||
fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]),
|
||||
$propertyName
|
||||
);
|
||||
|
||||
if ($this->lowerCamelCase) {
|
||||
$camelCasedName = lcfirst($camelCasedName);
|
||||
}
|
||||
|
||||
return $camelCasedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string|null $class
|
||||
* @param array<string, mixed> $context
|
||||
*/
|
||||
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
|
||||
{
|
||||
if (($context[self::REQUIRE_CAMEL_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) {
|
||||
throw new UnexpectedPropertyException($propertyName);
|
||||
}
|
||||
|
||||
$snakeCased = strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
|
||||
if (null === $this->attributes || \in_array($snakeCased, $this->attributes, true)) {
|
||||
return $snakeCased;
|
||||
}
|
||||
|
||||
return $propertyName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user