• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15394724286

02 Jun 2025 02:19PM UTC coverage: 22.201% (+0.1%) from 22.062%
15394724286

push

github

soyuka
feat(elasticsearch): add support for v9 (#7180)

Co-authored-by: darthf1 <17253332+darthf1@users.noreply.github.com>

10888 of 49042 relevant lines covered (22.2%)

10.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

48.72
/src/Metadata/Extractor/XmlResourceExtractor.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\Metadata\Extractor;
15

16
use ApiPlatform\Elasticsearch\State\Options;
17
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
18
use ApiPlatform\Metadata\GetCollection;
19
use ApiPlatform\Metadata\HeaderParameter;
20
use ApiPlatform\Metadata\Post;
21
use ApiPlatform\Metadata\QueryParameter;
22
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
23
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
24
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
25
use ApiPlatform\OpenApi\Model\RequestBody;
26
use ApiPlatform\State\OptionsInterface;
27
use Symfony\Component\Config\Util\XmlUtils;
28
use Symfony\Component\WebLink\Link;
29

30
/**
31
 * Extracts an array of metadata from a list of XML files.
32
 *
33
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
34
 */
35
final class XmlResourceExtractor extends AbstractResourceExtractor
36
{
37
    use ResourceExtractorTrait;
38

39
    public const SCHEMA = __DIR__.'/schema/resources.xsd';
40

41
    /**
42
     * {@inheritdoc}
43
     */
44
    protected function extractPath(string $path): void
45
    {
46
        try {
47
            /** @var \SimpleXMLElement $xml */
48
            $xml = simplexml_import_dom(XmlUtils::loadFile($path, self::SCHEMA));
40✔
49
        } catch (\InvalidArgumentException $e) {
40✔
50
            // Ensure it's not a resource
51
            try {
52
                simplexml_import_dom(XmlUtils::loadFile($path, XmlPropertyExtractor::SCHEMA));
40✔
53
            } catch (\InvalidArgumentException) {
×
54
                throw new InvalidArgumentException(\sprintf('Error while parsing %s: %s', $path, $e->getMessage()), $e->getCode(), $e);
×
55
            }
56

57
            // It's a property: ignore error
58
            return;
40✔
59
        }
60

61
        foreach ($xml->resource as $resource) {
40✔
62
            $base = $this->buildExtendedBase($resource);
40✔
63
            $this->resources[$this->resolve((string) $resource['class'])][] = array_merge($base, [
40✔
64
                'operations' => $this->buildOperations($resource, $base),
40✔
65
                'graphQlOperations' => $this->buildGraphQlOperations($resource, $base),
40✔
66
            ]);
40✔
67
        }
68
    }
69

70
    private function buildExtendedBase(\SimpleXMLElement $resource): array
71
    {
72
        return array_merge($this->buildBase($resource), [
40✔
73
            'uriTemplate' => $this->phpize($resource, 'uriTemplate', 'string'),
40✔
74
            'routePrefix' => $this->phpize($resource, 'routePrefix', 'string'),
40✔
75
            'stateless' => $this->phpize($resource, 'stateless', 'bool'),
40✔
76
            'sunset' => $this->phpize($resource, 'sunset', 'string'),
40✔
77
            'acceptPatch' => $this->phpize($resource, 'acceptPatch', 'string'),
40✔
78
            'status' => $this->phpize($resource, 'status', 'integer'),
40✔
79
            'host' => $this->phpize($resource, 'host', 'string'),
40✔
80
            'condition' => $this->phpize($resource, 'condition', 'string'),
40✔
81
            'controller' => $this->phpize($resource, 'controller', 'string'),
40✔
82
            'types' => $this->buildArrayValue($resource, 'type'),
40✔
83
            'formats' => $this->buildFormats($resource, 'formats'),
40✔
84
            'inputFormats' => $this->buildFormats($resource, 'inputFormats'),
40✔
85
            'outputFormats' => $this->buildFormats($resource, 'outputFormats'),
40✔
86
            'uriVariables' => $this->buildUriVariables($resource),
40✔
87
            'defaults' => isset($resource->defaults->values) ? $this->buildValues($resource->defaults->values) : null,
40✔
88
            'requirements' => $this->buildRequirements($resource),
40✔
89
            'options' => isset($resource->options->values) ? $this->buildValues($resource->options->values) : null,
40✔
90
            'schemes' => $this->buildArrayValue($resource, 'scheme'),
40✔
91
            'cacheHeaders' => $this->buildCacheHeaders($resource),
40✔
92
            'hydraContext' => isset($resource->hydraContext->values) ? $this->buildValues($resource->hydraContext->values) : null,
40✔
93
            'openapi' => $this->buildOpenapi($resource),
40✔
94
            'paginationViaCursor' => $this->buildPaginationViaCursor($resource),
40✔
95
            'exceptionToStatus' => $this->buildExceptionToStatus($resource),
40✔
96
            'queryParameterValidationEnabled' => $this->phpize($resource, 'queryParameterValidationEnabled', 'bool'),
40✔
97
            'strictQueryParameterValidation' => $this->phpize($resource, 'strictQueryParameterValidation', 'bool'),
40✔
98
            'hideHydraOperation' => $this->phpize($resource, 'hideHydraOperation', 'bool'),
40✔
99
            'stateOptions' => $this->buildStateOptions($resource),
40✔
100
            'links' => $this->buildLinks($resource),
40✔
101
            'headers' => $this->buildHeaders($resource),
40✔
102
            'parameters' => $this->buildParameters($resource),
40✔
103
        ]);
40✔
104
    }
105

106
    private function buildBase(\SimpleXMLElement $resource): array
107
    {
108
        return [
40✔
109
            'shortName' => $this->phpize($resource, 'shortName', 'string'),
40✔
110
            'description' => $this->phpize($resource, 'description', 'string'),
40✔
111
            'urlGenerationStrategy' => $this->phpize($resource, 'urlGenerationStrategy', 'integer'),
40✔
112
            'deprecationReason' => $this->phpize($resource, 'deprecationReason', 'string'),
40✔
113
            'messenger' => $this->phpize($resource, 'messenger', 'bool|string'),
40✔
114
            'mercure' => $this->buildMercure($resource),
40✔
115
            'input' => $this->phpize($resource, 'input', 'bool|string'),
40✔
116
            'output' => $this->phpize($resource, 'output', 'bool|string'),
40✔
117
            'fetchPartial' => $this->phpize($resource, 'fetchPartial', 'bool'),
40✔
118
            'forceEager' => $this->phpize($resource, 'forceEager', 'bool'),
40✔
119
            'paginationClientEnabled' => $this->phpize($resource, 'paginationClientEnabled', 'bool'),
40✔
120
            'paginationClientItemsPerPage' => $this->phpize($resource, 'paginationClientItemsPerPage', 'bool'),
40✔
121
            'paginationClientPartial' => $this->phpize($resource, 'paginationClientPartial', 'bool'),
40✔
122
            'paginationEnabled' => $this->phpize($resource, 'paginationEnabled', 'bool'),
40✔
123
            'paginationFetchJoinCollection' => $this->phpize($resource, 'paginationFetchJoinCollection', 'bool'),
40✔
124
            'paginationUseOutputWalkers' => $this->phpize($resource, 'paginationUseOutputWalkers', 'bool'),
40✔
125
            'paginationItemsPerPage' => $this->phpize($resource, 'paginationItemsPerPage', 'integer'),
40✔
126
            'paginationMaximumItemsPerPage' => $this->phpize($resource, 'paginationMaximumItemsPerPage', 'integer'),
40✔
127
            'paginationPartial' => $this->phpize($resource, 'paginationPartial', 'bool'),
40✔
128
            'paginationType' => $this->phpize($resource, 'paginationType', 'string'),
40✔
129
            'processor' => $this->phpize($resource, 'processor', 'string'),
40✔
130
            'provider' => $this->phpize($resource, 'provider', 'string'),
40✔
131
            'security' => $this->phpize($resource, 'security', 'string'),
40✔
132
            'securityMessage' => $this->phpize($resource, 'securityMessage', 'string'),
40✔
133
            'securityPostDenormalize' => $this->phpize($resource, 'securityPostDenormalize', 'string'),
40✔
134
            'securityPostDenormalizeMessage' => $this->phpize($resource, 'securityPostDenormalizeMessage', 'string'),
40✔
135
            'securityPostValidation' => $this->phpize($resource, 'securityPostValidation', 'string'),
40✔
136
            'securityPostValidationMessage' => $this->phpize($resource, 'securityPostValidationMessage', 'string'),
40✔
137
            'normalizationContext' => isset($resource->normalizationContext->values) ? $this->buildValues($resource->normalizationContext->values) : null,
40✔
138
            'denormalizationContext' => isset($resource->denormalizationContext->values) ? $this->buildValues($resource->denormalizationContext->values) : null,
40✔
139
            'collectDenormalizationErrors' => $this->phpize($resource, 'collectDenormalizationErrors', 'bool'),
40✔
140
            'validationContext' => isset($resource->validationContext->values) ? $this->buildValues($resource->validationContext->values) : null,
40✔
141
            'filters' => $this->buildArrayValue($resource, 'filter'),
40✔
142
            'order' => isset($resource->order->values) ? $this->buildValues($resource->order->values) : null,
40✔
143
            'extraProperties' => $this->buildExtraProperties($resource, 'extraProperties'),
40✔
144
            'read' => $this->phpize($resource, 'read', 'bool'),
40✔
145
            'write' => $this->phpize($resource, 'write', 'bool'),
40✔
146
        ];
40✔
147
    }
148

149
    private function buildFormats(\SimpleXMLElement $resource, string $key): ?array
150
    {
151
        if (!isset($resource->{$key}->format)) {
40✔
152
            return null;
40✔
153
        }
154

155
        $data = [];
×
156
        foreach ($resource->{$key}->format as $format) {
×
157
            if (isset($format['name'])) {
×
158
                $data[(string) $format['name']] = (string) $format;
×
159
                continue;
×
160
            }
161

162
            $data[] = (string) $format;
×
163
        }
164

165
        return $data;
×
166
    }
167

168
    private function buildOpenapi(\SimpleXMLElement $resource): bool|OpenApiOperation|null
169
    {
170
        if (!isset($resource->openapi) && !isset($resource['openapi'])) {
40✔
171
            return null;
40✔
172
        }
173

174
        if (isset($resource['openapi']) && \in_array((string) $resource['openapi'], ['1', '0', 'true', 'false'], true)) {
×
175
            return $this->phpize($resource, 'openapi', 'bool');
×
176
        }
177

178
        $openapi = $resource->openapi;
×
179
        $data = [];
×
180
        $attributes = $openapi->attributes();
×
181
        foreach ($attributes as $attribute) {
×
182
            $data[$attribute->getName()] = $this->phpize($attributes, 'deprecated', 'deprecated' === $attribute->getName() ? 'bool' : 'string');
×
183
        }
184

185
        $data['tags'] = $this->buildArrayValue($resource, 'tag');
×
186

187
        if (isset($openapi->responses->response)) {
×
188
            foreach ($openapi->responses->response as $response) {
×
189
                $data['responses'][(string) $response->attributes()->status] = [
×
190
                    'description' => $this->phpize($response, 'description', 'string'),
×
191
                    'content' => isset($response->content->values) ? $this->buildValues($response->content->values) : null,
×
192
                    'headers' => isset($response->headers->values) ? $this->buildValues($response->headers->values) : null,
×
193
                    'links' => isset($response->links->values) ? $this->buildValues($response->links->values) : null,
×
194
                ];
×
195
            }
196
        }
197

198
        $data['externalDocs'] = isset($openapi->externalDocs) ? new ExternalDocumentation(
×
199
            description: $this->phpize($resource, 'description', 'string'),
×
200
            url: $this->phpize($resource, 'url', 'string'),
×
201
        ) : null;
×
202

203
        if (isset($openapi->parameters->parameter)) {
×
204
            foreach ($openapi->parameters->parameter as $parameter) {
×
205
                $data['parameters'][(string) $parameter->attributes()->name] = new OpenApiParameter(
×
206
                    name: $this->phpize($parameter, 'name', 'string'),
×
207
                    in: $this->phpize($parameter, 'in', 'string'),
×
208
                    description: $this->phpize($parameter, 'description', 'string'),
×
209
                    required: $this->phpize($parameter, 'required', 'bool'),
×
210
                    deprecated: $this->phpize($parameter, 'deprecated', 'bool'),
×
211
                    allowEmptyValue: $this->phpize($parameter, 'allowEmptyValue', 'bool'),
×
212
                    schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null,
×
213
                    style: $this->phpize($parameter, 'style', 'string'),
×
214
                    explode: $this->phpize($parameter, 'explode', 'bool'),
×
215
                    allowReserved: $this->phpize($parameter, 'allowReserved', 'bool'),
×
216
                    example: $this->phpize($parameter, 'example', 'string'),
×
217
                    examples: isset($parameter->examples->values) ? new \ArrayObject($this->buildValues($parameter->examples->values)) : null,
×
218
                    content: isset($parameter->content->values) ? new \ArrayObject($this->buildValues($parameter->content->values)) : null,
×
219
                );
×
220
            }
221
        }
222
        $data['requestBody'] = isset($openapi->requestBody) ? new RequestBody(
×
223
            description: $this->phpize($openapi->requestBody, 'description', 'string'),
×
224
            content: isset($openapi->requestBody->content->values) ? new \ArrayObject($this->buildValues($openapi->requestBody->content->values)) : null,
×
225
            required: $this->phpize($openapi->requestBody, 'required', 'bool'),
×
226
        ) : null;
×
227

228
        $data['callbacks'] = isset($openapi->callbacks->values) ? new \ArrayObject($this->buildValues($openapi->callbacks->values)) : null;
×
229

230
        $data['security'] = isset($openapi->security->values) ? $this->buildValues($openapi->security->values) : null;
×
231

232
        if (isset($openapi->servers->server)) {
×
233
            foreach ($openapi->servers->server as $server) {
×
234
                $data['servers'][] = [
×
235
                    'description' => $this->phpize($server, 'description', 'string'),
×
236
                    'url' => $this->phpize($server, 'url', 'string'),
×
237
                    'variables' => isset($server->variables->values) ? $this->buildValues($server->variables->values) : null,
×
238
                ];
×
239
            }
240
        }
241

242
        $data['extensionProperties'] = isset($openapi->extensionProperties->values) ? $this->buildValues($openapi->extensionProperties->values) : null;
×
243

244
        foreach ($data as $key => $value) {
×
245
            if (null === $value) {
×
246
                unset($data[$key]);
×
247
            }
248
        }
249

250
        return new OpenApiOperation(...$data);
×
251
    }
252

253
    private function buildUriVariables(\SimpleXMLElement $resource): ?array
254
    {
255
        if (!isset($resource->uriVariables->uriVariable)) {
40✔
256
            return null;
40✔
257
        }
258

259
        $uriVariables = [];
40✔
260
        foreach ($resource->uriVariables->uriVariable as $data) {
40✔
261
            $parameterName = (string) $data['parameterName'];
40✔
262
            if (1 === (null === $data->attributes() ? 0 : \count($data->attributes()))) {
40✔
263
                $uriVariables[$parameterName] = $parameterName;
40✔
264
                continue;
40✔
265
            }
266

267
            if ($fromProperty = $this->phpize($data, 'fromProperty', 'string')) {
40✔
268
                $uriVariables[$parameterName]['from_property'] = $fromProperty;
×
269
            }
270
            if ($toProperty = $this->phpize($data, 'toProperty', 'string')) {
40✔
271
                $uriVariables[$parameterName]['to_property'] = $toProperty;
40✔
272
            }
273
            if ($fromClass = $this->resolve($this->phpize($data, 'fromClass', 'string'))) {
40✔
274
                $uriVariables[$parameterName]['from_class'] = $fromClass;
40✔
275
            }
276
            if ($toClass = $this->resolve($this->phpize($data, 'toClass', 'string'))) {
40✔
277
                $uriVariables[$parameterName]['to_class'] = $toClass;
×
278
            }
279
            if (isset($data->identifiers->values)) {
40✔
280
                $uriVariables[$parameterName]['identifiers'] = $this->buildValues($data->identifiers->values);
×
281
            }
282
            if (null !== ($compositeIdentifier = $this->phpize($data, 'compositeIdentifier', 'bool'))) {
40✔
283
                $uriVariables[$parameterName]['composite_identifier'] = $compositeIdentifier;
×
284
            }
285
        }
286

287
        return $uriVariables;
40✔
288
    }
289

290
    private function buildCacheHeaders(\SimpleXMLElement $resource): ?array
291
    {
292
        if (!isset($resource->cacheHeaders->cacheHeader)) {
40✔
293
            return null;
40✔
294
        }
295

296
        $data = [];
×
297
        foreach ($resource->cacheHeaders->cacheHeader as $cacheHeader) {
×
298
            if (isset($cacheHeader->values->value)) {
×
299
                $data[(string) $cacheHeader['name']] = $this->buildValues($cacheHeader->values);
×
300
                continue;
×
301
            }
302

303
            $data[(string) $cacheHeader['name']] = XmlUtils::phpize((string) $cacheHeader);
×
304
        }
305

306
        return $data;
×
307
    }
308

309
    private function buildRequirements(\SimpleXMLElement $resource): ?array
310
    {
311
        if (!isset($resource->requirements->requirement)) {
40✔
312
            return null;
40✔
313
        }
314

315
        $data = [];
×
316
        foreach ($resource->requirements->requirement as $requirement) {
×
317
            $data[(string) $requirement->attributes()->property] = (string) $requirement;
×
318
        }
319

320
        return $data;
×
321
    }
322

323
    private function buildMercure(\SimpleXMLElement $resource): array|bool|null
324
    {
325
        if (!isset($resource->mercure)) {
40✔
326
            return null;
40✔
327
        }
328

329
        if (null !== $resource->mercure->attributes()->private) {
×
330
            return ['private' => $this->phpize($resource->mercure->attributes(), 'private', 'bool')];
×
331
        }
332

333
        return true;
×
334
    }
335

336
    private function buildPaginationViaCursor(\SimpleXMLElement $resource): ?array
337
    {
338
        if (!isset($resource->paginationViaCursor->paginationField)) {
40✔
339
            return null;
40✔
340
        }
341

342
        $data = [];
×
343
        foreach ($resource->paginationViaCursor->paginationField as $paginationField) {
×
344
            $data[(string) $paginationField['field']] = (string) $paginationField['direction'];
×
345
        }
346

347
        return $data;
×
348
    }
349

350
    private function buildExceptionToStatus(\SimpleXMLElement $resource): ?array
351
    {
352
        if (!isset($resource->exceptionToStatus->exception)) {
40✔
353
            return null;
40✔
354
        }
355

356
        $data = [];
×
357
        foreach ($resource->exceptionToStatus->exception as $exception) {
×
358
            $data[(string) $exception['class']] = (int) $exception['statusCode'];
×
359
        }
360

361
        return $data;
×
362
    }
363

364
    private function buildExtraProperties(\SimpleXMLElement $resource, ?string $key = null): ?array
365
    {
366
        if (null !== $key) {
40✔
367
            if (!isset($resource->{$key})) {
40✔
368
                return null;
40✔
369
            }
370

371
            $resource = $resource->{$key};
×
372
        }
373

374
        return $this->buildValues($resource->values);
×
375
    }
376

377
    private function buildOperations(\SimpleXMLElement $resource, array $root): ?array
378
    {
379
        if (!isset($resource->operations->operation)) {
40✔
380
            return null;
40✔
381
        }
382

383
        $data = [];
40✔
384
        foreach ($resource->operations->operation as $operation) {
40✔
385
            $datum = $this->buildExtendedBase($operation);
40✔
386
            foreach ($datum as $key => $value) {
40✔
387
                if (null === $value) {
40✔
388
                    $datum[$key] = $root[$key];
40✔
389
                }
390
            }
391

392
            if (\in_array((string) $operation['class'], [GetCollection::class, Post::class], true)) {
40✔
393
                $datum['itemUriTemplate'] = $this->phpize($operation, 'itemUriTemplate', 'string');
40✔
394
            } elseif (isset($operation['itemUriTemplate'])) {
40✔
395
                throw new InvalidArgumentException(\sprintf('"itemUriTemplate" option is not allowed on a %s operation.', $operation['class']));
×
396
            }
397

398
            $data[] = array_merge($datum, [
40✔
399
                'collection' => $this->phpize($operation, 'collection', 'bool'),
40✔
400
                'class' => (string) $operation['class'],
40✔
401
                'method' => $this->phpize($operation, 'method', 'string'),
40✔
402
                'read' => $this->phpize($operation, 'read', 'bool'),
40✔
403
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
40✔
404
                'validate' => $this->phpize($operation, 'validate', 'bool'),
40✔
405
                'write' => $this->phpize($operation, 'write', 'bool'),
40✔
406
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
40✔
407
                'queryParameterValidate' => $this->phpize($operation, 'queryParameterValidate', 'bool'),
40✔
408
                'priority' => $this->phpize($operation, 'priority', 'integer'),
40✔
409
                'name' => $this->phpize($operation, 'name', 'string'),
40✔
410
                'routeName' => $this->phpize($operation, 'routeName', 'string'),
40✔
411
            ]);
40✔
412
        }
413

414
        return $data;
40✔
415
    }
416

417
    private function buildGraphQlOperations(\SimpleXMLElement $resource, array $root): ?array
418
    {
419
        if (!isset($resource->graphQlOperations->graphQlOperation)) {
40✔
420
            return null;
40✔
421
        }
422

423
        $data = [];
×
424
        foreach ($resource->graphQlOperations->graphQlOperation as $operation) {
×
425
            $datum = $this->buildBase($operation);
×
426
            foreach ($datum as $key => $value) {
×
427
                if (null === $value) {
×
428
                    $datum[$key] = $root[$key];
×
429
                }
430
            }
431

432
            $data[] = array_merge($datum, [
×
433
                'resolver' => $this->phpize($operation, 'resolver', 'string'),
×
434
                'args' => $this->buildArgs($operation),
×
435
                'extraArgs' => $this->buildExtraArgs($operation),
×
436
                'class' => (string) $operation['class'],
×
437
                'read' => $this->phpize($operation, 'read', 'bool'),
×
438
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
439
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
440
                'write' => $this->phpize($operation, 'write', 'bool'),
×
441
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
442
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
443
                'name' => $this->phpize($operation, 'name', 'string'),
×
444
            ]);
×
445
        }
446

447
        return $data;
×
448
    }
449

450
    private function buildStateOptions(\SimpleXMLElement $resource): ?OptionsInterface
451
    {
452
        $stateOptions = $resource->stateOptions ?? null;
40✔
453
        if (!$stateOptions) {
40✔
454
            return null;
40✔
455
        }
456
        $elasticsearchOptions = $stateOptions->elasticsearchOptions ?? null;
×
457
        if ($elasticsearchOptions) {
×
458
            if (class_exists(Options::class)) {
×
459
                return new Options(
×
460
                    isset($elasticsearchOptions['index']) ? (string) $elasticsearchOptions['index'] : null,
×
461
                );
×
462
            }
463
        }
464

465
        return null;
×
466
    }
467

468
    /**
469
     * @return Link[]
470
     */
471
    private function buildLinks(\SimpleXMLElement $resource): ?array
472
    {
473
        if (!$resource->links) {
40✔
474
            return null;
40✔
475
        }
476

477
        $links = [];
×
478
        foreach ($resource->links as $link) {
×
479
            $links[] = new Link(rel: (string) $link->link->attributes()->rel, href: (string) $link->link->attributes()->href);
×
480
        }
481

482
        return $links;
×
483
    }
484

485
    /**
486
     * @return array<string, string>
487
     */
488
    private function buildHeaders(\SimpleXMLElement $resource): ?array
489
    {
490
        if (!$resource->headers) {
40✔
491
            return null;
40✔
492
        }
493

494
        $headers = [];
×
495
        foreach ($resource->headers as $header) {
×
496
            $headers[(string) $header->header->attributes()->key] = (string) $header->header->attributes()->value;
×
497
        }
498

499
        return $headers;
×
500
    }
501

502
    /**
503
     * @return array<string, \ApiPlatform\Metadata\Parameter>
504
     */
505
    private function buildParameters(\SimpleXMLElement $resource): ?array
506
    {
507
        if (!$resource->parameters) {
40✔
508
            return null;
40✔
509
        }
510

511
        $parameters = [];
×
512
        foreach ($resource->parameters->parameter as $parameter) {
×
513
            $key = (string) $parameter->attributes()->key;
×
514
            $cl = ('header' === (string) $parameter->attributes()->in) ? HeaderParameter::class : QueryParameter::class;
×
515
            $parameters[$key] = new $cl(
×
516
                key: $key,
×
517
                required: $this->phpize($parameter, 'required', 'bool'),
×
518
                schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null,
×
519
                openApi: isset($parameter->openapi) ? new OpenApiParameter(
×
520
                    name: $this->phpize($parameter->openapi, 'name', 'string'),
×
521
                    in: $this->phpize($parameter->openapi, 'in', 'string'),
×
522
                    description: $this->phpize($parameter->openapi, 'description', 'string'),
×
523
                    required: $this->phpize($parameter->openapi, 'required', 'bool'),
×
524
                    deprecated: $this->phpize($parameter->openapi, 'deprecated', 'bool'),
×
525
                    allowEmptyValue: $this->phpize($parameter->openapi, 'allowEmptyValue', 'bool'),
×
526
                    schema: isset($parameter->openapi->schema->values) ? $this->buildValues($parameter->openapi->schema->values) : null,
×
527
                    style: $this->phpize($parameter->openapi, 'style', 'string'),
×
528
                    explode: $this->phpize($parameter->openapi, 'explode', 'bool'),
×
529
                    allowReserved: $this->phpize($parameter->openapi, 'allowReserved', 'bool'),
×
530
                    example: $this->phpize($parameter->openapi, 'example', 'string'),
×
531
                    examples: isset($parameter->openapi->examples->values) ? new \ArrayObject($this->buildValues($parameter->openapi->examples->values)) : null,
×
532
                    content: isset($parameter->openapi->content->values) ? new \ArrayObject($this->buildValues($parameter->openapi->content->values)) : null,
×
533
                ) : null,
×
534
                provider: $this->phpize($parameter, 'provider', 'string'),
×
535
                filter: $this->phpize($parameter, 'filter', 'string'),
×
536
                property: $this->phpize($parameter, 'property', 'string'),
×
537
                description: $this->phpize($parameter, 'description', 'string'),
×
538
                priority: $this->phpize($parameter, 'priority', 'integer'),
×
539
                extraProperties: $this->buildExtraProperties($parameter, 'extraProperties') ?? [],
×
540
            );
×
541
        }
542

543
        return $parameters;
×
544
    }
545
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc