Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Mapping/Factory/ClassMetadataFactoryCompiler.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Serializer\Mapping\Factory;
13
14 use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
15 use Symfony\Component\VarExporter\VarExporter;
16
17 trigger_deprecation('symfony/serializer', '7.4', 'The "%s" class is deprecated.', ClassMetadataFactoryCompiler::class);
18
19 /**
20 * @author Fabien Bourigault <[email protected]>
21 *
22 * @deprecated since Symfony 7.4
23 */
24 final class ClassMetadataFactoryCompiler
25 {
26 /**
27 * @param ClassMetadataInterface[] $classMetadatas
28 */
29 public function compile(array $classMetadatas): string
30 {
31 return <<<EOF
32 <?php
33
34 // This file has been auto-generated by the Symfony Serializer Component.
35
36 return [{$this->generateDeclaredClassMetadata($classMetadatas)}
37 ];
38 EOF;
39 }
40
41 /**
42 * @param ClassMetadataInterface[] $classMetadatas
43 */
44 private function generateDeclaredClassMetadata(array $classMetadatas): string
45 {
46 $compiled = '';
47
48 foreach ($classMetadatas as $classMetadata) {
49 $attributesMetadata = [];
50 foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) {
51 $attributesMetadata[$attributeMetadata->getName()] = [
52 $attributeMetadata->getGroups(),
53 $attributeMetadata->getMaxDepth(),
54 $attributeMetadata->getSerializedName(),
55 $attributeMetadata->getSerializedPath(),
56 ];
57 }
58
59 $classDiscriminatorMapping = $classMetadata->getClassDiscriminatorMapping() ? [
60 $classMetadata->getClassDiscriminatorMapping()->getTypeProperty(),
61 $classMetadata->getClassDiscriminatorMapping()->getTypesMapping(),
62 $classMetadata->getClassDiscriminatorMapping()->getDefaultType(),
63 ] : null;
64
65 $compiled .= \sprintf("\n'%s' => %s,", $classMetadata->getName(), VarExporter::export([
66 $attributesMetadata,
67 $classDiscriminatorMapping,
68 ]));
69 }
70
71 return $compiled;
72 }
73 }