first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,184 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
/**
* A helper providing autocompletion for available AbstractNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
abstract class AbstractNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configures how many loops of circular reference to allow while normalizing.
*
* The value 1 means that when we encounter the same object a
* second time, we consider that a circular reference.
*
* You can raise this value for special cases, e.g. in combination with the
* max depth setting of the object normalizer.
*
* Must be strictly positive.
*
* @param positive-int|null $circularReferenceLimit
*/
public function withCircularReferenceLimit(?int $circularReferenceLimit): static
{
return $this->with(AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT, $circularReferenceLimit);
}
/**
* Configures an object to be updated instead of creating a new instance.
*
* If you have a nested structure, child objects will be overwritten with
* new instances unless you set AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE to true.
*/
public function withObjectToPopulate(?object $objectToPopulate): static
{
return $this->with(AbstractNormalizer::OBJECT_TO_POPULATE, $objectToPopulate);
}
/**
* Configures groups containing attributes to (de)normalize.
*
* Eg: ['group1', 'group2']
*
* @param list<string>|string|null $groups
*/
public function withGroups(array|string|null $groups): static
{
if (null === $groups) {
return $this->with(AbstractNormalizer::GROUPS, null);
}
return $this->with(AbstractNormalizer::GROUPS, (array) $groups);
}
/**
* Configures attributes to (de)normalize.
*
* For nested structures, this list needs to reflect the object tree.
*
* Eg: ['foo', 'bar', 'object' => ['baz']]
*
* @param array<string|array>|null $attributes
*
* @throws InvalidArgumentException
*/
public function withAttributes(?array $attributes): static
{
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($attributes ?? []), \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($it as $attribute) {
if (!\is_string($attribute)) {
throw new InvalidArgumentException(sprintf('Each attribute must be a string, "%s" given.', get_debug_type($attribute)));
}
}
return $this->with(AbstractNormalizer::ATTRIBUTES, $attributes);
}
/**
* If AbstractNormalizer::ATTRIBUTES are specified, and the source has fields that are not part of that list,
* configures whether to ignore those attributes or throw an ExtraAttributesException.
*/
public function withAllowExtraAttributes(?bool $allowExtraAttributes): static
{
return $this->with(AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES, $allowExtraAttributes);
}
/**
* Configures a hashmap of classes containing hashmaps of constructor argument => default value.
*
* The names need to match the parameter names in the constructor arguments.
*
* Eg: [Foo::class => ['foo' => true, 'bar' => 0]]
*
* @param array<class-string, array<string, mixed>>|null $defaultConstructorArguments
*/
public function withDefaultConstructorArguments(?array $defaultConstructorArguments): static
{
return $this->with(AbstractNormalizer::DEFAULT_CONSTRUCTOR_ARGUMENTS, $defaultConstructorArguments);
}
/**
* Deprecated in Symfony 7.1, use withDefaultConstructorArguments() instead.
*/
public function withDefaultContructorArguments(?array $defaultContructorArguments): static
{
return self::withDefaultConstructorArguments($defaultContructorArguments);
}
/**
* Configures an hashmap of field name => callable to normalize this field.
*
* The callable is called if the field is encountered with the arguments:
*
* - mixed $attributeValue value of this field
* - object $object the whole object being normalized
* - string $attributeName name of the attribute being normalized
* - string $format the requested format
* - array<string, mixed> $context the serialization context
*
* @param array<string, callable>|null $callbacks
*/
public function withCallbacks(?array $callbacks): static
{
return $this->with(AbstractNormalizer::CALLBACKS, $callbacks);
}
/**
* Configures an handler to call when a circular reference has been detected.
*
* If no handler is specified, a CircularReferenceException is thrown.
*
* The method will be called with ($object, $format, $context) and its
* return value is returned as the result of the normalize call.
*/
public function withCircularReferenceHandler(?callable $circularReferenceHandler): static
{
return $this->with(AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER, $circularReferenceHandler);
}
/**
* Configures attributes to be skipped when normalizing an object tree.
*
* This list is applied to each element of nested structures.
*
* Eg: ['foo', 'bar']
*
* Note: The behaviour for nested structures is different from ATTRIBUTES
* for historical reason. Aligning the behaviour would be a BC break.
*
* @param list<string>|null $ignoredAttributes
*/
public function withIgnoredAttributes(?array $ignoredAttributes): static
{
return $this->with(AbstractNormalizer::IGNORED_ATTRIBUTES, $ignoredAttributes);
}
/**
* Configures requiring all properties to be listed in the input instead
* of falling back to null for nullable ones.
*/
public function withRequireAllProperties(?bool $requireAllProperties = true): static
{
return $this->with(AbstractNormalizer::REQUIRE_ALL_PROPERTIES, $requireAllProperties);
}
}

View File

@@ -0,0 +1,131 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
/**
* A helper providing autocompletion for available AbstractObjectNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
abstract class AbstractObjectNormalizerContextBuilder extends AbstractNormalizerContextBuilder
{
/**
* Configures whether to respect the max depth metadata on fields.
*/
public function withEnableMaxDepth(?bool $enableMaxDepth): static
{
return $this->with(AbstractObjectNormalizer::ENABLE_MAX_DEPTH, $enableMaxDepth);
}
/**
* Configures a pattern to keep track of the current depth.
*
* Must contain exactly two string placeholders.
*
* @throws InvalidArgumentException
*/
public function withDepthKeyPattern(?string $depthKeyPattern): static
{
if (null === $depthKeyPattern) {
return $this->with(AbstractObjectNormalizer::DEPTH_KEY_PATTERN, null);
}
// This will match every occurrences of sprintf specifiers
$matches = [];
preg_match_all('/(?<!%)(?:%{2})*%(?<specifier>[a-z])/', $depthKeyPattern, $matches);
if (2 !== \count($matches['specifier']) || 's' !== $matches['specifier'][0] || 's' !== $matches['specifier'][1]) {
throw new InvalidArgumentException(sprintf('The depth key pattern "%s" is not valid. You must set exactly two string placeholders.', $depthKeyPattern));
}
return $this->with(AbstractObjectNormalizer::DEPTH_KEY_PATTERN, $depthKeyPattern);
}
/**
* Configures whether verifying types match during denormalization.
*/
public function withDisableTypeEnforcement(?bool $disableTypeEnforcement): static
{
return $this->with(AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT, $disableTypeEnforcement);
}
/**
* Configures whether fields with the value `null` should be output during normalization.
*/
public function withSkipNullValues(?bool $skipNullValues): static
{
return $this->with(AbstractObjectNormalizer::SKIP_NULL_VALUES, $skipNullValues);
}
/**
* Configures whether uninitialized typed class properties should be excluded during normalization.
*/
public function withSkipUninitializedValues(?bool $skipUninitializedValues): static
{
return $this->with(AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES, $skipUninitializedValues);
}
/**
* Configures a callback to allow to set a value for an attribute when the max depth has
* been reached.
*
* If no callback is given, the attribute is skipped. If a callable is
* given, its return value is used (even if null).
*
* The arguments are:
*
* - mixed $attributeValue value of this field
* - object $object the whole object being normalized
* - string $attributeName name of the attribute being normalized
* - string $format the requested format
* - array<string, mixed> $context the serialization context
*/
public function withMaxDepthHandler(?callable $maxDepthHandler): static
{
return $this->with(AbstractObjectNormalizer::MAX_DEPTH_HANDLER, $maxDepthHandler);
}
/**
* Configures which context key are not relevant to determine which attributes
* of an object to (de)normalize.
*
* @param list<string>|null $excludeFromCacheKeys
*/
public function withExcludeFromCacheKeys(?array $excludeFromCacheKeys): static
{
return $this->with(AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY, $excludeFromCacheKeys);
}
/**
* Configures whether to tell the denormalizer to also populate existing objects on
* attributes of the main object.
*
* Setting this to true is only useful if you also specify the root object
* in AbstractNormalizer::OBJECT_TO_POPULATE.
*/
public function withDeepObjectToPopulate(?bool $deepObjectToPopulate): static
{
return $this->with(AbstractObjectNormalizer::DEEP_OBJECT_TO_POPULATE, $deepObjectToPopulate);
}
/**
* Configures whether an empty object should be kept as an object (in
* JSON: {}) or converted to a list (in JSON: []).
*/
public function withPreserveEmptyObjects(?bool $preserveEmptyObjects): static
{
return $this->with(AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS, $preserveEmptyObjects);
}
}

View File

@@ -0,0 +1,35 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer;
/**
* A helper providing autocompletion for available BackedEnumNormalizer options.
*
* @author Nicolas PHILIPPE <nikophil@gmail.com>
*/
final class BackedEnumNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configures if invalid values are allowed in denormalization.
* They will be denormalized into `null` values.
*/
public function withAllowInvalidValues(bool $allowInvalidValues): static
{
return $this->with(BackedEnumNormalizer::ALLOW_INVALID_VALUES, $allowInvalidValues);
}
}

View File

@@ -0,0 +1,71 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer;
/**
* A helper providing autocompletion for available ConstraintViolationList options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class ConstraintViolationListNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configure the instance field of normalized data.
*/
public function withInstance(mixed $instance): static
{
return $this->with(ConstraintViolationListNormalizer::INSTANCE, $instance);
}
/**
* Configure the status field of normalized data.
*/
public function withStatus(?int $status): static
{
return $this->with(ConstraintViolationListNormalizer::STATUS, $status);
}
/**
* Configure the title field of normalized data.
*/
public function withTitle(?string $title): static
{
return $this->with(ConstraintViolationListNormalizer::TITLE, $title);
}
/**
* Configure the type field of normalized data.
*/
public function withType(?string $type): static
{
return $this->with(ConstraintViolationListNormalizer::TYPE, $type);
}
/**
* Configures the payload fields which will act as an allowlist
* for the payload field of normalized data.
*
* Eg: ['foo', 'bar']
*
* @param list<string>|null $payloadFields
*/
public function withPayloadFields(?array $payloadFields): static
{
return $this->with(ConstraintViolationListNormalizer::PAYLOAD_FIELDS, $payloadFields);
}
}

View File

@@ -0,0 +1,36 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Normalizer\DateIntervalNormalizer;
/**
* A helper providing autocompletion for available DateIntervalNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class DateIntervalNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configures the format of the interval.
*
* @see https://php.net/manual/en/dateinterval.format.php
*/
public function withFormat(?string $format): static
{
return $this->with(DateIntervalNormalizer::FORMAT_KEY, $format);
}
}

View File

@@ -0,0 +1,64 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
/**
* A helper providing autocompletion for available DateTimeNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class DateTimeNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configures the format of the date.
*
* @see https://secure.php.net/manual/en/datetime.format.php
*/
public function withFormat(?string $format): static
{
return $this->with(DateTimeNormalizer::FORMAT_KEY, $format);
}
/**
* Configures the timezone of the date.
*
* It could be either a \DateTimeZone or a string
* that will be used to construct the \DateTimeZone
*
* @see https://secure.php.net/manual/en/class.datetimezone.php
*
* @throws InvalidArgumentException
*/
public function withTimezone(\DateTimeZone|string|null $timezone): static
{
if (null === $timezone) {
return $this->with(DateTimeNormalizer::TIMEZONE_KEY, null);
}
if (\is_string($timezone)) {
try {
$timezone = new \DateTimeZone($timezone);
} catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('The "%s" timezone is invalid.', $timezone), previous: $e);
}
}
return $this->with(DateTimeNormalizer::TIMEZONE_KEY, $timezone);
}
}

View File

@@ -0,0 +1,50 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Normalizer\FormErrorNormalizer;
/**
* A helper providing autocompletion for available FormErrorNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class FormErrorNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configures the title of the normalized data.
*/
public function withTitle(?string $title): static
{
return $this->with(FormErrorNormalizer::TITLE, $title);
}
/**
* Configures the type of the normalized data.
*/
public function withType(?string $type): static
{
return $this->with(FormErrorNormalizer::TYPE, $type);
}
/**
* Configures the code of the normalized data.
*/
public function withStatusCode(?int $statusCode): static
{
return $this->with(FormErrorNormalizer::CODE, $statusCode);
}
}

View File

@@ -0,0 +1,21 @@
<?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\Context\Normalizer;
/**
* A helper providing autocompletion for available GetSetMethodNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class GetSetMethodNormalizerContextBuilder extends AbstractObjectNormalizerContextBuilder
{
}

View File

@@ -0,0 +1,21 @@
<?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\Context\Normalizer;
/**
* A helper providing autocompletion for available JsonSerializableNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class JsonSerializableNormalizerContextBuilder extends AbstractNormalizerContextBuilder
{
}

View File

@@ -0,0 +1,21 @@
<?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\Context\Normalizer;
/**
* A helper providing autocompletion for available ObjectNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class ObjectNormalizerContextBuilder extends AbstractObjectNormalizerContextBuilder
{
}

View File

@@ -0,0 +1,50 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Normalizer\ProblemNormalizer;
/**
* A helper providing autocompletion for available ProblemNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class ProblemNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configure the title field of normalized data.
*/
public function withTitle(?string $title): static
{
return $this->with(ProblemNormalizer::TITLE, $title);
}
/**
* Configure the type field of normalized data.
*/
public function withType(?string $type): static
{
return $this->with(ProblemNormalizer::TYPE, $type);
}
/**
* Configure the status field of normalized data.
*/
public function withStatusCode(int|string|null $statusCode): static
{
return $this->with(ProblemNormalizer::STATUS, $statusCode);
}
}

View File

@@ -0,0 +1,30 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
/**
* A helper providing autocompletion for available PropertyNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class PropertyNormalizerContextBuilder extends AbstractObjectNormalizerContextBuilder
{
/**
* Configures whether fields should be output based on visibility.
*/
public function withNormalizeVisibility(int $normalizeVisibility): static
{
return $this->with(PropertyNormalizer::NORMALIZE_VISIBILITY, $normalizeVisibility);
}
}

View File

@@ -0,0 +1,41 @@
<?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\Context\Normalizer;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\UidNormalizer;
/**
* A helper providing autocompletion for available UidNormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class UidNormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configures the uuid format for normalization.
*
* @throws InvalidArgumentException
*/
public function withNormalizationFormat(?string $normalizationFormat): static
{
if (null !== $normalizationFormat && !\in_array($normalizationFormat, UidNormalizer::NORMALIZATION_FORMATS, true)) {
throw new InvalidArgumentException(sprintf('The "%s" normalization format is not valid.', $normalizationFormat));
}
return $this->with(UidNormalizer::NORMALIZATION_FORMAT_KEY, $normalizationFormat);
}
}

View File

@@ -0,0 +1,53 @@
<?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\Context\Normalizer;
use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\Serializer\Context\ContextBuilderInterface;
use Symfony\Component\Serializer\Context\ContextBuilderTrait;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
/**
* A helper providing autocompletion for available UnwrappingDenormalizer options.
*
* @author Mathias Arlaud <mathias.arlaud@gmail.com>
*/
final class UnwrappingDenormalizerContextBuilder implements ContextBuilderInterface
{
use ContextBuilderTrait;
/**
* Configures the path of wrapped data during denormalization.
*
* Eg: [foo].bar[bar]
*
* @see https://symfony.com/doc/current/components/property_access.html
*
* @throws InvalidArgumentException
*/
public function withUnwrapPath(?string $unwrapPath): static
{
if (null === $unwrapPath) {
return $this->with(UnwrappingDenormalizer::UNWRAP_PATH, null);
}
try {
new PropertyPath($unwrapPath);
} catch (InvalidPropertyPathException $e) {
throw new InvalidArgumentException(sprintf('The "%s" property path is not valid.', $unwrapPath), previous: $e);
}
return $this->with(UnwrappingDenormalizer::UNWRAP_PATH, $unwrapPath);
}
}