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

api-platform / core / 15775135891

20 Jun 2025 08:42AM UTC coverage: 22.065% (+0.2%) from 21.876%
15775135891

push

github

soyuka
Merge 4.1

13 of 103 new or added lines in 10 files covered. (12.62%)

868 existing lines in 35 files now uncovered.

11487 of 52060 relevant lines covered (22.06%)

21.72 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
     *     must_revalidate?: bool,
60
     *     proxy_revalidate?: bool,
61
     *     no_cache?: bool,
62
     *     no_store?: bool,
63
     *     no_transform?: bool,
64
     *     immutable?: bool,
65
     * }|null $cacheHeaders {@see https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers}
66
     * @param array<string, string>|null $headers
67
     * @param array{
68
     *     field: string,
69
     *     direction: string,
70
     * }|null $paginationViaCursor {@see https://api-platform.com/docs/core/pagination/#cursor-based-pagination}
71
     * @param array|null $normalizationContext   {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
72
     * @param array|null $denormalizationContext {@see https://api-platform.com/docs/core/serialization/#using-serialization-groups}
73
     * @param array|null $hydraContext           {@see https://api-platform.com/docs/core/extending-jsonld-context/#hydra}
74
     * @param array{
75
     *     class?: string|null,
76
     *     name?: string,
77
     * }|string|false|null $input {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
78
     * @param array{
79
     *     class?: string|null,
80
     *     name?: string,
81
     * }|string|false|null $output {@see https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation}
82
     * @param string|array|bool|null                              $mercure   {@see https://api-platform.com/docs/core/mercure}
83
     * @param string|bool|null                                    $messenger {@see https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus}
84
     * @param string|callable|null                                $provider  {@see https://api-platform.com/docs/core/state-providers/#state-providers}
85
     * @param string|callable|null                                $processor {@see https://api-platform.com/docs/core/state-processors/#state-processors}
86
     * @param WebLink[]|null                                      $links
87
     * @param array<class-string<ProblemExceptionInterface>>|null $errors
88
     */
89
    public function __construct(
90
        protected string $method = 'GET',
91
        protected ?string $uriTemplate = null,
92
        protected ?array $types = null,
93
        protected $formats = null,
94
        protected $inputFormats = null,
95
        protected $outputFormats = null,
96
        protected $uriVariables = null,
97
        protected ?string $routePrefix = null,
98
        protected ?string $routeName = null,
99
        protected ?array $defaults = null,
100
        protected ?array $requirements = null,
101
        protected ?array $options = null,
102
        protected ?bool $stateless = null,
103
        /**
104
         * The `sunset` option indicates when a deprecated operation will be removed.
105
         *
106
         * <div data-code-selector>
107
         *
108
         * ```php
109
         * <?php
110
         * // api/src/Entity/Parchment.php
111
         * use ApiPlatform\Metadata\Get;
112
         *
113
         * #[Get(deprecationReason: 'Create a Book instead', sunset: '01/01/2020')]
114
         * class Parchment
115
         * {
116
         *     // ...
117
         * }
118
         * ```
119
         *
120
         * ```yaml
121
         * # api/config/api_platform/resources.yaml
122
         * resources:
123
         *     App\Entity\Parchment:
124
         *         - operations:
125
         *               ApiPlatform\Metadata\Get:
126
         *                   deprecationReason: 'Create a Book instead'
127
         *                   sunset: '01/01/2020'
128
         * ```
129
         *
130
         * ```xml
131
         * <?xml version="1.0" encoding="UTF-8" ?>
132
         * <!-- api/config/api_platform/resources.xml -->
133
         *
134
         * <resources
135
         *         xmlns="https://api-platform.com/schema/metadata/resources-3.0"
136
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
137
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/resources-3.0
138
         *         https://api-platform.com/schema/metadata/resources-3.0.xsd">
139
         *     <resource class="App\Entity\Parchment">
140
         *         <operations>
141
         *             <operation class="ApiPlatform\Metadata\Get" deprecationReason="Create a Book instead" sunset="01/01/2020" />
142
         *         <operations>
143
         *     </resource>
144
         * </resources>
145
         * ```
146
         *
147
         * </div>
148
         */
149
        protected ?string $sunset = null,
150
        protected ?string $acceptPatch = null,
151
        protected $status = null,
152
        protected ?string $host = null,
153
        protected ?array $schemes = null,
154
        protected ?string $condition = null,
155
        protected ?string $controller = null,
156
        protected ?array $headers = null,
157
        protected ?array $cacheHeaders = null,
158
        protected ?array $paginationViaCursor = null,
159
        protected ?array $hydraContext = null,
160
        protected bool|OpenApiOperation|Webhook|null $openapi = null,
161
        protected ?array $exceptionToStatus = null,
162
        protected ?array $links = null,
163
        protected ?array $errors = null,
164
        protected ?bool $strictQueryParameterValidation = null,
165
        protected ?bool $hideHydraOperation = null,
166

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

272
    public function getMethod(): string
273
    {
274
        return $this->method;
674✔
275
    }
276

277
    public function withMethod(string $method): static
278
    {
279
        $self = clone $this;
2✔
280
        $self->method = $method;
2✔
281

282
        return $self;
2✔
283
    }
284

285
    public function getUriTemplate(): ?string
286
    {
287
        return $this->uriTemplate;
586✔
288
    }
289

290
    public function withUriTemplate(?string $uriTemplate = null)
291
    {
292
        $self = clone $this;
100✔
293
        $self->uriTemplate = $uriTemplate;
100✔
294

295
        return $self;
100✔
296
    }
297

298
    public function getTypes(): ?array
299
    {
300
        return $this->types;
558✔
301
    }
302

303
    /**
304
     * @param string[]|string $types
305
     */
306
    public function withTypes($types): static
307
    {
308
        $self = clone $this;
4✔
309
        $self->types = (array) $types;
4✔
310

311
        return $self;
4✔
312
    }
313

314
    public function getFormats()
315
    {
316
        return $this->formats;
102✔
317
    }
318

319
    public function withFormats($formats = null): static
320
    {
321
        $self = clone $this;
2✔
322
        $self->formats = $formats;
2✔
323

324
        return $self;
2✔
325
    }
326

327
    public function getInputFormats()
328
    {
329
        return $this->inputFormats;
133✔
330
    }
331

332
    public function withInputFormats($inputFormats = null): static
333
    {
334
        $self = clone $this;
100✔
335
        $self->inputFormats = $inputFormats;
100✔
336

337
        return $self;
100✔
338
    }
339

340
    public function getOutputFormats()
341
    {
342
        return $this->outputFormats;
552✔
343
    }
344

345
    public function withOutputFormats($outputFormats = null): static
346
    {
347
        $self = clone $this;
96✔
348
        $self->outputFormats = $outputFormats;
96✔
349

350
        return $self;
96✔
351
    }
352

353
    public function getUriVariables()
354
    {
355
        return $this->uriVariables;
582✔
356
    }
357

358
    /**
359
     * @param array<string, mixed>|array<int, Link>|list<string> $uriVariables
360
     */
361
    public function withUriVariables($uriVariables): static
362
    {
363
        $self = clone $this;
102✔
364
        $self->uriVariables = $uriVariables;
102✔
365

366
        return $self;
102✔
367
    }
368

369
    public function getRoutePrefix(): ?string
370
    {
371
        return $this->routePrefix;
130✔
372
    }
373

374
    public function withRoutePrefix(string $routePrefix): static
375
    {
376
        $self = clone $this;
2✔
377
        $self->routePrefix = $routePrefix;
2✔
378

379
        return $self;
2✔
380
    }
381

382
    public function getRouteName(): ?string
383
    {
384
        return $this->routeName;
555✔
385
    }
386

387
    public function withRouteName(?string $routeName): static
388
    {
389
        $self = clone $this;
×
UNCOV
390
        $self->routeName = $routeName;
×
391

UNCOV
392
        return $self;
×
393
    }
394

395
    public function getDefaults(): ?array
396
    {
397
        return $this->defaults;
128✔
398
    }
399

400
    public function withDefaults(array $defaults): static
401
    {
402
        $self = clone $this;
4✔
403
        $self->defaults = $defaults;
4✔
404

405
        return $self;
4✔
406
    }
407

408
    public function getRequirements(): ?array
409
    {
410
        return $this->requirements;
128✔
411
    }
412

413
    public function withRequirements(array $requirements): static
414
    {
415
        $self = clone $this;
6✔
416
        $self->requirements = $requirements;
6✔
417

418
        return $self;
6✔
419
    }
420

421
    public function getOptions(): ?array
422
    {
423
        return $this->options;
128✔
424
    }
425

426
    public function withOptions(array $options): static
427
    {
428
        $self = clone $this;
2✔
429
        $self->options = $options;
2✔
430

431
        return $self;
2✔
432
    }
433

434
    public function getStateless(): ?bool
435
    {
436
        return $this->stateless;
128✔
437
    }
438

439
    public function withStateless($stateless): static
440
    {
441
        $self = clone $this;
2✔
442
        $self->stateless = $stateless;
2✔
443

444
        return $self;
2✔
445
    }
446

447
    public function getSunset(): ?string
448
    {
449
        return $this->sunset;
506✔
450
    }
451

452
    public function withSunset(string $sunset): static
453
    {
454
        $self = clone $this;
2✔
455
        $self->sunset = $sunset;
2✔
456

457
        return $self;
2✔
458
    }
459

460
    public function getAcceptPatch(): ?string
461
    {
462
        return $this->acceptPatch;
506✔
463
    }
464

465
    public function withAcceptPatch(string $acceptPatch): static
466
    {
467
        $self = clone $this;
28✔
468
        $self->acceptPatch = $acceptPatch;
28✔
469

470
        return $self;
28✔
471
    }
472

473
    public function getStatus(): ?int
474
    {
475
        return $this->status;
567✔
476
    }
477

478
    public function withStatus(int $status): static
479
    {
480
        $self = clone $this;
82✔
481
        $self->status = $status;
82✔
482

483
        return $self;
82✔
484
    }
485

486
    public function getHost(): ?string
487
    {
488
        return $this->host;
128✔
489
    }
490

491
    public function withHost(string $host): static
492
    {
493
        $self = clone $this;
2✔
494
        $self->host = $host;
2✔
495

496
        return $self;
2✔
497
    }
498

499
    public function getSchemes(): ?array
500
    {
501
        return $this->schemes;
128✔
502
    }
503

504
    public function withSchemes(array $schemes): static
505
    {
506
        $self = clone $this;
2✔
507
        $self->schemes = $schemes;
2✔
508

509
        return $self;
2✔
510
    }
511

512
    public function getCondition(): ?string
513
    {
514
        return $this->condition;
128✔
515
    }
516

517
    public function withCondition(string $condition): static
518
    {
519
        $self = clone $this;
2✔
520
        $self->condition = $condition;
2✔
521

522
        return $self;
2✔
523
    }
524

525
    public function getController(): ?string
526
    {
527
        return $this->controller;
146✔
528
    }
529

530
    public function withController(string $controller): static
531
    {
532
        $self = clone $this;
52✔
533
        $self->controller = $controller;
52✔
534

535
        return $self;
52✔
536
    }
537

538
    public function getHeaders(): ?array
539
    {
540
        return $this->headers;
506✔
541
    }
542

543
    public function withHeaders(array $headers): static
544
    {
545
        $self = clone $this;
×
UNCOV
546
        $self->headers = $headers;
×
547

UNCOV
548
        return $self;
×
549
    }
550

551
    public function getCacheHeaders(): ?array
552
    {
553
        return $this->cacheHeaders;
449✔
554
    }
555

556
    public function withCacheHeaders(array $cacheHeaders): static
557
    {
558
        $self = clone $this;
96✔
559
        $self->cacheHeaders = $cacheHeaders;
96✔
560

561
        return $self;
96✔
562
    }
563

564
    public function getPaginationViaCursor(): ?array
565
    {
566
        return $this->paginationViaCursor;
280✔
567
    }
568

569
    public function withPaginationViaCursor(array $paginationViaCursor): static
570
    {
571
        $self = clone $this;
×
UNCOV
572
        $self->paginationViaCursor = $paginationViaCursor;
×
573

UNCOV
574
        return $self;
×
575
    }
576

577
    public function getHydraContext(): ?array
578
    {
579
        return $this->hydraContext;
102✔
580
    }
581

582
    public function withHydraContext(array $hydraContext): static
583
    {
584
        $self = clone $this;
×
UNCOV
585
        $self->hydraContext = $hydraContext;
×
586

UNCOV
587
        return $self;
×
588
    }
589

590
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
591
    {
592
        return $this->openapi;
130✔
593
    }
594

595
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): static
596
    {
597
        $self = clone $this;
4✔
598
        $self->openapi = $openapi;
4✔
599

600
        return $self;
4✔
601
    }
602

603
    public function getExceptionToStatus(): ?array
604
    {
605
        return $this->exceptionToStatus;
158✔
606
    }
607

608
    public function withExceptionToStatus(array $exceptionToStatus): static
609
    {
610
        $self = clone $this;
×
UNCOV
611
        $self->exceptionToStatus = $exceptionToStatus;
×
612

UNCOV
613
        return $self;
×
614
    }
615

616
    public function getLinks(): ?array
617
    {
618
        return $this->links;
509✔
619
    }
620

621
    /**
622
     * @param WebLink[] $links
623
     */
624
    public function withLinks(array $links): static
625
    {
626
        $self = clone $this;
×
UNCOV
627
        $self->links = $links;
×
628

UNCOV
629
        return $self;
×
630
    }
631

632
    public function getErrors(): ?array
633
    {
634
        return $this->errors;
22✔
635
    }
636

637
    /**
638
     * @param class-string<ProblemExceptionInterface>[] $errors
639
     */
640
    public function withErrors(array $errors): static
641
    {
642
        $self = clone $this;
×
UNCOV
643
        $self->errors = $errors;
×
644

UNCOV
645
        return $self;
×
646
    }
647
}
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