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