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

api-platform / core / 9710836697

28 Jun 2024 09:35AM UTC coverage: 63.285% (+1.2%) from 62.122%
9710836697

push

github

soyuka
docs: changelog v3.3.7

11104 of 17546 relevant lines covered (63.29%)

52.26 hits per line

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

94.51
/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\OpenApi\Attributes\Webhook;
17
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
18
use ApiPlatform\State\OptionsInterface;
19
use Symfony\Component\WebLink\Link as WebLink;
20

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

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

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

256
    public function getMethod(): string
257
    {
258
        return $this->method;
903✔
259
    }
260

261
    public function withMethod(string $method): self
262
    {
263
        $self = clone $this;
4✔
264
        $self->method = $method;
4✔
265

266
        return $self;
4✔
267
    }
268

269
    public function getUriTemplate(): ?string
270
    {
271
        return $this->uriTemplate;
367✔
272
    }
273

274
    public function withUriTemplate(?string $uriTemplate = null)
275
    {
276
        $self = clone $this;
41✔
277
        $self->uriTemplate = $uriTemplate;
41✔
278

279
        return $self;
41✔
280
    }
281

282
    public function getTypes(): ?array
283
    {
284
        return $this->types;
415✔
285
    }
286

287
    /**
288
     * @param string[]|string $types
289
     */
290
    public function withTypes($types): self
291
    {
292
        $self = clone $this;
21✔
293
        $self->types = (array) $types;
21✔
294

295
        return $self;
21✔
296
    }
297

298
    public function getFormats()
299
    {
300
        return $this->formats;
26✔
301
    }
302

303
    public function withFormats($formats = null): self
304
    {
305
        $self = clone $this;
4✔
306
        $self->formats = $formats;
4✔
307

308
        return $self;
4✔
309
    }
310

311
    public function getInputFormats()
312
    {
313
        return $this->inputFormats;
101✔
314
    }
315

316
    public function withInputFormats($inputFormats = null): self
317
    {
318
        $self = clone $this;
22✔
319
        $self->inputFormats = $inputFormats;
22✔
320

321
        return $self;
22✔
322
    }
323

324
    public function getOutputFormats()
325
    {
326
        return $this->outputFormats;
323✔
327
    }
328

329
    public function withOutputFormats($outputFormats = null): self
330
    {
331
        $self = clone $this;
14✔
332
        $self->outputFormats = $outputFormats;
14✔
333

334
        return $self;
14✔
335
    }
336

337
    public function getUriVariables()
338
    {
339
        return $this->uriVariables;
403✔
340
    }
341

342
    public function withUriVariables($uriVariables): self
343
    {
344
        $self = clone $this;
34✔
345
        $self->uriVariables = $uriVariables;
34✔
346

347
        return $self;
34✔
348
    }
349

350
    public function getRoutePrefix(): ?string
351
    {
352
        return $this->routePrefix;
61✔
353
    }
354

355
    public function withRoutePrefix(string $routePrefix): self
356
    {
357
        $self = clone $this;
8✔
358
        $self->routePrefix = $routePrefix;
8✔
359

360
        return $self;
8✔
361
    }
362

363
    public function getRouteName(): ?string
364
    {
365
        return $this->routeName;
303✔
366
    }
367

368
    public function withRouteName(?string $routeName): self
369
    {
370
        $self = clone $this;
×
371
        $self->routeName = $routeName;
×
372

373
        return $self;
×
374
    }
375

376
    public function getDefaults(): ?array
377
    {
378
        return $this->defaults;
57✔
379
    }
380

381
    public function withDefaults(array $defaults): self
382
    {
383
        $self = clone $this;
8✔
384
        $self->defaults = $defaults;
8✔
385

386
        return $self;
8✔
387
    }
388

389
    public function getRequirements(): ?array
390
    {
391
        return $this->requirements;
57✔
392
    }
393

394
    public function withRequirements(array $requirements): self
395
    {
396
        $self = clone $this;
8✔
397
        $self->requirements = $requirements;
8✔
398

399
        return $self;
8✔
400
    }
401

402
    public function getOptions(): ?array
403
    {
404
        return $this->options;
57✔
405
    }
406

407
    public function withOptions(array $options): self
408
    {
409
        $self = clone $this;
4✔
410
        $self->options = $options;
4✔
411

412
        return $self;
4✔
413
    }
414

415
    public function getStateless(): ?bool
416
    {
417
        return $this->stateless;
57✔
418
    }
419

420
    public function withStateless($stateless): self
421
    {
422
        $self = clone $this;
4✔
423
        $self->stateless = $stateless;
4✔
424

425
        return $self;
4✔
426
    }
427

428
    public function getSunset(): ?string
429
    {
430
        return $this->sunset;
279✔
431
    }
432

433
    public function withSunset(string $sunset): self
434
    {
435
        $self = clone $this;
4✔
436
        $self->sunset = $sunset;
4✔
437

438
        return $self;
4✔
439
    }
440

441
    public function getAcceptPatch(): ?string
442
    {
443
        return $this->acceptPatch;
279✔
444
    }
445

446
    public function withAcceptPatch(string $acceptPatch): self
447
    {
448
        $self = clone $this;
4✔
449
        $self->acceptPatch = $acceptPatch;
4✔
450

451
        return $self;
4✔
452
    }
453

454
    public function getStatus(): ?int
455
    {
456
        return $this->status;
347✔
457
    }
458

459
    public function withStatus(int $status): self
460
    {
461
        $self = clone $this;
64✔
462
        $self->status = $status;
64✔
463

464
        return $self;
64✔
465
    }
466

467
    public function getHost(): ?string
468
    {
469
        return $this->host;
57✔
470
    }
471

472
    public function withHost(string $host): self
473
    {
474
        $self = clone $this;
4✔
475
        $self->host = $host;
4✔
476

477
        return $self;
4✔
478
    }
479

480
    public function getSchemes(): ?array
481
    {
482
        return $this->schemes;
57✔
483
    }
484

485
    public function withSchemes(array $schemes): self
486
    {
487
        $self = clone $this;
4✔
488
        $self->schemes = $schemes;
4✔
489

490
        return $self;
4✔
491
    }
492

493
    public function getCondition(): ?string
494
    {
495
        return $this->condition;
57✔
496
    }
497

498
    public function withCondition(string $condition): self
499
    {
500
        $self = clone $this;
4✔
501
        $self->condition = $condition;
4✔
502

503
        return $self;
4✔
504
    }
505

506
    public function getController(): ?string
507
    {
508
        return $this->controller;
315✔
509
    }
510

511
    public function withController(string $controller): self
512
    {
513
        $self = clone $this;
21✔
514
        $self->controller = $controller;
21✔
515

516
        return $self;
21✔
517
    }
518

519
    public function getHeaders(): ?array
520
    {
521
        return $this->headers;
259✔
522
    }
523

524
    public function withHeaders(array $headers): self
525
    {
526
        $self = clone $this;
4✔
527
        $self->headers = $headers;
4✔
528

529
        return $self;
4✔
530
    }
531

532
    public function getCacheHeaders(): ?array
533
    {
534
        return $this->cacheHeaders;
228✔
535
    }
536

537
    public function withCacheHeaders(array $cacheHeaders): self
538
    {
539
        $self = clone $this;
14✔
540
        $self->cacheHeaders = $cacheHeaders;
14✔
541

542
        return $self;
14✔
543
    }
544

545
    public function getPaginationViaCursor(): ?array
546
    {
547
        return $this->paginationViaCursor;
41✔
548
    }
549

550
    public function withPaginationViaCursor(array $paginationViaCursor): self
551
    {
552
        $self = clone $this;
8✔
553
        $self->paginationViaCursor = $paginationViaCursor;
8✔
554

555
        return $self;
8✔
556
    }
557

558
    public function getHydraContext(): ?array
559
    {
560
        return $this->hydraContext;
38✔
561
    }
562

563
    public function withHydraContext(array $hydraContext): self
564
    {
565
        $self = clone $this;
8✔
566
        $self->hydraContext = $hydraContext;
8✔
567

568
        return $self;
8✔
569
    }
570

571
    public function getOpenapiContext(): ?array
572
    {
573
        return $this->openapiContext;
49✔
574
    }
575

576
    public function withOpenapiContext(array $openapiContext): self
577
    {
578
        $self = clone $this;
4✔
579
        $self->openapiContext = $openapiContext;
4✔
580

581
        return $self;
4✔
582
    }
583

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

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

594
        return $self;
5✔
595
    }
596

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

602
    public function withExceptionToStatus(array $exceptionToStatus): self
603
    {
604
        $self = clone $this;
44✔
605
        $self->exceptionToStatus = $exceptionToStatus;
44✔
606

607
        return $self;
44✔
608
    }
609

610
    public function getQueryParameterValidationEnabled(): ?bool
611
    {
612
        return $this->queryParameterValidationEnabled;
247✔
613
    }
614

615
    public function withQueryParameterValidationEnabled(bool $queryParameterValidationEnabled): self
616
    {
617
        $self = clone $this;
×
618
        $self->queryParameterValidationEnabled = $queryParameterValidationEnabled;
×
619

620
        return $self;
×
621
    }
622

623
    public function getLinks(): ?array
624
    {
625
        return $this->links;
259✔
626
    }
627

628
    /**
629
     * @param WebLink[] $links
630
     */
631
    public function withLinks(array $links): self
632
    {
633
        $self = clone $this;
×
634
        $self->links = $links;
×
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