Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+31 -6
View File
@@ -42,11 +42,15 @@ class AttributeMetadata implements AttributeMetadataInterface
public $maxDepth;
/**
* Constructs a metadata for the given attribute.
* @var string|null
*
* @param string $name
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getSerializedName()} instead.
*/
public function __construct($name)
public $serializedName;
public function __construct(string $name)
{
$this->name = $name;
}
@@ -54,7 +58,7 @@ class AttributeMetadata implements AttributeMetadataInterface
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return $this->name;
}
@@ -72,7 +76,7 @@ class AttributeMetadata implements AttributeMetadataInterface
/**
* {@inheritdoc}
*/
public function getGroups()
public function getGroups(): array
{
return $this->groups;
}
@@ -93,6 +97,22 @@ class AttributeMetadata implements AttributeMetadataInterface
return $this->maxDepth;
}
/**
* {@inheritdoc}
*/
public function setSerializedName(string $serializedName = null)
{
$this->serializedName = $serializedName;
}
/**
* {@inheritdoc}
*/
public function getSerializedName(): ?string
{
return $this->serializedName;
}
/**
* {@inheritdoc}
*/
@@ -106,6 +126,11 @@ class AttributeMetadata implements AttributeMetadataInterface
if (null === $this->maxDepth) {
$this->maxDepth = $attributeMetadata->getMaxDepth();
}
// Overwrite only if not defined
if (null === $this->serializedName) {
$this->serializedName = $attributeMetadata->getSerializedName();
}
}
/**
@@ -115,6 +140,6 @@ class AttributeMetadata implements AttributeMetadataInterface
*/
public function __sleep()
{
return ['name', 'groups', 'maxDepth'];
return ['name', 'groups', 'maxDepth', 'serializedName'];
}
}
@@ -24,10 +24,8 @@ interface AttributeMetadataInterface
{
/**
* Gets the attribute name.
*
* @return string
*/
public function getName();
public function getName(): string;
/**
* Adds this attribute to the given group.
@@ -41,7 +39,7 @@ interface AttributeMetadataInterface
*
* @return string[]
*/
public function getGroups();
public function getGroups(): array;
/**
* Sets the serialization max depth for this attribute.
@@ -57,6 +55,16 @@ interface AttributeMetadataInterface
*/
public function getMaxDepth();
/**
* Sets the serialization name for this attribute.
*/
public function setSerializedName(string $serializedName = null);
/**
* Gets the serialization name for this attribute.
*/
public function getSerializedName(): ?string;
/**
* Merges an {@see AttributeMetadataInterface} with in the current one.
*/
+31 -6
View File
@@ -40,19 +40,27 @@ class ClassMetadata implements ClassMetadataInterface
private $reflClass;
/**
* Constructs a metadata for the given class.
* @var ClassDiscriminatorMapping|null
*
* @param string $class
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
* {@link getClassDiscriminatorMapping()} instead.
*/
public function __construct($class)
public $classDiscriminatorMapping;
/**
* Constructs a metadata for the given class.
*/
public function __construct(string $class, ClassDiscriminatorMapping $classDiscriminatorMapping = null)
{
$this->name = $class;
$this->classDiscriminatorMapping = $classDiscriminatorMapping;
}
/**
* {@inheritdoc}
*/
public function getName()
public function getName(): string
{
return $this->name;
}
@@ -68,7 +76,7 @@ class ClassMetadata implements ClassMetadataInterface
/**
* {@inheritdoc}
*/
public function getAttributesMetadata()
public function getAttributesMetadata(): array
{
return $this->attributesMetadata;
}
@@ -90,7 +98,7 @@ class ClassMetadata implements ClassMetadataInterface
/**
* {@inheritdoc}
*/
public function getReflectionClass()
public function getReflectionClass(): \ReflectionClass
{
if (!$this->reflClass) {
$this->reflClass = new \ReflectionClass($this->getName());
@@ -99,6 +107,22 @@ class ClassMetadata implements ClassMetadataInterface
return $this->reflClass;
}
/**
* {@inheritdoc}
*/
public function getClassDiscriminatorMapping(): ?ClassDiscriminatorMapping
{
return $this->classDiscriminatorMapping;
}
/**
* {@inheritdoc}
*/
public function setClassDiscriminatorMapping(ClassDiscriminatorMapping $mapping = null)
{
$this->classDiscriminatorMapping = $mapping;
}
/**
* Returns the names of the properties that should be serialized.
*
@@ -109,6 +133,7 @@ class ClassMetadata implements ClassMetadataInterface
return [
'name',
'attributesMetadata',
'classDiscriminatorMapping',
];
}
}
@@ -29,7 +29,7 @@ interface ClassMetadataInterface
*
* @return string The name of the backing class
*/
public function getName();
public function getName(): string;
/**
* Adds an {@link AttributeMetadataInterface}.
@@ -41,7 +41,7 @@ interface ClassMetadataInterface
*
* @return AttributeMetadataInterface[]
*/
public function getAttributesMetadata();
public function getAttributesMetadata(): array;
/**
* Merges a {@link ClassMetadataInterface} in the current one.
@@ -50,8 +50,10 @@ interface ClassMetadataInterface
/**
* Returns a {@link \ReflectionClass} instance for this class.
*
* @return \ReflectionClass
*/
public function getReflectionClass();
public function getReflectionClass(): \ReflectionClass;
public function getClassDiscriminatorMapping(): ?ClassDiscriminatorMapping;
public function setClassDiscriminatorMapping(ClassDiscriminatorMapping $mapping = null);
}
@@ -44,8 +44,7 @@ class CacheClassMetadataFactory implements ClassMetadataFactoryInterface
public function getMetadataFor($value)
{
$class = $this->getClass($value);
// Key cannot contain backslashes according to PSR-6
$key = strtr($class, '\\', '_');
$key = rawurlencode(strtr($class, '\\', '_'));
$item = $this->cacheItemPool->getItem($key);
if ($item->isHit()) {
@@ -11,8 +11,6 @@
namespace Symfony\Component\Serializer\Mapping\Factory;
use Doctrine\Common\Cache\Cache;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Loader\LoaderInterface;
@@ -26,17 +24,15 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
use ClassResolverTrait;
private $loader;
private $cache;
/**
* @var array
*/
private $loadedClasses;
public function __construct(LoaderInterface $loader, Cache $cache = null)
public function __construct(LoaderInterface $loader)
{
$this->loader = $loader;
$this->cache = $cache;
if (null !== $cache) {
@trigger_error(sprintf('Passing a Doctrine Cache instance as 2nd parameter of the "%s" constructor is deprecated since Symfony 3.1. This parameter will be removed in Symfony 4.0. Use the "%s" class instead.', __CLASS__, CacheClassMetadataFactory::class), \E_USER_DEPRECATED);
}
}
/**
@@ -50,10 +46,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
return $this->loadedClasses[$class];
}
if ($this->cache && ($this->loadedClasses[$class] = $this->cache->fetch($class))) {
return $this->loadedClasses[$class];
}
$classMetadata = new ClassMetadata($class);
$this->loader->loadClassMetadata($classMetadata);
@@ -69,10 +61,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
$classMetadata->merge($this->getMetadataFor($interface->name));
}
if ($this->cache) {
$this->cache->save($class, $classMetadata);
}
return $this->loadedClasses[$class] = $classMetadata;
}
@@ -81,14 +69,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
*/
public function hasMetadataFor($value)
{
try {
$this->getClass($value);
return true;
} catch (InvalidArgumentException $invalidArgumentException) {
// Return false in case of exception
}
return false;
return \is_object($value) || (\is_string($value) && (class_exists($value) || interface_exists($value, false)));
}
}
@@ -27,14 +27,12 @@ trait ClassResolverTrait
*
* @param object|string $value
*
* @return string
*
* @throws InvalidArgumentException If the class does not exist
*/
private function getClass($value)
private function getClass($value): string
{
if (\is_string($value)) {
if (!class_exists($value) && !interface_exists($value)) {
if (!class_exists($value) && !interface_exists($value, false)) {
throw new InvalidArgumentException(sprintf('The class or interface "%s" does not exist.', $value));
}
@@ -12,10 +12,13 @@
namespace Symfony\Component\Serializer\Mapping\Loader;
use Doctrine\Common\Annotations\Reader;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Serializer\Exception\MappingException;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
/**
@@ -43,6 +46,15 @@ class AnnotationLoader implements LoaderInterface
$attributesMetadata = $classMetadata->getAttributesMetadata();
foreach ($this->reader->getClassAnnotations($reflectionClass) as $annotation) {
if ($annotation instanceof DiscriminatorMap) {
$classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping(
$annotation->getTypeProperty(),
$annotation->getMapping()
));
}
}
foreach ($reflectionClass->getProperties() as $property) {
if (!isset($attributesMetadata[$property->name])) {
$attributesMetadata[$property->name] = new AttributeMetadata($property->name);
@@ -57,6 +69,8 @@ class AnnotationLoader implements LoaderInterface
}
} elseif ($annotation instanceof MaxDepth) {
$attributesMetadata[$property->name]->setMaxDepth($annotation->getMaxDepth());
} elseif ($annotation instanceof SerializedName) {
$attributesMetadata[$property->name]->setSerializedName($annotation->getSerializedName());
}
$loaded = true;
@@ -84,7 +98,7 @@ class AnnotationLoader implements LoaderInterface
foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
if ($annotation instanceof Groups) {
if (!$accessorOrMutator) {
throw new MappingException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
throw new MappingException(sprintf('Groups on "%s::%s()" cannot be added. Groups can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
}
foreach ($annotation->getGroups() as $group) {
@@ -92,10 +106,16 @@ class AnnotationLoader implements LoaderInterface
}
} elseif ($annotation instanceof MaxDepth) {
if (!$accessorOrMutator) {
throw new MappingException(sprintf('MaxDepth on "%s::%s" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
throw new MappingException(sprintf('MaxDepth on "%s::%s()" cannot be added. MaxDepth can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
}
$attributeMetadata->setMaxDepth($annotation->getMaxDepth());
} elseif ($annotation instanceof SerializedName) {
if (!$accessorOrMutator) {
throw new MappingException(sprintf('SerializedName on "%s::%s()" cannot be added. SerializedName can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
}
$attributeMetadata->setSerializedName($annotation->getSerializedName());
}
$loaded = true;
+1 -1
View File
@@ -27,7 +27,7 @@ abstract class FileLoader implements LoaderInterface
*
* @throws MappingException if the mapping file does not exist or is not readable
*/
public function __construct($file)
public function __construct(string $file)
{
if (!is_file($file)) {
throw new MappingException(sprintf('The mapping file "%s" does not exist.', $file));
+21 -7
View File
@@ -14,6 +14,7 @@ namespace Symfony\Component\Serializer\Mapping\Loader;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\Serializer\Exception\MappingException;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
/**
@@ -65,6 +66,23 @@ class XmlFileLoader extends FileLoader
if (isset($attribute['max-depth'])) {
$attributeMetadata->setMaxDepth((int) $attribute['max-depth']);
}
if (isset($attribute['serialized-name'])) {
$attributeMetadata->setSerializedName((string) $attribute['serialized-name']);
}
}
if (isset($xml->{'discriminator-map'})) {
$mapping = [];
foreach ($xml->{'discriminator-map'}->mapping as $element) {
$elementAttributes = $element->attributes();
$mapping[(string) $elementAttributes->type] = (string) $elementAttributes->class;
}
$classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping(
(string) $xml->{'discriminator-map'}->attributes()->{'type-property'},
$mapping
));
}
return true;
@@ -88,15 +106,11 @@ class XmlFileLoader extends FileLoader
}
/**
* Parses a XML File.
*
* @param string $file Path of file
*
* @return \SimpleXMLElement
* Parses an XML File.
*
* @throws MappingException
*/
private function parseFile($file)
private function parseFile(string $file): \SimpleXMLElement
{
try {
$dom = XmlUtils::loadFile($file, __DIR__.'/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd');
@@ -107,7 +121,7 @@ class XmlFileLoader extends FileLoader
return simplexml_import_dom($dom);
}
private function getClassesFromXml()
private function getClassesFromXml(): array
{
$xml = $this->parseFile($this->file);
$classes = [];
+27 -2
View File
@@ -13,8 +13,10 @@ namespace Symfony\Component\Serializer\Mapping\Loader;
use Symfony\Component\Serializer\Exception\MappingException;
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;
/**
* YAML File Loader.
@@ -83,9 +85,32 @@ class YamlFileLoader extends FileLoader
$attributeMetadata->setMaxDepth($data['max_depth']);
}
if (isset($data['serialized_name'])) {
if (!\is_string($data['serialized_name']) || empty($data['serialized_name'])) {
throw new MappingException(sprintf('The "serialized_name" value must be a non-empty string in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName()));
}
$attributeMetadata->setSerializedName($data['serialized_name']);
}
}
}
if (isset($yaml['discriminator_map'])) {
if (!isset($yaml['discriminator_map']['type_property'])) {
throw new MappingException(sprintf('The "type_property" key must be set for the discriminator map of the class "%s" in "%s".', $classMetadata->getName(), $this->file));
}
if (!isset($yaml['discriminator_map']['mapping'])) {
throw new MappingException(sprintf('The "mapping" key must be set for the discriminator map of the class "%s" in "%s".', $classMetadata->getName(), $this->file));
}
$classMetadata->setClassDiscriminatorMapping(new ClassDiscriminatorMapping(
$yaml['discriminator_map']['type_property'],
$yaml['discriminator_map']['mapping']
));
}
return true;
}
@@ -103,7 +128,7 @@ class YamlFileLoader extends FileLoader
return array_keys($this->classes);
}
private function getClassesFromYaml()
private function getClassesFromYaml(): array
{
if (!stream_is_local($this->file)) {
throw new MappingException(sprintf('This is not a local file "%s".', $this->file));
@@ -113,7 +138,7 @@ class YamlFileLoader extends FileLoader
$this->yamlParser = new Parser();
}
$classes = $this->yamlParser->parseFile($this->file);
$classes = $this->yamlParser->parseFile($this->file, Yaml::PARSE_CONSTANT);
if (empty($classes)) {
return [];
@@ -8,7 +8,7 @@
<xsd:annotation>
<xsd:documentation><![CDATA[
Symfony Serializer Mapping Schema, version 1.0
Authors: Kévin Dunglas
Authors: Kévin Dunglas, Samuel Roze
A serializer mapping connects attributes with serialization groups.
]]></xsd:documentation>
@@ -37,10 +37,23 @@
</xsd:annotation>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="attribute" type="attribute" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="discriminator-map" type="discriminator-map" />
</xsd:choice>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="discriminator-map">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="mapping" type="discriminator-map-mapping" maxOccurs="unbounded" />
</xsd:choice>
<xsd:attribute name="type-property" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="discriminator-map-mapping">
<xsd:attribute name="type" type="xsd:string" use="required" />
<xsd:attribute name="class" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="attribute">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -58,6 +71,13 @@
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="serialized-name">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1" />
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:schema>