1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Chubbyphp\ApiSkeleton\Serialization; |
6
|
|
|
|
7
|
|
|
use Chubbyphp\Serialization\Link\LinkGeneratorInterface; |
8
|
|
|
use Chubbyphp\Serialization\Mapping\FieldMappingInterface; |
9
|
|
|
use Chubbyphp\Serialization\Mapping\LinkMapping; |
10
|
|
|
use Chubbyphp\Serialization\Mapping\LinkMappingInterface; |
11
|
|
|
use Chubbyphp\Serialization\Mapping\ObjectMappingInterface; |
12
|
|
|
use Chubbyphp\Serialization\Serializer\Link\CallbackLinkSerializer; |
13
|
|
|
use Chubbyphp\ApiSkeleton\Search\Index; |
14
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
15
|
|
|
|
16
|
|
|
final class IndexMapping implements ObjectMappingInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var LinkGeneratorInterface |
20
|
|
|
*/ |
21
|
|
|
private $linkGenerator; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param LinkGeneratorInterface $linkGenerator |
25
|
|
|
*/ |
26
|
5 |
|
public function __construct(LinkGeneratorInterface $linkGenerator) |
27
|
|
|
{ |
28
|
5 |
|
$this->linkGenerator = $linkGenerator; |
29
|
5 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
1 |
|
public function getClass(): string |
35
|
|
|
{ |
36
|
1 |
|
return Index::class; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
1 |
|
public function getType(): string |
43
|
|
|
{ |
44
|
1 |
|
return 'index'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return FieldMappingInterface[] |
49
|
|
|
*/ |
50
|
1 |
|
public function getFieldMappings(): array |
51
|
|
|
{ |
52
|
1 |
|
return []; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return FieldMappingInterface[] |
57
|
|
|
*/ |
58
|
1 |
|
public function getEmbeddedFieldMappings(): array |
59
|
|
|
{ |
60
|
1 |
|
return []; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return LinkMappingInterface[] |
65
|
|
|
*/ |
66
|
|
|
public function getLinkMappings(): array |
67
|
|
|
{ |
68
|
|
|
return [ |
69
|
1 |
|
new LinkMapping('self', new CallbackLinkSerializer(function (Request $request) { |
70
|
1 |
|
return $this->linkGenerator->generateLink($request, 'index'); |
71
|
1 |
|
})), |
72
|
1 |
|
new LinkMapping('courses', new CallbackLinkSerializer(function (Request $request) { |
73
|
1 |
|
return $this->linkGenerator->generateLink($request, 'course_search'); |
74
|
1 |
|
})), |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|