1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace W2w\Lib\Apie\Plugins\PrimaryKey; |
5
|
|
|
|
6
|
|
|
use erasys\OpenApi\Spec\v3\Schema; |
7
|
|
|
use W2w\Lib\Apie\Core\Resources\ApiResources; |
8
|
|
|
use W2w\Lib\Apie\Exceptions\BadConfigurationException; |
9
|
|
|
use W2w\Lib\Apie\OpenApiSchema\Factories\SchemaFactory; |
10
|
|
|
use W2w\Lib\Apie\PluginInterfaces\ApieAwareInterface; |
11
|
|
|
use W2w\Lib\Apie\PluginInterfaces\ApieAwareTrait; |
12
|
|
|
use W2w\Lib\Apie\PluginInterfaces\NormalizerProviderInterface; |
13
|
|
|
use W2w\Lib\Apie\PluginInterfaces\SchemaProviderInterface; |
14
|
|
|
use W2w\Lib\Apie\Plugins\PrimaryKey\Normalizers\ApiePrimaryKeyNormalizer; |
15
|
|
|
use W2w\Lib\Apie\Plugins\PrimaryKey\Normalizers\PrimaryKeyReferenceNormalizer; |
16
|
|
|
use W2w\Lib\Apie\Plugins\PrimaryKey\Schema\ApiResourceLinkSchemaBuilder; |
17
|
|
|
use W2w\Lib\Apie\Plugins\PrimaryKey\ValueObjects\PrimaryKeyReference; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Core Apie plugin to map api resources to string urls for child objects. |
21
|
|
|
*/ |
22
|
|
|
class PrimaryKeyPlugin implements NormalizerProviderInterface, ApieAwareInterface, SchemaProviderInterface |
23
|
|
|
{ |
24
|
|
|
use ApieAwareTrait; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* {@inheritDoc} |
28
|
|
|
*/ |
29
|
|
|
public function getNormalizers(): array |
30
|
|
|
{ |
31
|
|
|
$primaryKeyNormalizer = new ApiePrimaryKeyNormalizer( |
32
|
|
|
new ApiResources($this->getApie()->getResources()), |
33
|
|
|
$this->getApie()->getIdentifierExtractor(), |
34
|
|
|
$this->getApie()->getApiResourceMetadataFactory(), |
35
|
|
|
$this->getApie()->getClassResourceConverter(), |
36
|
|
|
$this->getApie()->getFrameworkConnection() |
37
|
|
|
); |
38
|
|
|
return [ |
|
|
|
|
39
|
|
|
new PrimaryKeyReferenceNormalizer(), |
40
|
|
|
$primaryKeyNormalizer, |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritDoc} |
46
|
|
|
*/ |
47
|
|
|
public function getDefinedStaticData(): array |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
|
|
PrimaryKeyReference::class => SchemaFactory::createStringSchema('path'), |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritDoc} |
56
|
|
|
*/ |
57
|
|
|
public function getDynamicSchemaLogic(): array |
58
|
|
|
{ |
59
|
|
|
$res = []; |
60
|
|
|
$identifierExtractor = $this->getApie()->getIdentifierExtractor(); |
61
|
|
|
$builder = new ApiResourceLinkSchemaBuilder($this->getApie()->getFrameworkConnection()); |
62
|
|
|
foreach ($this->getApie()->getResources() as $resource) { |
63
|
|
|
if (null !== $identifierExtractor->getIdentifierKeyOfClass($resource)) { |
64
|
|
|
$res[$resource] = $builder; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
return $res; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|