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

api-platform / core / 15394724286

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

push

github

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

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

10888 of 49042 relevant lines covered (22.2%)

10.59 hits per line

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

87.27
/src/Metadata/HttpOperation.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;
15

16
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
17
use ApiPlatform\OpenApi\Attributes\Webhook;
18
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
19
use ApiPlatform\State\OptionsInterface;
20
use Symfony\Component\WebLink\Link as WebLink;
21

22
class HttpOperation extends Operation
23
{
24
    public const METHOD_GET = 'GET';
25
    public const METHOD_POST = 'POST';
26
    public const METHOD_PUT = 'PUT';
27
    public const METHOD_PATCH = 'PATCH';
28
    public const METHOD_DELETE = 'DELETE';
29
    public const METHOD_HEAD = 'HEAD';
30
    public const METHOD_OPTIONS = 'OPTIONS';
31

32
    /**
33
     * @param string[]|null                                  $types         the RDF types of this property
34
     * @param array<int|string, string|string[]>|string|null $formats       {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
35
     * @param array<int|string, string|string[]>|string|null $inputFormats  {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
36
     * @param array<int|string, string|string[]>|string|null $outputFormats {@see https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation}
37
     * @param array<string,array{
38
     *     0: string,
39
     *     1: string
40
     * }|array{
41
     *     from_property?: string,
42
     *     to_property?: string,
43
     *     from_class?: string,
44
     *     to_class?: string,
45
     *     identifiers?: string[],
46
     *     composite_identifier?: bool,
47
     *     expanded_value?: string,
48
     * }|Link>|string[]|string|null $uriVariables {@see https://api-platform.com/docs/core/subresources/}
49
     * @param string|null     $routePrefix {@see https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations}
50
     * @param string|null     $sunset      {@see https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed}
51
     * @param string|int|null $status      {@see https://api-platform.com/docs/core/operations/#configuring-operations}
52
     * @param array{
53
     *     max_age?: int,
54
     *     vary?: string|string[],
55
     *     public?: bool,
56
     *     shared_max_age?: int,
57
     *     stale_while_revalidate?: int,
58
     *     stale-if-error?: int,
59
     * }|null $cacheHeaders {@see https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers}
60
     * @param array<string, string>|null $headers
61
     * @param array{
62
     *     field: string,
63
     *     direction: string,
64
     * }|null $paginationViaCursor {@see https://api-platform.com/docs/core/pagination/#cursor-based-pagination}
65
     * @param array|null $normalizationContext   {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
66
     * @param array|null $denormalizationContext {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
67
     * @param array|null $hydraContext           {@see https://api-platform.com/docs/core/extending-jsonld-context/#hydra}
68
     * @param array{
69
     *     class?: string|null,
70
     *     name?: string,
71
     * }|string|false|null $input {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
72
     * @param array{
73
     *     class?: string|null,
74
     *     name?: string,
75
     * }|string|false|null $output {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
76
     * @param string|array|bool|null                              $mercure   {@see https://api-platform.com/docs/core/mercure}
77
     * @param string|bool|null                                    $messenger {@see https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus}
78
     * @param string|callable|null                                $provider  {@see https://api-platform.com/docs/core/state-providers/#state-providers}
79
     * @param string|callable|null                                $processor {@see https://api-platform.com/docs/core/state-processors/#state-processors}
80
     * @param WebLink[]|null                                      $links
81
     * @param array<class-string<ProblemExceptionInterface>>|null $errors
82
     */
83
    public function __construct(
84
        protected string $method = 'GET',
85
        protected ?string $uriTemplate = null,
86
        protected ?array $types = null,
87
        protected $formats = null,
88
        protected $inputFormats = null,
89
        protected $outputFormats = null,
90
        protected $uriVariables = null,
91
        protected ?string $routePrefix = null,
92
        protected ?string $routeName = null,
93
        protected ?array $defaults = null,
94
        protected ?array $requirements = null,
95
        protected ?array $options = null,
96
        protected ?bool $stateless = null,
97
        /**
98
         * The `sunset` option indicates when a deprecated operation will be removed.
99
         *
100
         * <div data-code-selector>
101
         *
102
         * ```php
103
         * <?php
104
         * // api/src/Entity/Parchment.php
105
         * use ApiPlatform\Metadata\Get;
106
         *
107
         * #[Get(deprecationReason: 'Create a Book instead', sunset: '01/01/2020')]
108
         * class Parchment
109
         * {
110
         *     // ...
111
         * }
112
         * ```
113
         *
114
         * ```yaml
115
         * # api/config/api_platform/resources.yaml
116
         * resources:
117
         *     App\Entity\Parchment:
118
         *         - operations:
119
         *               ApiPlatform\Metadata\Get:
120
         *                   deprecationReason: 'Create a Book instead'
121
         *                   sunset: '01/01/2020'
122
         * ```
123
         *
124
         * ```xml
125
         * <?xml version="1.0" encoding="UTF-8" ?>
126
         * <!-- api/config/api_platform/resources.xml -->
127
         *
128
         * <resources
129
         *         xmlns="https://api-platform.com/schema/metadata/resources-3.0"
130
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
131
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
132
         *         https://api-platform.com/schema/metadata/resources-3.0.xsd">
133
         *     <resource class="App\Entity\Parchment">
134
         *         <operations>
135
         *             <operation class="ApiPlatform\Metadata\Get" deprecationReason="Create a Book instead" sunset="01/01/2020" />
136
         *         <operations>
137
         *     </resource>
138
         * </resources>
139
         * ```
140
         *
141
         * </div>
142
         */
143
        protected ?string $sunset = null,
144
        protected ?string $acceptPatch = null,
145
        protected $status = null,
146
        protected ?string $host = null,
147
        protected ?array $schemes = null,
148
        protected ?string $condition = null,
149
        protected ?string $controller = null,
150
        protected ?array $headers = null,
151
        protected ?array $cacheHeaders = null,
152
        protected ?array $paginationViaCursor = null,
153
        protected ?array $hydraContext = null,
154
        protected bool|OpenApiOperation|Webhook|null $openapi = null,
155
        protected ?array $exceptionToStatus = null,
156
        protected ?array $links = null,
157
        protected ?array $errors = null,
158
        protected ?bool $strictQueryParameterValidation = null,
159
        protected ?bool $hideHydraOperation = null,
160

161
        ?string $shortName = null,
162
        ?string $class = null,
163
        ?bool $paginationEnabled = null,
164
        ?string $paginationType = null,
165
        ?int $paginationItemsPerPage = null,
166
        ?int $paginationMaximumItemsPerPage = null,
167
        ?bool $paginationPartial = null,
168
        ?bool $paginationClientEnabled = null,
169
        ?bool $paginationClientItemsPerPage = null,
170
        ?bool $paginationClientPartial = null,
171
        ?bool $paginationFetchJoinCollection = null,
172
        ?bool $paginationUseOutputWalkers = null,
173
        ?array $order = null,
174
        ?string $description = null,
175
        ?array $normalizationContext = null,
176
        ?array $denormalizationContext = null,
177
        ?bool $collectDenormalizationErrors = null,
178
        string|\Stringable|null $security = null,
179
        ?string $securityMessage = null,
180
        string|\Stringable|null $securityPostDenormalize = null,
181
        ?string $securityPostDenormalizeMessage = null,
182
        string|\Stringable|null $securityPostValidation = null,
183
        ?string $securityPostValidationMessage = null,
184
        ?string $deprecationReason = null,
185
        ?array $filters = null,
186
        ?array $validationContext = null,
187
        $input = null,
188
        $output = null,
189
        $mercure = null,
190
        $messenger = null,
191
        ?int $urlGenerationStrategy = null,
192
        ?bool $read = null,
193
        ?bool $deserialize = null,
194
        ?bool $validate = null,
195
        ?bool $write = null,
196
        ?bool $serialize = null,
197
        ?bool $fetchPartial = null,
198
        ?bool $forceEager = null,
199
        ?int $priority = null,
200
        ?string $name = null,
201
        $provider = null,
202
        $processor = null,
203
        ?OptionsInterface $stateOptions = null,
204
        array|Parameters|null $parameters = null,
205
        array|string|null $rules = null,
206
        ?string $policy = null,
207
        array|string|null $middleware = null,
208
        ?bool $queryParameterValidationEnabled = null,
209
        array $extraProperties = [],
210
    ) {
211
        parent::__construct(
329✔
212
            shortName: $shortName,
329✔
213
            class: $class,
329✔
214
            paginationEnabled: $paginationEnabled,
329✔
215
            paginationType: $paginationType,
329✔
216
            paginationItemsPerPage: $paginationItemsPerPage,
329✔
217
            paginationMaximumItemsPerPage: $paginationMaximumItemsPerPage,
329✔
218
            paginationPartial: $paginationPartial,
329✔
219
            paginationClientEnabled: $paginationClientEnabled,
329✔
220
            paginationClientItemsPerPage: $paginationClientItemsPerPage,
329✔
221
            paginationClientPartial: $paginationClientPartial,
329✔
222
            paginationFetchJoinCollection: $paginationFetchJoinCollection,
329✔
223
            paginationUseOutputWalkers: $paginationUseOutputWalkers,
329✔
224
            order: $order,
329✔
225
            description: $description,
329✔
226
            normalizationContext: $normalizationContext,
329✔
227
            denormalizationContext: $denormalizationContext,
329✔
228
            collectDenormalizationErrors: $collectDenormalizationErrors,
329✔
229
            security: $security,
329✔
230
            securityMessage: $securityMessage,
329✔
231
            securityPostDenormalize: $securityPostDenormalize,
329✔
232
            securityPostDenormalizeMessage: $securityPostDenormalizeMessage,
329✔
233
            securityPostValidation: $securityPostValidation,
329✔
234
            securityPostValidationMessage: $securityPostValidationMessage,
329✔
235
            deprecationReason: $deprecationReason,
329✔
236
            filters: $filters,
329✔
237
            validationContext: $validationContext,
329✔
238
            input: $input,
329✔
239
            output: $output,
329✔
240
            mercure: $mercure,
329✔
241
            messenger: $messenger,
329✔
242
            urlGenerationStrategy: $urlGenerationStrategy,
329✔
243
            read: $read,
329✔
244
            deserialize: $deserialize,
329✔
245
            validate: $validate,
329✔
246
            write: $write,
329✔
247
            serialize: $serialize,
329✔
248
            fetchPartial: $fetchPartial,
329✔
249
            forceEager: $forceEager,
329✔
250
            priority: $priority,
329✔
251
            name: $name,
329✔
252
            provider: $provider,
329✔
253
            processor: $processor,
329✔
254
            stateOptions: $stateOptions,
329✔
255
            parameters: $parameters,
329✔
256
            rules: $rules,
329✔
257
            policy: $policy,
329✔
258
            middleware: $middleware,
329✔
259
            queryParameterValidationEnabled: $queryParameterValidationEnabled,
329✔
260
            strictQueryParameterValidation: $strictQueryParameterValidation,
329✔
261
            hideHydraOperation: $hideHydraOperation,
329✔
262
            extraProperties: $extraProperties
329✔
263
        );
329✔
264
    }
265

266
    public function getMethod(): string
267
    {
268
        return $this->method;
313✔
269
    }
270

271
    public function withMethod(string $method): static
272
    {
273
        $self = clone $this;
1✔
274
        $self->method = $method;
1✔
275

276
        return $self;
1✔
277
    }
278

279
    public function getUriTemplate(): ?string
280
    {
281
        return $this->uriTemplate;
273✔
282
    }
283

284
    public function withUriTemplate(?string $uriTemplate = null)
285
    {
286
        $self = clone $this;
42✔
287
        $self->uriTemplate = $uriTemplate;
42✔
288

289
        return $self;
42✔
290
    }
291

292
    public function getTypes(): ?array
293
    {
294
        return $this->types;
258✔
295
    }
296

297
    /**
298
     * @param string[]|string $types
299
     */
300
    public function withTypes($types): static
301
    {
302
        $self = clone $this;
2✔
303
        $self->types = (array) $types;
2✔
304

305
        return $self;
2✔
306
    }
307

308
    public function getFormats()
309
    {
310
        return $this->formats;
42✔
311
    }
312

313
    public function withFormats($formats = null): static
314
    {
315
        $self = clone $this;
1✔
316
        $self->formats = $formats;
1✔
317

318
        return $self;
1✔
319
    }
320

321
    public function getInputFormats()
322
    {
323
        return $this->inputFormats;
57✔
324
    }
325

326
    public function withInputFormats($inputFormats = null): static
327
    {
328
        $self = clone $this;
41✔
329
        $self->inputFormats = $inputFormats;
41✔
330

331
        return $self;
41✔
332
    }
333

334
    public function getOutputFormats()
335
    {
336
        return $this->outputFormats;
255✔
337
    }
338

339
    public function withOutputFormats($outputFormats = null): static
340
    {
341
        $self = clone $this;
39✔
342
        $self->outputFormats = $outputFormats;
39✔
343

344
        return $self;
39✔
345
    }
346

347
    public function getUriVariables()
348
    {
349
        return $this->uriVariables;
277✔
350
    }
351

352
    public function withUriVariables($uriVariables): static
353
    {
354
        $self = clone $this;
42✔
355
        $self->uriVariables = $uriVariables;
42✔
356

357
        return $self;
42✔
358
    }
359

360
    public function getRoutePrefix(): ?string
361
    {
362
        return $this->routePrefix;
55✔
363
    }
364

365
    public function withRoutePrefix(string $routePrefix): static
366
    {
367
        $self = clone $this;
1✔
368
        $self->routePrefix = $routePrefix;
1✔
369

370
        return $self;
1✔
371
    }
372

373
    public function getRouteName(): ?string
374
    {
375
        return $this->routeName;
258✔
376
    }
377

378
    public function withRouteName(?string $routeName): static
379
    {
380
        $self = clone $this;
×
381
        $self->routeName = $routeName;
×
382

383
        return $self;
×
384
    }
385

386
    public function getDefaults(): ?array
387
    {
388
        return $this->defaults;
54✔
389
    }
390

391
    public function withDefaults(array $defaults): static
392
    {
393
        $self = clone $this;
2✔
394
        $self->defaults = $defaults;
2✔
395

396
        return $self;
2✔
397
    }
398

399
    public function getRequirements(): ?array
400
    {
401
        return $this->requirements;
54✔
402
    }
403

404
    public function withRequirements(array $requirements): static
405
    {
406
        $self = clone $this;
3✔
407
        $self->requirements = $requirements;
3✔
408

409
        return $self;
3✔
410
    }
411

412
    public function getOptions(): ?array
413
    {
414
        return $this->options;
54✔
415
    }
416

417
    public function withOptions(array $options): static
418
    {
419
        $self = clone $this;
1✔
420
        $self->options = $options;
1✔
421

422
        return $self;
1✔
423
    }
424

425
    public function getStateless(): ?bool
426
    {
427
        return $this->stateless;
54✔
428
    }
429

430
    public function withStateless($stateless): static
431
    {
432
        $self = clone $this;
1✔
433
        $self->stateless = $stateless;
1✔
434

435
        return $self;
1✔
436
    }
437

438
    public function getSunset(): ?string
439
    {
440
        return $this->sunset;
235✔
441
    }
442

443
    public function withSunset(string $sunset): static
444
    {
445
        $self = clone $this;
1✔
446
        $self->sunset = $sunset;
1✔
447

448
        return $self;
1✔
449
    }
450

451
    public function getAcceptPatch(): ?string
452
    {
453
        return $this->acceptPatch;
235✔
454
    }
455

456
    public function withAcceptPatch(string $acceptPatch): static
457
    {
458
        $self = clone $this;
9✔
459
        $self->acceptPatch = $acceptPatch;
9✔
460

461
        return $self;
9✔
462
    }
463

464
    public function getStatus(): ?int
465
    {
466
        return $this->status;
264✔
467
    }
468

469
    public function withStatus(int $status): static
470
    {
471
        $self = clone $this;
35✔
472
        $self->status = $status;
35✔
473

474
        return $self;
35✔
475
    }
476

477
    public function getHost(): ?string
478
    {
479
        return $this->host;
54✔
480
    }
481

482
    public function withHost(string $host): static
483
    {
484
        $self = clone $this;
1✔
485
        $self->host = $host;
1✔
486

487
        return $self;
1✔
488
    }
489

490
    public function getSchemes(): ?array
491
    {
492
        return $this->schemes;
54✔
493
    }
494

495
    public function withSchemes(array $schemes): static
496
    {
497
        $self = clone $this;
1✔
498
        $self->schemes = $schemes;
1✔
499

500
        return $self;
1✔
501
    }
502

503
    public function getCondition(): ?string
504
    {
505
        return $this->condition;
54✔
506
    }
507

508
    public function withCondition(string $condition): static
509
    {
510
        $self = clone $this;
1✔
511
        $self->condition = $condition;
1✔
512

513
        return $self;
1✔
514
    }
515

516
    public function getController(): ?string
517
    {
518
        return $this->controller;
63✔
519
    }
520

521
    public function withController(string $controller): static
522
    {
523
        $self = clone $this;
2✔
524
        $self->controller = $controller;
2✔
525

526
        return $self;
2✔
527
    }
528

529
    public function getHeaders(): ?array
530
    {
531
        return $this->headers;
235✔
532
    }
533

534
    public function withHeaders(array $headers): static
535
    {
536
        $self = clone $this;
×
537
        $self->headers = $headers;
×
538

539
        return $self;
×
540
    }
541

542
    public function getCacheHeaders(): ?array
543
    {
544
        return $this->cacheHeaders;
207✔
545
    }
546

547
    public function withCacheHeaders(array $cacheHeaders): static
548
    {
549
        $self = clone $this;
39✔
550
        $self->cacheHeaders = $cacheHeaders;
39✔
551

552
        return $self;
39✔
553
    }
554

555
    public function getPaginationViaCursor(): ?array
556
    {
557
        return $this->paginationViaCursor;
129✔
558
    }
559

560
    public function withPaginationViaCursor(array $paginationViaCursor): static
561
    {
562
        $self = clone $this;
×
563
        $self->paginationViaCursor = $paginationViaCursor;
×
564

565
        return $self;
×
566
    }
567

568
    public function getHydraContext(): ?array
569
    {
570
        return $this->hydraContext;
42✔
571
    }
572

573
    public function withHydraContext(array $hydraContext): static
574
    {
575
        $self = clone $this;
×
576
        $self->hydraContext = $hydraContext;
×
577

578
        return $self;
×
579
    }
580

581
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
582
    {
583
        return $this->openapi;
50✔
584
    }
585

586
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): static
587
    {
588
        $self = clone $this;
1✔
589
        $self->openapi = $openapi;
1✔
590

591
        return $self;
1✔
592
    }
593

594
    public function getExceptionToStatus(): ?array
595
    {
596
        return $this->exceptionToStatus;
66✔
597
    }
598

599
    public function withExceptionToStatus(array $exceptionToStatus): static
600
    {
601
        $self = clone $this;
×
602
        $self->exceptionToStatus = $exceptionToStatus;
×
603

604
        return $self;
×
605
    }
606

607
    public function getLinks(): ?array
608
    {
609
        return $this->links;
234✔
610
    }
611

612
    /**
613
     * @param WebLink[] $links
614
     */
615
    public function withLinks(array $links): static
616
    {
617
        $self = clone $this;
×
618
        $self->links = $links;
×
619

620
        return $self;
×
621
    }
622

623
    public function getErrors(): ?array
624
    {
625
        return $this->errors;
10✔
626
    }
627

628
    /**
629
     * @param class-string<ProblemExceptionInterface>[] $errors
630
     */
631
    public function withErrors(array $errors): static
632
    {
633
        $self = clone $this;
×
634
        $self->errors = $errors;
×
635

636
        return $self;
×
637
    }
638
}
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