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

api-platform / core / 15935978034

27 Jun 2025 09:07PM UTC coverage: 22.499% (-0.001%) from 22.5%
15935978034

push

github

web-flow
fix(metadata): support stateOptions in YAML and XML for Doctrine ORM/ODM (#7217)

0 of 23 new or added lines in 2 files covered. (0.0%)

2 existing lines in 1 file now uncovered.

11075 of 49224 relevant lines covered (22.5%)

21.83 hits per line

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

47.35
/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\State\OptionsInterface;
29
use Symfony\Component\Config\Util\XmlUtils;
30
use Symfony\Component\WebLink\Link;
31

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

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

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

59
            // It's a property: ignore error
60
            return;
84✔
61
        }
62

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

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

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

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

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

164
            $data[] = (string) $format;
×
165
        }
166

167
        return $data;
×
168
    }
169

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

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

180
        $openapi = $resource->openapi;
×
181
        $data = [];
×
182
        $attributes = $openapi->attributes();
×
183

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

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

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

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

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

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

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

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

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

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

261
        foreach ($data as $key => $value) {
×
262
            if (null === $value) {
×
263
                unset($data[$key]);
×
264
            }
265
        }
266

267
        return new OpenApiOperation(...$data);
×
268
    }
269

270
    private function buildUriVariables(\SimpleXMLElement $resource): ?array
271
    {
272
        if (!isset($resource->uriVariables->uriVariable)) {
84✔
273
            return null;
84✔
274
        }
275

276
        $uriVariables = [];
84✔
277
        foreach ($resource->uriVariables->uriVariable as $data) {
84✔
278
            $parameterName = (string) $data['parameterName'];
84✔
279
            if (1 === (null === $data->attributes() ? 0 : \count($data->attributes()))) {
84✔
280
                $uriVariables[$parameterName] = $parameterName;
84✔
281
                continue;
84✔
282
            }
283

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

304
        return $uriVariables;
84✔
305
    }
306

307
    private function buildCacheHeaders(\SimpleXMLElement $resource): ?array
308
    {
309
        if (!isset($resource->cacheHeaders->cacheHeader)) {
84✔
310
            return null;
84✔
311
        }
312

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

320
            $data[(string) $cacheHeader['name']] = XmlUtils::phpize((string) $cacheHeader);
×
321
        }
322

323
        return $data;
×
324
    }
325

326
    private function buildRequirements(\SimpleXMLElement $resource): ?array
327
    {
328
        if (!isset($resource->requirements->requirement)) {
84✔
329
            return null;
84✔
330
        }
331

332
        $data = [];
×
333
        foreach ($resource->requirements->requirement as $requirement) {
×
334
            $data[(string) $requirement->attributes()->property] = (string) $requirement;
×
335
        }
336

337
        return $data;
×
338
    }
339

340
    private function buildMercure(\SimpleXMLElement $resource): array|bool|null
341
    {
342
        if (!isset($resource->mercure)) {
84✔
343
            return null;
84✔
344
        }
345

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

350
        return true;
×
351
    }
352

353
    private function buildPaginationViaCursor(\SimpleXMLElement $resource): ?array
354
    {
355
        if (!isset($resource->paginationViaCursor->paginationField)) {
84✔
356
            return null;
84✔
357
        }
358

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

364
        return $data;
×
365
    }
366

367
    private function buildExceptionToStatus(\SimpleXMLElement $resource): ?array
368
    {
369
        if (!isset($resource->exceptionToStatus->exception)) {
84✔
370
            return null;
84✔
371
        }
372

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

378
        return $data;
×
379
    }
380

381
    private function buildExtraProperties(\SimpleXMLElement $resource, ?string $key = null): ?array
382
    {
383
        if (null !== $key) {
84✔
384
            if (!isset($resource->{$key})) {
84✔
385
                return null;
84✔
386
            }
387

388
            $resource = $resource->{$key};
×
389
        }
390

391
        return $this->buildValues($resource->values);
×
392
    }
393

394
    private function buildOperations(\SimpleXMLElement $resource, array $root): ?array
395
    {
396
        if (!isset($resource->operations->operation)) {
84✔
397
            return null;
84✔
398
        }
399

400
        $data = [];
84✔
401
        foreach ($resource->operations->operation as $operation) {
84✔
402
            $datum = $this->buildExtendedBase($operation);
84✔
403
            foreach ($datum as $key => $value) {
84✔
404
                if (null === $value) {
84✔
405
                    $datum[$key] = $root[$key];
84✔
406
                }
407
            }
408

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

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

431
        return $data;
84✔
432
    }
433

434
    private function buildGraphQlOperations(\SimpleXMLElement $resource, array $root): ?array
435
    {
436
        if (!isset($resource->graphQlOperations->graphQlOperation)) {
84✔
437
            return null;
84✔
438
        }
439

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

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

464
        return $data;
×
465
    }
466

467
    private function buildStateOptions(\SimpleXMLElement $resource): ?OptionsInterface
468
    {
469
        $stateOptions = $resource->stateOptions ?? null;
84✔
470
        if (!$stateOptions) {
84✔
471
            return null;
84✔
472
        }
473

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

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

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

492
        return null;
×
493
    }
494

495
    /**
496
     * @return Link[]
497
     */
498
    private function buildLinks(\SimpleXMLElement $resource): ?array
499
    {
500
        if (!$resource->links) {
84✔
501
            return null;
84✔
502
        }
503

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

509
        return $links;
×
510
    }
511

512
    /**
513
     * @return array<string, string>
514
     */
515
    private function buildHeaders(\SimpleXMLElement $resource): ?array
516
    {
517
        if (!$resource->headers) {
84✔
518
            return null;
84✔
519
        }
520

521
        $headers = [];
×
522
        foreach ($resource->headers as $header) {
×
523
            $headers[(string) $header->header->attributes()->key] = (string) $header->header->attributes()->value;
×
524
        }
525

526
        return $headers;
×
527
    }
528

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

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

570
        return $parameters;
×
571
    }
572
}
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