|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the "elao/api-resources-metadata" package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) 2016 Elao |
|
7
|
|
|
* |
|
8
|
|
|
* @author Elao <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Elao\ApiResourcesMetadata\Bridge\Nelmio\ApiDoc\Extractor; |
|
12
|
|
|
|
|
13
|
|
|
use Elao\ApiResourcesMetadata\Resource\ResourceIndex; |
|
14
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
|
15
|
|
|
use Nelmio\ApiDocBundle\DataTypes; |
|
16
|
|
|
use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor as NelmioApiDocExtractor; |
|
17
|
|
|
use Nelmio\ApiDocBundle\Parser\ParserInterface; |
|
18
|
|
|
use Symfony\Component\Routing\Route; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Decorates an existing NelmioApiDocExtractor instance. |
|
22
|
|
|
*/ |
|
23
|
|
|
class ApiDocExtractor extends NelmioApiDocExtractor |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var NelmioApiDocExtractor */ |
|
26
|
|
|
private $innerApiDocExtractor; |
|
27
|
|
|
|
|
28
|
|
|
/** @var ResourceIndex */ |
|
29
|
|
|
private $resourceIndex; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(NelmioApiDocExtractor $innerApiDocExtractor, ResourceIndex $resourceIndex) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->innerApiDocExtractor = $innerApiDocExtractor; |
|
34
|
|
|
$this->resourceIndex = $resourceIndex; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
protected function generateHumanReadableType($actualType, $subType) |
|
38
|
|
|
{ |
|
39
|
|
|
if (!class_exists($subType) && $this->resourceIndex->has($subType)) { |
|
40
|
|
|
$subType = $this->resourceIndex->getResourceClass($subType); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (null === $shortName = $this->getShortName($subType)) { |
|
44
|
|
|
return $this->innerApiDocExtractor->generateHumanReadableType($actualType, $subType); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if ($actualType == DataTypes::MODEL) { |
|
48
|
|
|
return sprintf('object (%s)', $shortName); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if ($actualType == DataTypes::COLLECTION) { |
|
52
|
|
|
return sprintf('array of objects (%s)', $shortName); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getRoutes() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->innerApiDocExtractor->getRoutes(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function all($view = ApiDoc::DEFAULT_VIEW) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->innerApiDocExtractor->all($view); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function extractAnnotations(array $routes, $view = ApiDoc::DEFAULT_VIEW) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->innerApiDocExtractor->extractAnnotations($routes, $view); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getReflectionMethod($controller) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->innerApiDocExtractor->getReflectionMethod($controller); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function get($controller, $route) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->innerApiDocExtractor->get($controller, $route); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function addParser(ParserInterface $parser) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->innerApiDocExtractor->addParser($parser); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function extractData(ApiDoc $annotation, Route $route, \ReflectionMethod $method) |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->innerApiDocExtractor->extractData($annotation, $route, $method); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
protected function normalizeClassParameter($input) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->innerApiDocExtractor->normalizeClassParameter($input); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
protected function mergeParameters($p1, $p2) |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->innerApiDocExtractor->mergeParameters($p1, $p2); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
protected function parseAnnotations(ApiDoc $annotation, Route $route, \ReflectionMethod $method) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->innerApiDocExtractor->parseAnnotations($annotation, $route, $method); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
protected function clearClasses($array) |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->innerApiDocExtractor->clearClasses($array); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
protected function generateHumanReadableTypes(array $array) |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->innerApiDocExtractor->generateHumanReadableTypes($array); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
private function getShortName(string $className) |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->resourceIndex->has($className) ? $this->resourceIndex->getShortName($className) : null; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|