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

api-platform / core / 19438754788

17 Nov 2025 05:34PM UTC coverage: 0.0%. Remained the same
19438754788

push

github

soyuka
Merge 4.2

0 of 95 new or added lines in 28 files covered. (0.0%)

19 existing lines in 18 files now uncovered.

0 of 57020 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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\Doctrine\Odm\State\Options as OdmOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options as OrmOptions;
18
use ApiPlatform\Elasticsearch\State\Options as ElasticsearchOptions;
19
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
20
use ApiPlatform\Metadata\GetCollection;
21
use ApiPlatform\Metadata\HeaderParameter;
22
use ApiPlatform\Metadata\Post;
23
use ApiPlatform\Metadata\QueryParameter;
24
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
25
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
26
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
27
use ApiPlatform\OpenApi\Model\RequestBody;
28
use ApiPlatform\OpenApi\Model\Response;
29
use ApiPlatform\State\OptionsInterface;
30
use Symfony\Component\Config\Util\XmlUtils;
31
use Symfony\Component\WebLink\Link;
32

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

42
    public const SCHEMA = __DIR__.'/schema/resources.xsd';
43

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

60
            // It's a property: ignore error
61
            return;
×
62
        }
63

64
        foreach ($xml->resource as $resource) {
×
65
            $base = $this->buildExtendedBase($resource);
×
66
            $this->resources[$this->resolve((string) $resource['class'])][] = array_merge($base, [
×
67
                'operations' => $this->buildOperations($resource, $base),
×
68
                'graphQlOperations' => $this->buildGraphQlOperations($resource, $base),
×
69
            ]);
×
70
        }
71
    }
72

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

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

154
    private function buildFormats(\SimpleXMLElement $resource, string $key): ?array
155
    {
156
        if (!isset($resource->{$key}->format)) {
×
157
            return null;
×
158
        }
159

160
        $data = [];
×
161
        foreach ($resource->{$key}->format as $format) {
×
162
            if (isset($format['name'])) {
×
163
                $data[(string) $format['name']] = (string) $format;
×
164
                continue;
×
165
            }
166

167
            $data[] = (string) $format;
×
168
        }
169

170
        return $data;
×
171
    }
172

173
    private function buildOpenapi(\SimpleXMLElement $resource): bool|OpenApiOperation|null
174
    {
175
        if (!isset($resource->openapi) && !isset($resource['openapi'])) {
×
176
            return null;
×
177
        }
178

179
        if (isset($resource['openapi']) && \in_array((string) $resource['openapi'], ['1', '0', 'true', 'false'], true)) {
×
180
            return $this->phpize($resource, 'openapi', 'bool');
×
181
        }
182

183
        $openapi = $resource->openapi;
×
184
        $data = [];
×
185
        $attributes = $openapi->attributes();
×
186

187
        /*
188
         * \SimpleXMLElement should not be read in an iteration because of a known bug in SimpleXML lib that resets the iterator
189
         * and leads to infinite loop
190
         * https://bugs.php.net/bug.php?id=55098
191
         * https://github.com/php/php-src/issues/12208
192
         * https://github.com/php/php-src/issues/12192
193
         *
194
         * attribute names are stored in an iteration and values are fetched in another one
195
         */
196
        $attributeNames = [];
×
197
        foreach ($attributes as $name => $attribute) {
×
198
            $attributeNames[] = $name;
×
199
        }
200

201
        foreach ($attributeNames as $attributeName) {
×
202
            $data[$attributeName] = $this->phpize($attributes, $attributeName, 'deprecated' === $attributeName ? 'bool' : 'string');
×
203
        }
204

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

207
        if (isset($openapi->responses->response)) {
×
208
            foreach ($openapi->responses->response as $response) {
×
209
                $data['responses'][(string) $response->attributes()->status] = new Response(
×
210
                    description: $this->phpize($response, 'description', 'string'),
×
211
                    content: isset($response->content->values) ? new \ArrayObject($this->buildValues($response->content->values)) : null,
×
212
                    headers: isset($response->headers->values) ? new \ArrayObject($this->buildValues($response->headers->values)) : null,
×
213
                    links: isset($response->links->values) ? new \ArrayObject($this->buildValues($response->links->values)) : null,
×
214
                );
×
215
            }
216
        }
217

218
        $data['externalDocs'] = isset($openapi->externalDocs) ? new ExternalDocumentation(
×
219
            description: $this->phpize($resource, 'description', 'string'),
×
220
            url: $this->phpize($resource, 'url', 'string'),
×
221
        ) : null;
×
222

223
        if (isset($openapi->parameters->parameter)) {
×
224
            foreach ($openapi->parameters->parameter as $parameter) {
×
225
                $data['parameters'][(string) $parameter->attributes()->name] = new OpenApiParameter(
×
226
                    name: $this->phpize($parameter, 'name', 'string'),
×
227
                    in: $this->phpize($parameter, 'in', 'string'),
×
228
                    description: $this->phpize($parameter, 'description', 'string'),
×
229
                    required: $this->phpize($parameter, 'required', 'bool'),
×
230
                    deprecated: $this->phpize($parameter, 'deprecated', 'bool', false),
×
231
                    allowEmptyValue: $this->phpize($parameter, 'allowEmptyValue', 'bool', null),
×
232
                    schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : [],
×
233
                    style: $this->phpize($parameter, 'style', 'string'),
×
234
                    explode: $this->phpize($parameter, 'explode', 'bool', false),
×
235
                    allowReserved: $this->phpize($parameter, 'allowReserved', 'bool', null),
×
236
                    example: $this->phpize($parameter, 'example', 'string'),
×
237
                    examples: isset($parameter->examples->values) ? new \ArrayObject($this->buildValues($parameter->examples->values)) : null,
×
238
                    content: isset($parameter->content->values) ? new \ArrayObject($this->buildValues($parameter->content->values)) : null,
×
239
                );
×
240
            }
241
        }
242
        $data['requestBody'] = isset($openapi->requestBody) ? new RequestBody(
×
243
            description: $this->phpize($openapi->requestBody, 'description', 'string'),
×
244
            content: isset($openapi->requestBody->content->values) ? new \ArrayObject($this->buildValues($openapi->requestBody->content->values)) : null,
×
245
            required: $this->phpize($openapi->requestBody, 'required', 'bool'),
×
246
        ) : null;
×
247

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

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

252
        if (isset($openapi->servers->server)) {
×
253
            foreach ($openapi->servers->server as $server) {
×
254
                $data['servers'][] = [
×
255
                    'description' => $this->phpize($server, 'description', 'string'),
×
256
                    'url' => $this->phpize($server, 'url', 'string'),
×
257
                    'variables' => isset($server->variables->values) ? $this->buildValues($server->variables->values) : null,
×
258
                ];
×
259
            }
260
        }
261

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

264
        foreach ($data as $key => $value) {
×
265
            if (null === $value) {
×
266
                unset($data[$key]);
×
267
            }
268
        }
269

270
        return new OpenApiOperation(...$data);
×
271
    }
272

273
    private function buildUriVariables(\SimpleXMLElement $resource): ?array
274
    {
275
        if (!isset($resource->uriVariables->uriVariable)) {
×
276
            return null;
×
277
        }
278

279
        $uriVariables = [];
×
280
        foreach ($resource->uriVariables->uriVariable as $data) {
×
281
            $parameterName = (string) $data['parameterName'];
×
282
            if (1 === (null === $data->attributes() ? 0 : \count($data->attributes()))) {
×
283
                $uriVariables[$parameterName] = $parameterName;
×
284
                continue;
×
285
            }
286

287
            if ($fromProperty = $this->phpize($data, 'fromProperty', 'string')) {
×
288
                $uriVariables[$parameterName]['from_property'] = $fromProperty;
×
289
            }
290
            if ($toProperty = $this->phpize($data, 'toProperty', 'string')) {
×
291
                $uriVariables[$parameterName]['to_property'] = $toProperty;
×
292
            }
293
            if ($fromClass = $this->resolve($this->phpize($data, 'fromClass', 'string'))) {
×
294
                $uriVariables[$parameterName]['from_class'] = $fromClass;
×
295
            }
296
            if ($toClass = $this->resolve($this->phpize($data, 'toClass', 'string'))) {
×
297
                $uriVariables[$parameterName]['to_class'] = $toClass;
×
298
            }
299
            if (isset($data->identifiers->values)) {
×
300
                $uriVariables[$parameterName]['identifiers'] = $this->buildValues($data->identifiers->values);
×
301
            }
302
            if (null !== ($compositeIdentifier = $this->phpize($data, 'compositeIdentifier', 'bool'))) {
×
303
                $uriVariables[$parameterName]['composite_identifier'] = $compositeIdentifier;
×
304
            }
305
        }
306

307
        return $uriVariables;
×
308
    }
309

310
    private function buildCacheHeaders(\SimpleXMLElement $resource): ?array
311
    {
312
        if (!isset($resource->cacheHeaders->cacheHeader)) {
×
313
            return null;
×
314
        }
315

316
        $data = [];
×
317
        foreach ($resource->cacheHeaders->cacheHeader as $cacheHeader) {
×
318
            if (isset($cacheHeader->values->value)) {
×
319
                $data[(string) $cacheHeader['name']] = $this->buildValues($cacheHeader->values);
×
320
                continue;
×
321
            }
322

323
            $data[(string) $cacheHeader['name']] = XmlUtils::phpize((string) $cacheHeader);
×
324
        }
325

326
        return $data;
×
327
    }
328

329
    private function buildRequirements(\SimpleXMLElement $resource): ?array
330
    {
331
        if (!isset($resource->requirements->requirement)) {
×
332
            return null;
×
333
        }
334

335
        $data = [];
×
336
        foreach ($resource->requirements->requirement as $requirement) {
×
337
            $data[(string) $requirement->attributes()->property] = (string) $requirement;
×
338
        }
339

340
        return $data;
×
341
    }
342

343
    private function buildMercure(\SimpleXMLElement $resource): array|bool|null
344
    {
345
        if (!isset($resource->mercure)) {
×
346
            return null;
×
347
        }
348

349
        if (null !== $resource->mercure->attributes()->private) {
×
350
            return ['private' => $this->phpize($resource->mercure->attributes(), 'private', 'bool')];
×
351
        }
352

353
        return true;
×
354
    }
355

356
    private function buildPaginationViaCursor(\SimpleXMLElement $resource): ?array
357
    {
358
        if (!isset($resource->paginationViaCursor->paginationField)) {
×
359
            return null;
×
360
        }
361

362
        $data = [];
×
363
        foreach ($resource->paginationViaCursor->paginationField as $paginationField) {
×
364
            $data[(string) $paginationField['field']] = (string) $paginationField['direction'];
×
365
        }
366

367
        return $data;
×
368
    }
369

370
    private function buildExceptionToStatus(\SimpleXMLElement $resource): ?array
371
    {
372
        if (!isset($resource->exceptionToStatus->exception)) {
×
373
            return null;
×
374
        }
375

376
        $data = [];
×
377
        foreach ($resource->exceptionToStatus->exception as $exception) {
×
378
            $data[(string) $exception['class']] = (int) $exception['statusCode'];
×
379
        }
380

381
        return $data;
×
382
    }
383

384
    private function buildExtraProperties(\SimpleXMLElement $resource, ?string $key = null): ?array
385
    {
386
        if (null !== $key) {
×
387
            if (!isset($resource->{$key})) {
×
388
                return null;
×
389
            }
390

391
            $resource = $resource->{$key};
×
392
        }
393

394
        return $this->buildValues($resource->values);
×
395
    }
396

397
    private function buildOperations(\SimpleXMLElement $resource, array $root): ?array
398
    {
399
        if (!isset($resource->operations->operation)) {
×
400
            return null;
×
401
        }
402

403
        $data = [];
×
404
        foreach ($resource->operations->operation as $operation) {
×
405
            $datum = $this->buildExtendedBase($operation);
×
406
            foreach ($datum as $key => $value) {
×
407
                if (null === $value) {
×
408
                    $datum[$key] = $root[$key];
×
409
                }
410
            }
411

412
            if (\in_array((string) $operation['class'], [GetCollection::class, Post::class], true)) {
×
413
                $datum['itemUriTemplate'] = $this->phpize($operation, 'itemUriTemplate', 'string');
×
414
            } elseif (isset($operation['itemUriTemplate'])) {
×
415
                throw new InvalidArgumentException(\sprintf('"itemUriTemplate" option is not allowed on a %s operation.', $operation['class']));
×
416
            }
417

418
            $data[] = array_merge($datum, [
×
419
                'collection' => $this->phpize($operation, 'collection', 'bool'),
×
420
                'class' => (string) $operation['class'],
×
421
                'method' => $this->phpize($operation, 'method', 'string'),
×
422
                'read' => $this->phpize($operation, 'read', 'bool'),
×
423
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
424
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
425
                'write' => $this->phpize($operation, 'write', 'bool'),
×
426
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
427
                'queryParameterValidate' => $this->phpize($operation, 'queryParameterValidate', 'bool'),
×
428
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
429
                'name' => $this->phpize($operation, 'name', 'string'),
×
430
                'routeName' => $this->phpize($operation, 'routeName', 'string'),
×
431
            ]);
×
432
        }
433

434
        return $data;
×
435
    }
436

437
    private function buildGraphQlOperations(\SimpleXMLElement $resource, array $root): ?array
438
    {
439
        if (!isset($resource->graphQlOperations->graphQlOperation)) {
×
440
            return null;
×
441
        }
442

443
        $data = [];
×
444
        foreach ($resource->graphQlOperations->graphQlOperation as $operation) {
×
445
            $datum = $this->buildBase($operation);
×
446
            foreach ($datum as $key => $value) {
×
447
                if (null === $value) {
×
448
                    $datum[$key] = $root[$key];
×
449
                }
450
            }
451

452
            $data[] = array_merge($datum, [
×
453
                'resolver' => $this->phpize($operation, 'resolver', 'string'),
×
454
                'args' => $this->buildArgs($operation),
×
455
                'extraArgs' => $this->buildExtraArgs($operation),
×
456
                'class' => (string) $operation['class'],
×
457
                'read' => $this->phpize($operation, 'read', 'bool'),
×
458
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
459
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
460
                'write' => $this->phpize($operation, 'write', 'bool'),
×
461
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
462
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
463
                'name' => $this->phpize($operation, 'name', 'string'),
×
464
            ]);
×
465
        }
466

467
        return $data;
×
468
    }
469

470
    private function buildStateOptions(\SimpleXMLElement $resource): ?OptionsInterface
471
    {
472
        $stateOptions = $resource->stateOptions ?? null;
×
473
        if (!$stateOptions) {
×
474
            return null;
×
475
        }
476

477
        if (isset($stateOptions->elasticsearchOptions) && class_exists(ElasticsearchOptions::class)) {
×
478
            return new ElasticsearchOptions(
×
479
                isset($stateOptions->elasticsearchOptions['index']) ? (string) $stateOptions->elasticsearchOptions['index'] : null,
×
480
            );
×
481
        }
482

483
        if (isset($stateOptions->doctrineOdmOptions) && class_exists(OdmOptions::class)) {
×
484
            return new OdmOptions(
×
485
                isset($stateOptions->doctrineOdmOptions['documentClass']) ? (string) $stateOptions->doctrineOdmOptions['documentClass'] : null,
×
486
            );
×
487
        }
488

489
        if (isset($stateOptions->doctrineOrmOptions) && class_exists(OrmOptions::class)) {
×
490
            return new OrmOptions(
×
491
                isset($stateOptions->doctrineOrmOptions['entityClass']) ? (string) $stateOptions->doctrineOrmOptions['entityClass'] : null,
×
492
            );
×
493
        }
494

495
        return null;
×
496
    }
497

498
    /**
499
     * @return Link[]
500
     */
501
    private function buildLinks(\SimpleXMLElement $resource): ?array
502
    {
503
        if (!$resource->links) {
×
504
            return null;
×
505
        }
506

507
        $links = [];
×
508
        foreach ($resource->links as $link) {
×
509
            $links[] = new Link(rel: (string) $link->link->attributes()->rel, href: (string) $link->link->attributes()->href);
×
510
        }
511

512
        return $links;
×
513
    }
514

515
    /**
516
     * @return array<string, string>
517
     */
518
    private function buildHeaders(\SimpleXMLElement $resource): ?array
519
    {
520
        if (!$resource->headers) {
×
521
            return null;
×
522
        }
523

524
        $headers = [];
×
525
        foreach ($resource->headers as $header) {
×
526
            $headers[(string) $header->header->attributes()->key] = (string) $header->header->attributes()->value;
×
527
        }
528

529
        return $headers;
×
530
    }
531

532
    /**
533
     * @return array<string, \ApiPlatform\Metadata\Parameter>
534
     */
535
    private function buildParameters(\SimpleXMLElement $resource): ?array
536
    {
537
        if (!$resource->parameters) {
×
538
            return null;
×
539
        }
540

541
        $parameters = [];
×
542
        foreach ($resource->parameters->parameter as $parameter) {
×
543
            $key = (string) $parameter->attributes()->key;
×
544
            $cl = ('header' === (string) $parameter->attributes()->in) ? HeaderParameter::class : QueryParameter::class;
×
545
            $parameters[$key] = new $cl(
×
546
                key: $key,
×
547
                required: $this->phpize($parameter, 'required', 'bool'),
×
548
                schema: isset($parameter->schema->values) ? $this->buildValues($parameter->schema->values) : null,
×
549
                openApi: isset($parameter->openapi) ? new OpenApiParameter(
×
550
                    name: $this->phpize($parameter->openapi, 'name', 'string'),
×
551
                    in: $this->phpize($parameter->openapi, 'in', 'string'),
×
552
                    description: $this->phpize($parameter->openapi, 'description', 'string'),
×
553
                    required: $this->phpize($parameter->openapi, 'required', 'bool'),
×
554
                    deprecated: $this->phpize($parameter->openapi, 'deprecated', 'bool'),
×
555
                    allowEmptyValue: $this->phpize($parameter->openapi, 'allowEmptyValue', 'bool'),
×
556
                    schema: isset($parameter->openapi->schema->values) ? $this->buildValues($parameter->openapi->schema->values) : null,
×
557
                    style: $this->phpize($parameter->openapi, 'style', 'string'),
×
558
                    explode: $this->phpize($parameter->openapi, 'explode', 'bool'),
×
559
                    allowReserved: $this->phpize($parameter->openapi, 'allowReserved', 'bool'),
×
560
                    example: $this->phpize($parameter->openapi, 'example', 'string'),
×
561
                    examples: isset($parameter->openapi->examples->values) ? new \ArrayObject($this->buildValues($parameter->openapi->examples->values)) : null,
×
562
                    content: isset($parameter->openapi->content->values) ? new \ArrayObject($this->buildValues($parameter->openapi->content->values)) : null,
×
563
                ) : null,
×
564
                provider: $this->phpize($parameter, 'provider', 'string'),
×
565
                filter: $this->phpize($parameter, 'filter', 'string'),
×
566
                property: $this->phpize($parameter, 'property', 'string'),
×
567
                description: $this->phpize($parameter, 'description', 'string'),
×
568
                priority: $this->phpize($parameter, 'priority', 'integer'),
×
569
                extraProperties: $this->buildExtraProperties($parameter, 'extraProperties') ?? [],
×
570
            );
×
571
        }
572

573
        return $parameters;
×
574
    }
575
}
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