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

api-platform / core / 17487636389

05 Sep 2025 08:13AM UTC coverage: 22.339% (-0.2%) from 22.577%
17487636389

push

github

soyuka
docs: changelog 4.1.23

11057 of 49497 relevant lines covered (22.34%)

11.74 hits per line

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

87.35
/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(
373✔
212
            shortName: $shortName,
373✔
213
            class: $class,
373✔
214
            paginationEnabled: $paginationEnabled,
373✔
215
            paginationType: $paginationType,
373✔
216
            paginationItemsPerPage: $paginationItemsPerPage,
373✔
217
            paginationMaximumItemsPerPage: $paginationMaximumItemsPerPage,
373✔
218
            paginationPartial: $paginationPartial,
373✔
219
            paginationClientEnabled: $paginationClientEnabled,
373✔
220
            paginationClientItemsPerPage: $paginationClientItemsPerPage,
373✔
221
            paginationClientPartial: $paginationClientPartial,
373✔
222
            paginationFetchJoinCollection: $paginationFetchJoinCollection,
373✔
223
            paginationUseOutputWalkers: $paginationUseOutputWalkers,
373✔
224
            paginationViaCursor: $paginationViaCursor,
373✔
225
            order: $order,
373✔
226
            description: $description,
373✔
227
            normalizationContext: $normalizationContext,
373✔
228
            denormalizationContext: $denormalizationContext,
373✔
229
            collectDenormalizationErrors: $collectDenormalizationErrors,
373✔
230
            security: $security,
373✔
231
            securityMessage: $securityMessage,
373✔
232
            securityPostDenormalize: $securityPostDenormalize,
373✔
233
            securityPostDenormalizeMessage: $securityPostDenormalizeMessage,
373✔
234
            securityPostValidation: $securityPostValidation,
373✔
235
            securityPostValidationMessage: $securityPostValidationMessage,
373✔
236
            deprecationReason: $deprecationReason,
373✔
237
            filters: $filters,
373✔
238
            validationContext: $validationContext,
373✔
239
            input: $input,
373✔
240
            output: $output,
373✔
241
            mercure: $mercure,
373✔
242
            messenger: $messenger,
373✔
243
            urlGenerationStrategy: $urlGenerationStrategy,
373✔
244
            read: $read,
373✔
245
            deserialize: $deserialize,
373✔
246
            validate: $validate,
373✔
247
            write: $write,
373✔
248
            serialize: $serialize,
373✔
249
            fetchPartial: $fetchPartial,
373✔
250
            forceEager: $forceEager,
373✔
251
            priority: $priority,
373✔
252
            name: $name,
373✔
253
            provider: $provider,
373✔
254
            processor: $processor,
373✔
255
            stateOptions: $stateOptions,
373✔
256
            parameters: $parameters,
373✔
257
            rules: $rules,
373✔
258
            policy: $policy,
373✔
259
            middleware: $middleware,
373✔
260
            queryParameterValidationEnabled: $queryParameterValidationEnabled,
373✔
261
            strictQueryParameterValidation: $strictQueryParameterValidation,
373✔
262
            hideHydraOperation: $hideHydraOperation,
373✔
263
            extraProperties: $extraProperties
373✔
264
        );
373✔
265
    }
266

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

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

277
        return $self;
1✔
278
    }
279

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

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

290
        return $self;
47✔
291
    }
292

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

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

306
        return $self;
2✔
307
    }
308

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

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

319
        return $self;
1✔
320
    }
321

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

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

332
        return $self;
46✔
333
    }
334

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

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

345
        return $self;
44✔
346
    }
347

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

353
    /**
354
     * @param array<string, mixed>|array<int, Link>|list<string> $uriVariables
355
     */
356
    public function withUriVariables($uriVariables): static
357
    {
358
        $self = clone $this;
47✔
359
        $self->uriVariables = $uriVariables;
47✔
360

361
        return $self;
47✔
362
    }
363

364
    public function getRoutePrefix(): ?string
365
    {
366
        return $this->routePrefix;
60✔
367
    }
368

369
    public function withRoutePrefix(string $routePrefix): static
370
    {
371
        $self = clone $this;
1✔
372
        $self->routePrefix = $routePrefix;
1✔
373

374
        return $self;
1✔
375
    }
376

377
    public function getRouteName(): ?string
378
    {
379
        return $this->routeName;
314✔
380
    }
381

382
    public function withRouteName(?string $routeName): static
383
    {
384
        $self = clone $this;
×
385
        $self->routeName = $routeName;
×
386

387
        return $self;
×
388
    }
389

390
    public function getDefaults(): ?array
391
    {
392
        return $this->defaults;
59✔
393
    }
394

395
    public function withDefaults(array $defaults): static
396
    {
397
        $self = clone $this;
2✔
398
        $self->defaults = $defaults;
2✔
399

400
        return $self;
2✔
401
    }
402

403
    public function getRequirements(): ?array
404
    {
405
        return $this->requirements;
59✔
406
    }
407

408
    public function withRequirements(array $requirements): static
409
    {
410
        $self = clone $this;
4✔
411
        $self->requirements = $requirements;
4✔
412

413
        return $self;
4✔
414
    }
415

416
    public function getOptions(): ?array
417
    {
418
        return $this->options;
59✔
419
    }
420

421
    public function withOptions(array $options): static
422
    {
423
        $self = clone $this;
1✔
424
        $self->options = $options;
1✔
425

426
        return $self;
1✔
427
    }
428

429
    public function getStateless(): ?bool
430
    {
431
        return $this->stateless;
59✔
432
    }
433

434
    public function withStateless($stateless): static
435
    {
436
        $self = clone $this;
1✔
437
        $self->stateless = $stateless;
1✔
438

439
        return $self;
1✔
440
    }
441

442
    public function getSunset(): ?string
443
    {
444
        return $this->sunset;
266✔
445
    }
446

447
    public function withSunset(string $sunset): static
448
    {
449
        $self = clone $this;
1✔
450
        $self->sunset = $sunset;
1✔
451

452
        return $self;
1✔
453
    }
454

455
    public function getAcceptPatch(): ?string
456
    {
457
        return $this->acceptPatch;
266✔
458
    }
459

460
    public function withAcceptPatch(string $acceptPatch): static
461
    {
462
        $self = clone $this;
11✔
463
        $self->acceptPatch = $acceptPatch;
11✔
464

465
        return $self;
11✔
466
    }
467

468
    public function getStatus(): ?int
469
    {
470
        return $this->status;
320✔
471
    }
472

473
    public function withStatus(int $status): static
474
    {
475
        $self = clone $this;
54✔
476
        $self->status = $status;
54✔
477

478
        return $self;
54✔
479
    }
480

481
    public function getHost(): ?string
482
    {
483
        return $this->host;
59✔
484
    }
485

486
    public function withHost(string $host): static
487
    {
488
        $self = clone $this;
1✔
489
        $self->host = $host;
1✔
490

491
        return $self;
1✔
492
    }
493

494
    public function getSchemes(): ?array
495
    {
496
        return $this->schemes;
59✔
497
    }
498

499
    public function withSchemes(array $schemes): static
500
    {
501
        $self = clone $this;
1✔
502
        $self->schemes = $schemes;
1✔
503

504
        return $self;
1✔
505
    }
506

507
    public function getCondition(): ?string
508
    {
509
        return $this->condition;
59✔
510
    }
511

512
    public function withCondition(string $condition): static
513
    {
514
        $self = clone $this;
1✔
515
        $self->condition = $condition;
1✔
516

517
        return $self;
1✔
518
    }
519

520
    public function getController(): ?string
521
    {
522
        return $this->controller;
68✔
523
    }
524

525
    public function withController(string $controller): static
526
    {
527
        $self = clone $this;
46✔
528
        $self->controller = $controller;
46✔
529

530
        return $self;
46✔
531
    }
532

533
    public function getHeaders(): ?array
534
    {
535
        return $this->headers;
266✔
536
    }
537

538
    public function withHeaders(array $headers): static
539
    {
540
        $self = clone $this;
×
541
        $self->headers = $headers;
×
542

543
        return $self;
×
544
    }
545

546
    public function getCacheHeaders(): ?array
547
    {
548
        return $this->cacheHeaders;
249✔
549
    }
550

551
    public function withCacheHeaders(array $cacheHeaders): static
552
    {
553
        $self = clone $this;
44✔
554
        $self->cacheHeaders = $cacheHeaders;
44✔
555

556
        return $self;
44✔
557
    }
558

559
    public function getPaginationViaCursor(): ?array
560
    {
561
        return $this->paginationViaCursor;
136✔
562
    }
563

564
    public function withPaginationViaCursor(array $paginationViaCursor): static
565
    {
566
        $self = clone $this;
×
567
        $self->paginationViaCursor = $paginationViaCursor;
×
568

569
        return $self;
×
570
    }
571

572
    public function getHydraContext(): ?array
573
    {
574
        return $this->hydraContext;
47✔
575
    }
576

577
    public function withHydraContext(array $hydraContext): static
578
    {
579
        $self = clone $this;
×
580
        $self->hydraContext = $hydraContext;
×
581

582
        return $self;
×
583
    }
584

585
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
586
    {
587
        return $this->openapi;
60✔
588
    }
589

590
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): static
591
    {
592
        $self = clone $this;
2✔
593
        $self->openapi = $openapi;
2✔
594

595
        return $self;
2✔
596
    }
597

598
    public function getExceptionToStatus(): ?array
599
    {
600
        return $this->exceptionToStatus;
89✔
601
    }
602

603
    public function withExceptionToStatus(array $exceptionToStatus): static
604
    {
605
        $self = clone $this;
×
606
        $self->exceptionToStatus = $exceptionToStatus;
×
607

608
        return $self;
×
609
    }
610

611
    public function getLinks(): ?array
612
    {
613
        return $this->links;
292✔
614
    }
615

616
    /**
617
     * @param WebLink[] $links
618
     */
619
    public function withLinks(array $links): static
620
    {
621
        $self = clone $this;
×
622
        $self->links = $links;
×
623

624
        return $self;
×
625
    }
626

627
    public function getErrors(): ?array
628
    {
629
        return $this->errors;
10✔
630
    }
631

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

640
        return $self;
×
641
    }
642
}
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

© 2026 Coveralls, Inc