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

api-platform / core / 17581213192

09 Sep 2025 11:31AM UTC coverage: 0.0% (-22.6%) from 22.604%
17581213192

Pull #7374

github

web-flow
Merge 0f1360e1a into 6db55be8c
Pull Request #7374: fix(jsonld): various json streamer fixes

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

12081 existing lines in 401 files now uncovered.

0 of 52792 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\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 */
UNCOV
50
            $xml = simplexml_import_dom(XmlUtils::loadFile($path, self::SCHEMA));
×
UNCOV
51
        } catch (\InvalidArgumentException $e) {
×
52
            // Ensure it's not a resource
53
            try {
UNCOV
54
                simplexml_import_dom(XmlUtils::loadFile($path, XmlPropertyExtractor::SCHEMA));
×
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
UNCOV
60
            return;
×
61
        }
62

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

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

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

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

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

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

168
        return $data;
×
169
    }
170

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
305
        return $uriVariables;
×
306
    }
307

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

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

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

324
        return $data;
×
325
    }
326

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

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

338
        return $data;
×
339
    }
340

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

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

351
        return true;
×
352
    }
353

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

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

365
        return $data;
×
366
    }
367

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

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

379
        return $data;
×
380
    }
381

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

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

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

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

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

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

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

UNCOV
432
        return $data;
×
433
    }
434

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

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

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

465
        return $data;
×
466
    }
467

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

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

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

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

493
        return null;
×
494
    }
495

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

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

510
        return $links;
×
511
    }
512

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

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

527
        return $headers;
×
528
    }
529

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

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

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