1 | <?php |
||
23 | class SwaggerStrategy implements DispersalStrategyInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $fallbackData = []; |
||
29 | |||
30 | /** |
||
31 | * |
||
32 | */ |
||
33 | private $document; |
||
34 | |||
35 | /** |
||
36 | * constructor |
||
37 | * |
||
38 | * @param Document $document Swagger document parser |
||
39 | */ |
||
40 | 4 | public function __construct(Document $document) |
|
44 | |||
45 | /** |
||
46 | * process data |
||
47 | * |
||
48 | * @param string $input JSON information about the swagger service. |
||
49 | * @param array $fallbackData Set of information to be registered in case the swagger info is not complete. |
||
50 | * |
||
51 | * @return ApiDefinition |
||
52 | */ |
||
53 | 2 | public function process($input, array $fallbackData = []) |
|
84 | |||
85 | /** |
||
86 | * is input data valid json |
||
87 | * |
||
88 | * @param string $input json string |
||
89 | * |
||
90 | * @return boolean |
||
91 | */ |
||
92 | 2 | public function supports($input) |
|
106 | |||
107 | /** |
||
108 | * decode a json string |
||
109 | * |
||
110 | * @param string $input json string |
||
111 | * @param bool $assoc Force the encoded result to be a hash. |
||
112 | * |
||
113 | * @return array|\stdClass |
||
114 | */ |
||
115 | 3 | private function decodeJson($input, $assoc = false) |
|
121 | |||
122 | /** |
||
123 | * set base values |
||
124 | * |
||
125 | * @param ApiDefinition $apiDef API definition |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | 1 | private function setBaseValues(ApiDefinition $apiDef) |
|
137 | |||
138 | /** |
||
139 | * get the schema |
||
140 | * |
||
141 | * @param OperationReference $service service endpoint |
||
142 | * |
||
143 | * @return \stdClass |
||
144 | */ |
||
145 | 1 | private function getServiceSchema($service) |
|
184 | |||
185 | /** |
||
186 | * resolve schema |
||
187 | * |
||
188 | * @param \stdClass $reference reference |
||
189 | * |
||
190 | * @return \stdClass |
||
191 | */ |
||
192 | 1 | private function resolveSchema($reference) |
|
220 | |||
221 | /** |
||
222 | * Sets the destination host for the api definition. |
||
223 | * |
||
224 | * @param ApiDefinition $apiDef Configuration for the swagger api to be recognized. |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | 1 | private function registerHost(ApiDefinition $apiDef) |
|
237 | |||
238 | /** |
||
239 | * Set of information to be used as default if not defined by the swagger configuration. |
||
240 | * |
||
241 | * @param array $fallbackData Set of default information (e.g. host) |
||
242 | * |
||
243 | * @return void |
||
244 | */ |
||
245 | 2 | private function registerFallbackData(array $fallbackData) |
|
253 | |||
254 | /** |
||
255 | * Normalizes the provided path. |
||
256 | * |
||
257 | * The idea is to consolidate endpoints for GET requests. |
||
258 | * |
||
259 | * <code> |
||
260 | * /my/path/ » /my/path |
||
261 | * /my/path/{id} » /my/path |
||
262 | * </code> |
||
263 | * |
||
264 | * @param string $path path to be normalized |
||
265 | * |
||
266 | * @return string |
||
267 | * |
||
268 | * @todo: determine how to treat endpoints with a variable within the path: /my/path/{id}/special |
||
269 | */ |
||
270 | 1 | private function normalizePath($path) |
|
274 | } |
||
275 |