This commit is contained in:
Marek
2026-03-24 00:04:55 +01:00
commit c5229e48ed
4225 changed files with 511461 additions and 0 deletions

View 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\Attribute;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
class Context
{
public readonly array $groups;
/**
* @param array<string, mixed> $context The common context to use when serializing or deserializing
* @param array<string, mixed> $normalizationContext The context to use when serializing
* @param array<string, mixed> $denormalizationContext The context to use when deserializing
* @param string|string[] $groups The groups to use when serializing or deserializing
*
* @throws InvalidArgumentException
*/
public function __construct(
public readonly array $context = [],
public readonly array $normalizationContext = [],
public readonly array $denormalizationContext = [],
string|array $groups = [],
) {
if (!$context && !$normalizationContext && !$denormalizationContext) {
throw new InvalidArgumentException(\sprintf('At least one of the "context", "normalizationContext", or "denormalizationContext" options must be provided as a non-empty array to "%s".', static::class));
}
$this->groups = (array) $groups;
foreach ($this->groups as $group) {
if (!\is_string($group)) {
throw new InvalidArgumentException(\sprintf('Parameter "groups" given to "%s" must be a string or an array of strings, "%s" given.', static::class, get_debug_type($group)));
}
}
}
#[\Deprecated('Use the "context" property instead', 'symfony/serializer:7.4')]
public function getContext(): array
{
return $this->context;
}
#[\Deprecated('Use the "normalizationContext" property instead', 'symfony/serializer:7.4')]
public function getNormalizationContext(): array
{
return $this->normalizationContext;
}
#[\Deprecated('Use the "denormalizationContext" property instead', 'symfony/serializer:7.4')]
public function getDenormalizationContext(): array
{
return $this->denormalizationContext;
}
#[\Deprecated('Use the "groups" property instead', 'symfony/serializer:7.4')]
public function getGroups(): array
{
return $this->groups;
}
}
if (!class_exists(\Symfony\Component\Serializer\Annotation\Context::class, false)) {
class_alias(Context::class, \Symfony\Component\Serializer\Annotation\Context::class);
}

View File

@@ -0,0 +1,68 @@
<?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\Attribute;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @author Samuel Roze <samuel.roze@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class DiscriminatorMap
{
/**
* @param string $typeProperty The property holding the type discriminator
* @param array<string, class-string> $mapping The mapping between types and classes (i.e. ['admin_user' => AdminUser::class])
* @param ?string $defaultType The fallback value if nothing specified by $typeProperty
*
* @throws InvalidArgumentException
*/
public function __construct(
public readonly string $typeProperty,
public readonly array $mapping,
public readonly ?string $defaultType = null,
) {
if (!$typeProperty) {
throw new InvalidArgumentException(\sprintf('Parameter "typeProperty" given to "%s" cannot be empty.', static::class));
}
if (!$mapping) {
throw new InvalidArgumentException(\sprintf('Parameter "mapping" given to "%s" cannot be empty.', static::class));
}
if (null !== $this->defaultType && !\array_key_exists($this->defaultType, $this->mapping)) {
throw new InvalidArgumentException(\sprintf('Default type "%s" given to "%s" must be present in "mapping" types.', $this->defaultType, static::class));
}
}
#[\Deprecated('Use the "typeProperty" property instead', 'symfony/serializer:7.4')]
public function getTypeProperty(): string
{
return $this->typeProperty;
}
#[\Deprecated('Use the "mapping" property instead', 'symfony/serializer:7.4')]
public function getMapping(): array
{
return $this->mapping;
}
#[\Deprecated('Use the "defaultType" property instead', 'symfony/serializer:7.4')]
public function getDefaultType(): ?string
{
return $this->defaultType;
}
}
if (!class_exists(\Symfony\Component\Serializer\Annotation\DiscriminatorMap::class, false)) {
class_alias(DiscriminatorMap::class, \Symfony\Component\Serializer\Annotation\DiscriminatorMap::class);
}

View File

@@ -0,0 +1,32 @@
<?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\Attribute;
/**
* Declares that serialization attributes listed on the current class should be added to the given class.
*
* Classes that use this attribute should contain only properties and methods that
* exist on the target class (not necessarily all of them).
*
* @author Nicolas Grekas <p@tchwork.com>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class ExtendsSerializationFor
{
/**
* @param class-string $class
*/
public function __construct(
public string $class,
) {
}
}

View File

@@ -0,0 +1,57 @@
<?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\Attribute;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS)]
class Groups
{
/**
* @var string[]
*/
public readonly array $groups;
/**
* @param string|string[] $groups The groups to define on the attribute target
*/
public function __construct(string|array $groups)
{
$this->groups = (array) $groups;
if (!$this->groups) {
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" cannot be empty.', static::class));
}
foreach ($this->groups as $group) {
if (!\is_string($group) || '' === $group) {
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a string or an array of non-empty strings.', static::class));
}
}
}
/**
* @return string[]
*/
#[\Deprecated('Use the "groups" property instead', 'symfony/serializer:7.4')]
public function getGroups(): array
{
return $this->groups;
}
}
if (!class_exists(\Symfony\Component\Serializer\Annotation\Groups::class, false)) {
class_alias(Groups::class, \Symfony\Component\Serializer\Annotation\Groups::class);
}

View File

@@ -0,0 +1,24 @@
<?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\Attribute;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
class Ignore
{
}
if (!class_exists(\Symfony\Component\Serializer\Annotation\Ignore::class, false)) {
class_alias(Ignore::class, \Symfony\Component\Serializer\Annotation\Ignore::class);
}

View File

@@ -0,0 +1,42 @@
<?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\Attribute;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
class MaxDepth
{
/**
* @param int $maxDepth The maximum serialization depth
*/
public function __construct(
public readonly int $maxDepth,
) {
if ($maxDepth <= 0) {
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a positive integer.', static::class));
}
}
#[\Deprecated('Use the "maxdepth" property instead', 'symfony/serializer:7.4')]
public function getMaxDepth(): int
{
return $this->maxDepth;
}
}
if (!class_exists(\Symfony\Component\Serializer\Annotation\MaxDepth::class, false)) {
class_alias(MaxDepth::class, \Symfony\Component\Serializer\Annotation\MaxDepth::class);
}

View File

@@ -0,0 +1,42 @@
<?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\Attribute;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
class SerializedName
{
/**
* @param string $serializedName The name of the property as it will be serialized
*/
public function __construct(
public readonly string $serializedName,
) {
if ('' === $serializedName) {
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a non-empty string.', self::class));
}
}
#[\Deprecated('Use the "serializedName" property instead', 'symfony/serializer:7.4')]
public function getSerializedName(): string
{
return $this->serializedName;
}
}
if (!class_exists(\Symfony\Component\Serializer\Annotation\SerializedName::class, false)) {
class_alias(SerializedName::class, \Symfony\Component\Serializer\Annotation\SerializedName::class);
}

View File

@@ -0,0 +1,47 @@
<?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\Attribute;
use Symfony\Component\PropertyAccess\Exception\InvalidPropertyPathException;
use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
/**
* @author Tobias Bönner <tobi@boenner.family>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
class SerializedPath
{
public readonly PropertyPath $serializedPath;
/**
* @param string $serializedPath A path using a valid PropertyAccess syntax where the value is stored in a normalized representation
*/
public function __construct(string $serializedPath)
{
try {
$this->serializedPath = new PropertyPath($serializedPath);
} catch (InvalidPropertyPathException) {
throw new InvalidArgumentException(\sprintf('Parameter given to "%s" must be a valid property path.', self::class));
}
}
#[\Deprecated('Use the "serializedPath" property instead', 'symfony/serializer:7.4')]
public function getSerializedPath(): PropertyPath
{
return $this->serializedPath;
}
}
if (!class_exists(\Symfony\Component\Serializer\Annotation\SerializedPath::class, false)) {
class_alias(SerializedPath::class, \Symfony\Component\Serializer\Annotation\SerializedPath::class);
}