1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace ApiPlatform\Core\Documentation; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Generates the API documentation. |
20
|
|
|
* |
21
|
|
|
* @author Amrouche Hamza <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class Documentation |
24
|
|
|
{ |
25
|
|
|
private $resourceNameCollection; |
26
|
|
|
private $info = []; |
27
|
|
|
private $mimeTypes = []; |
28
|
|
|
|
29
|
|
|
public function __construct(ResourceNameCollection $resourceNameCollection, array $info = [], array $formats = null) |
30
|
|
|
{ |
31
|
|
|
$this->resourceNameCollection = $resourceNameCollection; |
32
|
|
|
$this->info = $info; |
33
|
|
|
|
34
|
|
|
if (null === $formats) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
@trigger_error(sprintf('Passing a 5th parameter to the constructor of "%s" is deprecated since API Platform 2.5', __CLASS__), E_USER_DEPRECATED); |
39
|
|
|
|
40
|
|
|
foreach ($formats as $mimeTypes) { |
41
|
|
|
foreach ($mimeTypes as $mimeType) { |
42
|
|
|
$this->mimeTypes[] = $mimeType; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getMimeTypes(): array |
48
|
|
|
{ |
49
|
|
|
@trigger_error(sprintf('The method "%s" is deprecated since API Platform 2.5, use the "formats" attribute instead', __METHOD__), E_USER_DEPRECATED); |
50
|
|
|
|
51
|
|
|
return $this->mimeTypes; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getVersion(): string |
55
|
|
|
{ |
56
|
|
|
return $this->info['version'] ?? ''; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getDescription(): string |
60
|
|
|
{ |
61
|
|
|
return $this->info['description'] ?? ''; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getTitle(): string |
65
|
|
|
{ |
66
|
|
|
return $this->info['title'] ?? ''; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function getContact(): array |
70
|
|
|
{ |
71
|
|
|
return $this->info['contact'] ?? []; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getLicense(): array |
75
|
|
|
{ |
76
|
|
|
return $this->info['license'] ?? []; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getTermsOfService(): string |
80
|
|
|
{ |
81
|
|
|
return $this->info['termsOfService'] ?? ''; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function getResourceNameCollection(): ResourceNameCollection |
85
|
|
|
{ |
86
|
|
|
return $this->resourceNameCollection; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|