1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace W2w\Lib\ApieDomainPlugin; |
5
|
|
|
|
6
|
|
|
use erasys\OpenApi\Spec\v3\Schema; |
7
|
|
|
use Pdp\Cache; |
8
|
|
|
use Pdp\CurlHttpClient; |
9
|
|
|
use Pdp\Domain; |
10
|
|
|
use Pdp\Manager; |
11
|
|
|
use Pdp\PublicSuffix; |
12
|
|
|
use Pdp\Rules; |
13
|
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
14
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
15
|
|
|
use W2w\Lib\Apie\PluginInterfaces\NormalizerProviderInterface; |
16
|
|
|
use W2w\Lib\Apie\PluginInterfaces\SchemaProviderInterface; |
17
|
|
|
use W2w\Lib\ApieDomainPlugin\Normalizers\DomainNormalizer; |
18
|
|
|
use W2w\Lib\ApieDomainPlugin\Normalizers\PublicSuffixNormalizer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Apie plugin to add support for Pdp\Domain. |
22
|
|
|
*/ |
23
|
|
|
class DomainPlugin implements SchemaProviderInterface, NormalizerProviderInterface |
24
|
|
|
{ |
25
|
|
|
private $rules; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Rules|null $rules |
29
|
|
|
*/ |
30
|
|
|
public function __construct(?Rules $rules = null) |
31
|
|
|
{ |
32
|
|
|
if (!$rules) { |
33
|
|
|
$manager = new Manager(new Cache(), new CurlHttpClient()); |
34
|
|
|
$rules = $manager->getRules(); |
35
|
|
|
} |
36
|
|
|
$this->rules = $rules; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return Schema[] |
41
|
|
|
*/ |
42
|
|
|
public function getDefinedStaticData(): array |
43
|
|
|
{ |
44
|
|
|
return [ |
45
|
|
|
Domain::class => new Schema(['type' => 'string', 'format' => 'domain', 'example' => 'example.nl', 'default' => 'example.nl']), |
46
|
|
|
PublicSuffix::class => new Schema(['type' => 'string', 'format' => 'tld', 'example' => 'nl', 'default' => 'nl']), |
47
|
|
|
]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return callable[] |
52
|
|
|
*/ |
53
|
|
|
public function getDynamicSchemaLogic(): array |
54
|
|
|
{ |
55
|
|
|
return []; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return NormalizerInterface[]|DenormalizerInterface[] |
60
|
|
|
*/ |
61
|
|
|
public function getNormalizers(): array |
62
|
|
|
{ |
63
|
|
|
return [new DomainNormalizer($this->rules), new PublicSuffixNormalizer($this->rules)]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|