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

api-platform / core / 8371158547

21 Mar 2024 07:25AM UTC coverage: 57.153% (+0.06%) from 57.095%
8371158547

push

github

soyuka
Merge 3.2

47 of 49 new or added lines in 11 files covered. (95.92%)

78 existing lines in 3 files now uncovered.

9592 of 16783 relevant lines covered (57.15%)

41.89 hits per line

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

94.48
/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 $security = null,
177
        ?string $securityMessage = null,
178
        ?string $securityPostDenormalize = null,
179
        ?string $securityPostDenormalizeMessage = null,
180
        ?string $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 $extraProperties = [],
204
    ) {
205
        parent::__construct(
972✔
206
            shortName: $shortName,
972✔
207
            class: $class,
972✔
208
            paginationEnabled: $paginationEnabled,
972✔
209
            paginationType: $paginationType,
972✔
210
            paginationItemsPerPage: $paginationItemsPerPage,
972✔
211
            paginationMaximumItemsPerPage: $paginationMaximumItemsPerPage,
972✔
212
            paginationPartial: $paginationPartial,
972✔
213
            paginationClientEnabled: $paginationClientEnabled,
972✔
214
            paginationClientItemsPerPage: $paginationClientItemsPerPage,
972✔
215
            paginationClientPartial: $paginationClientPartial,
972✔
216
            paginationFetchJoinCollection: $paginationFetchJoinCollection,
972✔
217
            paginationUseOutputWalkers: $paginationUseOutputWalkers,
972✔
218
            order: $order,
972✔
219
            description: $description,
972✔
220
            normalizationContext: $normalizationContext,
972✔
221
            denormalizationContext: $denormalizationContext,
972✔
222
            collectDenormalizationErrors: $collectDenormalizationErrors,
972✔
223
            security: $security,
972✔
224
            securityMessage: $securityMessage,
972✔
225
            securityPostDenormalize: $securityPostDenormalize,
972✔
226
            securityPostDenormalizeMessage: $securityPostDenormalizeMessage,
972✔
227
            securityPostValidation: $securityPostValidation,
972✔
228
            securityPostValidationMessage: $securityPostValidationMessage,
972✔
229
            deprecationReason: $deprecationReason,
972✔
230
            filters: $filters,
972✔
231
            validationContext: $validationContext,
972✔
232
            input: $input,
972✔
233
            output: $output,
972✔
234
            mercure: $mercure,
972✔
235
            messenger: $messenger,
972✔
236
            elasticsearch: $elasticsearch,
972✔
237
            urlGenerationStrategy: $urlGenerationStrategy,
972✔
238
            read: $read,
972✔
239
            deserialize: $deserialize,
972✔
240
            validate: $validate,
972✔
241
            write: $write,
972✔
242
            serialize: $serialize,
972✔
243
            fetchPartial: $fetchPartial,
972✔
244
            forceEager: $forceEager,
972✔
245
            priority: $priority,
972✔
246
            name: $name,
972✔
247
            provider: $provider,
972✔
248
            processor: $processor,
972✔
249
            stateOptions: $stateOptions,
972✔
250
            extraProperties: $extraProperties
972✔
251
        );
972✔
252
    }
253

254
    public function getMethod(): string
255
    {
256
        return $this->method;
732✔
257
    }
258

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

264
        return $self;
4✔
265
    }
266

267
    public function getUriTemplate(): ?string
268
    {
269
        return $this->uriTemplate;
260✔
270
    }
271

272
    public function withUriTemplate(?string $uriTemplate = null)
273
    {
274
        $self = clone $this;
64✔
275
        $self->uriTemplate = $uriTemplate;
64✔
276

277
        return $self;
64✔
278
    }
279

280
    public function getTypes(): ?array
281
    {
282
        return $this->types;
248✔
283
    }
284

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

293
        return $self;
20✔
294
    }
295

296
    public function getFormats()
297
    {
298
        return $this->formats;
48✔
299
    }
300

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

306
        return $self;
4✔
307
    }
308

309
    public function getInputFormats()
310
    {
311
        return $this->inputFormats;
116✔
312
    }
313

314
    public function withInputFormats($inputFormats = null): self
315
    {
316
        $self = clone $this;
44✔
317
        $self->inputFormats = $inputFormats;
44✔
318

319
        return $self;
44✔
320
    }
321

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

327
    public function withOutputFormats($outputFormats = null): self
328
    {
329
        $self = clone $this;
36✔
330
        $self->outputFormats = $outputFormats;
36✔
331

332
        return $self;
36✔
333
    }
334

335
    public function getUriVariables()
336
    {
337
        return $this->uriVariables;
296✔
338
    }
339

340
    public function withUriVariables($uriVariables): self
341
    {
342
        $self = clone $this;
56✔
343
        $self->uriVariables = $uriVariables;
56✔
344

345
        return $self;
56✔
346
    }
347

348
    public function getRoutePrefix(): ?string
349
    {
350
        return $this->routePrefix;
76✔
351
    }
352

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

358
        return $self;
8✔
359
    }
360

361
    public function getRouteName(): ?string
362
    {
363
        return $this->routeName;
76✔
364
    }
365

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

UNCOV
371
        return $self;
×
372
    }
373

374
    public function getDefaults(): ?array
375
    {
376
        return $this->defaults;
72✔
377
    }
378

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

384
        return $self;
8✔
385
    }
386

387
    public function getRequirements(): ?array
388
    {
389
        return $this->requirements;
72✔
390
    }
391

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

397
        return $self;
8✔
398
    }
399

400
    public function getOptions(): ?array
401
    {
402
        return $this->options;
72✔
403
    }
404

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

410
        return $self;
4✔
411
    }
412

413
    public function getStateless(): ?bool
414
    {
415
        return $this->stateless;
72✔
416
    }
417

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

423
        return $self;
4✔
424
    }
425

426
    public function getSunset(): ?string
427
    {
428
        return $this->sunset;
184✔
429
    }
430

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

436
        return $self;
4✔
437
    }
438

439
    public function getAcceptPatch(): ?string
440
    {
441
        return $this->acceptPatch;
184✔
442
    }
443

444
    public function withAcceptPatch(string $acceptPatch): self
445
    {
446
        $self = clone $this;
20✔
447
        $self->acceptPatch = $acceptPatch;
20✔
448

449
        return $self;
20✔
450
    }
451

452
    public function getStatus(): ?int
453
    {
454
        return $this->status;
248✔
455
    }
456

457
    public function withStatus(int $status): self
458
    {
459
        $self = clone $this;
32✔
460
        $self->status = $status;
32✔
461

462
        return $self;
32✔
463
    }
464

465
    public function getHost(): ?string
466
    {
467
        return $this->host;
72✔
468
    }
469

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

475
        return $self;
4✔
476
    }
477

478
    public function getSchemes(): ?array
479
    {
480
        return $this->schemes;
72✔
481
    }
482

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

488
        return $self;
4✔
489
    }
490

491
    public function getCondition(): ?string
492
    {
493
        return $this->condition;
72✔
494
    }
495

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

501
        return $self;
4✔
502
    }
503

504
    public function getController(): ?string
505
    {
506
        return $this->controller;
300✔
507
    }
508

509
    public function withController(string $controller): self
510
    {
511
        $self = clone $this;
44✔
512
        $self->controller = $controller;
44✔
513

514
        return $self;
44✔
515
    }
516

517
    public function getHeaders(): ?array
518
    {
519
        return $this->headers;
164✔
520
    }
521

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

527
        return $self;
4✔
528
    }
529

530
    public function getCacheHeaders(): ?array
531
    {
532
        return $this->cacheHeaders;
172✔
533
    }
534

535
    public function withCacheHeaders(array $cacheHeaders): self
536
    {
537
        $self = clone $this;
36✔
538
        $self->cacheHeaders = $cacheHeaders;
36✔
539

540
        return $self;
36✔
541
    }
542

543
    public function getPaginationViaCursor(): ?array
544
    {
545
        return $this->paginationViaCursor;
52✔
546
    }
547

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

553
        return $self;
8✔
554
    }
555

556
    public function getHydraContext(): ?array
557
    {
558
        return $this->hydraContext;
56✔
559
    }
560

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

566
        return $self;
8✔
567
    }
568

569
    public function getOpenapiContext(): ?array
570
    {
571
        return $this->openapiContext;
64✔
572
    }
573

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

579
        return $self;
4✔
580
    }
581

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

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

592
        return $self;
4✔
593
    }
594

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

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

605
        return $self;
44✔
606
    }
607

608
    public function getQueryParameterValidationEnabled(): ?bool
609
    {
610
        return $this->queryParameterValidationEnabled;
152✔
611
    }
612

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

UNCOV
618
        return $self;
×
619
    }
620

621
    public function getLinks(): ?array
622
    {
623
        return $this->links;
164✔
624
    }
625

626
    /**
627
     * @param WebLink[] $links
628
     */
629
    public function withLinks(array $links): self
630
    {
631
        $self = clone $this;
×
UNCOV
632
        $self->links = $links;
×
633

UNCOV
634
        return $self;
×
635
    }
636
}
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