|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Test\Stub\DataAbstractionLayer; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Test\Cart\Promotion\Helpers\Fakes\FakeConnection; |
|
6
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\FieldAccessorBuilder\DefaultFieldAccessorBuilder; |
|
7
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\FieldAccessorBuilder\FieldAccessorBuilderInterface; |
|
8
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry; |
|
9
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition; |
|
10
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\BoolFieldSerializer; |
|
11
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\CreatedAtFieldSerializer; |
|
12
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\CustomFieldsSerializer; |
|
13
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\FieldSerializerInterface; |
|
14
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\FkFieldSerializer; |
|
15
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\FloatFieldSerializer; |
|
16
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\IdFieldSerializer; |
|
17
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\IntFieldSerializer; |
|
18
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\JsonFieldSerializer; |
|
19
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\ManyToManyAssociationFieldSerializer; |
|
20
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\ManyToOneAssociationFieldSerializer; |
|
21
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\OneToManyAssociationFieldSerializer; |
|
22
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\OneToOneAssociationFieldSerializer; |
|
23
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\StringFieldSerializer; |
|
24
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\UpdatedAtFieldSerializer; |
|
25
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Write\EntityWriteGatewayInterface; |
|
26
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Write\WriteCommandExtractor; |
|
27
|
|
|
use Shopware\Core\Framework\Util\HtmlSanitizer; |
|
28
|
|
|
use Shopware\Core\System\CustomField\CustomFieldService; |
|
29
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
30
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @final |
|
34
|
|
|
*/ |
|
35
|
|
|
class StaticDefinitionInstanceRegistry extends DefinitionInstanceRegistry |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @var FieldSerializerInterface[] |
|
39
|
|
|
*/ |
|
40
|
|
|
private array $serializers; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param array<int|string, class-string<EntityDefinition>|EntityDefinition> $registeredDefinitions |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
array $registeredDefinitions, |
|
47
|
|
|
private readonly ValidatorInterface $validator, |
|
48
|
|
|
private readonly EntityWriteGatewayInterface $entityWriteGateway |
|
49
|
|
|
) { |
|
50
|
|
|
parent::__construct(new ContainerBuilder(), [], []); |
|
51
|
|
|
|
|
52
|
|
|
$this->setUpSerializers(); |
|
53
|
|
|
|
|
54
|
|
|
foreach ($registeredDefinitions as $serviceId => $definition) { |
|
55
|
|
|
$this->register( |
|
56
|
|
|
$definition instanceof EntityDefinition ? $definition : new $definition(), |
|
57
|
|
|
\is_string($serviceId) ? $serviceId : null |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function getSerializer(string $serializerClass): FieldSerializerInterface |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->serializers[$serializerClass]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getAccessorBuilder(string $accessorBuilderClass): FieldAccessorBuilderInterface |
|
68
|
|
|
{ |
|
69
|
|
|
return new DefaultFieldAccessorBuilder(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function setUpSerializers(): void |
|
73
|
|
|
{ |
|
74
|
|
|
$this->serializers = [ |
|
75
|
|
|
IdFieldSerializer::class => new IdFieldSerializer($this->validator, $this), |
|
76
|
|
|
FkFieldSerializer::class => new FkFieldSerializer($this->validator, $this), |
|
77
|
|
|
StringFieldSerializer::class => new StringFieldSerializer($this->validator, $this, new HtmlSanitizer()), |
|
78
|
|
|
IntFieldSerializer::class => new IntFieldSerializer($this->validator, $this), |
|
79
|
|
|
FloatFieldSerializer::class => new FloatFieldSerializer($this->validator, $this), |
|
80
|
|
|
BoolFieldSerializer::class => new BoolFieldSerializer($this->validator, $this), |
|
81
|
|
|
JsonFieldSerializer::class => new JsonFieldSerializer($this->validator, $this), |
|
82
|
|
|
CreatedAtFieldSerializer::class => new CreatedAtFieldSerializer($this->validator, $this), |
|
83
|
|
|
UpdatedAtFieldSerializer::class => new UpdatedAtFieldSerializer($this->validator, $this), |
|
84
|
|
|
CustomFieldsSerializer::class => new CustomFieldsSerializer( |
|
85
|
|
|
$this, |
|
86
|
|
|
$this->validator, |
|
87
|
|
|
new CustomFieldService(new FakeConnection([['foo', 'int']])) |
|
88
|
|
|
), |
|
89
|
|
|
ManyToManyAssociationFieldSerializer::class => new ManyToManyAssociationFieldSerializer( |
|
90
|
|
|
new WriteCommandExtractor($this->entityWriteGateway), |
|
91
|
|
|
), |
|
92
|
|
|
ManyToOneAssociationFieldSerializer::class => new ManyToOneAssociationFieldSerializer( |
|
93
|
|
|
new WriteCommandExtractor($this->entityWriteGateway), |
|
94
|
|
|
), |
|
95
|
|
|
OneToManyAssociationFieldSerializer::class => new OneToManyAssociationFieldSerializer( |
|
96
|
|
|
new WriteCommandExtractor($this->entityWriteGateway), |
|
97
|
|
|
), |
|
98
|
|
|
OneToOneAssociationFieldSerializer::class => new OneToOneAssociationFieldSerializer( |
|
99
|
|
|
new WriteCommandExtractor($this->entityWriteGateway), |
|
100
|
|
|
), |
|
101
|
|
|
]; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|