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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

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

92.77
/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
        ?bool $elasticsearch = null,
198
        ?int $urlGenerationStrategy = null,
199
        ?bool $read = null,
200
        ?bool $deserialize = null,
201
        ?bool $validate = null,
202
        ?bool $write = null,
203
        ?bool $serialize = null,
204
        ?bool $fetchPartial = null,
205
        ?bool $forceEager = null,
206
        ?int $priority = null,
207
        ?string $name = null,
208
        $provider = null,
209
        $processor = null,
210
        ?OptionsInterface $stateOptions = null,
211
        array|Parameters|null $parameters = null,
212
        array|string|null $rules = null,
213
        ?string $policy = null,
214
        array|string|null $middleware = null,
215
        ?bool $queryParameterValidationEnabled = null,
216
        array $extraProperties = [],
217
    ) {
218
        parent::__construct(
1,285✔
219
            shortName: $shortName,
1,285✔
220
            class: $class,
1,285✔
221
            paginationEnabled: $paginationEnabled,
1,285✔
222
            paginationType: $paginationType,
1,285✔
223
            paginationItemsPerPage: $paginationItemsPerPage,
1,285✔
224
            paginationMaximumItemsPerPage: $paginationMaximumItemsPerPage,
1,285✔
225
            paginationPartial: $paginationPartial,
1,285✔
226
            paginationClientEnabled: $paginationClientEnabled,
1,285✔
227
            paginationClientItemsPerPage: $paginationClientItemsPerPage,
1,285✔
228
            paginationClientPartial: $paginationClientPartial,
1,285✔
229
            paginationFetchJoinCollection: $paginationFetchJoinCollection,
1,285✔
230
            paginationUseOutputWalkers: $paginationUseOutputWalkers,
1,285✔
231
            order: $order,
1,285✔
232
            description: $description,
1,285✔
233
            normalizationContext: $normalizationContext,
1,285✔
234
            denormalizationContext: $denormalizationContext,
1,285✔
235
            collectDenormalizationErrors: $collectDenormalizationErrors,
1,285✔
236
            security: $security,
1,285✔
237
            securityMessage: $securityMessage,
1,285✔
238
            securityPostDenormalize: $securityPostDenormalize,
1,285✔
239
            securityPostDenormalizeMessage: $securityPostDenormalizeMessage,
1,285✔
240
            securityPostValidation: $securityPostValidation,
1,285✔
241
            securityPostValidationMessage: $securityPostValidationMessage,
1,285✔
242
            deprecationReason: $deprecationReason,
1,285✔
243
            filters: $filters,
1,285✔
244
            validationContext: $validationContext,
1,285✔
245
            input: $input,
1,285✔
246
            output: $output,
1,285✔
247
            mercure: $mercure,
1,285✔
248
            messenger: $messenger,
1,285✔
249
            elasticsearch: $elasticsearch,
1,285✔
250
            urlGenerationStrategy: $urlGenerationStrategy,
1,285✔
251
            read: $read,
1,285✔
252
            deserialize: $deserialize,
1,285✔
253
            validate: $validate,
1,285✔
254
            write: $write,
1,285✔
255
            serialize: $serialize,
1,285✔
256
            fetchPartial: $fetchPartial,
1,285✔
257
            forceEager: $forceEager,
1,285✔
258
            priority: $priority,
1,285✔
259
            name: $name,
1,285✔
260
            provider: $provider,
1,285✔
261
            processor: $processor,
1,285✔
262
            stateOptions: $stateOptions,
1,285✔
263
            parameters: $parameters,
1,285✔
264
            rules: $rules,
1,285✔
265
            policy: $policy,
1,285✔
266
            middleware: $middleware,
1,285✔
267
            queryParameterValidationEnabled: $queryParameterValidationEnabled,
1,285✔
268
            strictQueryParameterValidation: $strictQueryParameterValidation,
1,285✔
269
            hideHydraOperation: $hideHydraOperation,
1,285✔
270
            extraProperties: $extraProperties
1,285✔
271
        );
1,285✔
272
    }
273

274
    public function getMethod(): string
275
    {
276
        return $this->method;
1,299✔
277
    }
278

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

284
        return $self;
2✔
285
    }
286

287
    public function getUriTemplate(): ?string
288
    {
289
        return $this->uriTemplate;
1,214✔
290
    }
291

292
    public function withUriTemplate(?string $uriTemplate = null)
293
    {
294
        $self = clone $this;
101✔
295
        $self->uriTemplate = $uriTemplate;
101✔
296

297
        return $self;
101✔
298
    }
299

300
    public function getTypes(): ?array
301
    {
302
        return $this->types;
1,058✔
303
    }
304

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

313
        return $self;
7✔
314
    }
315

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

321
    public function withFormats($formats = null): static
322
    {
323
        $self = clone $this;
3✔
324
        $self->formats = $formats;
3✔
325

326
        return $self;
3✔
327
    }
328

329
    public function getInputFormats()
330
    {
331
        return $this->inputFormats;
324✔
332
    }
333

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

339
        return $self;
100✔
340
    }
341

342
    public function getOutputFormats()
343
    {
344
        return $this->outputFormats;
1,051✔
345
    }
346

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

352
        return $self;
96✔
353
    }
354

355
    public function getUriVariables()
356
    {
357
        return $this->uriVariables;
1,191✔
358
    }
359

360
    public function withUriVariables($uriVariables): static
361
    {
362
        $self = clone $this;
102✔
363
        $self->uriVariables = $uriVariables;
102✔
364

365
        return $self;
102✔
366
    }
367

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

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

378
        return $self;
3✔
379
    }
380

381
    public function getRouteName(): ?string
382
    {
383
        return $this->routeName;
1,133✔
384
    }
385

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

391
        return $self;
×
392
    }
393

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

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

404
        return $self;
4✔
405
    }
406

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

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

417
        return $self;
7✔
418
    }
419

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

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

430
        return $self;
2✔
431
    }
432

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

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

443
        return $self;
2✔
444
    }
445

446
    public function getSunset(): ?string
447
    {
448
        return $this->sunset;
1,007✔
449
    }
450

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

456
        return $self;
3✔
457
    }
458

459
    public function getAcceptPatch(): ?string
460
    {
461
        return $this->acceptPatch;
1,007✔
462
    }
463

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

469
        return $self;
36✔
470
    }
471

472
    public function getStatus(): ?int
473
    {
474
        return $this->status;
1,161✔
475
    }
476

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

482
        return $self;
131✔
483
    }
484

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

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

495
        return $self;
2✔
496
    }
497

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

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

508
        return $self;
2✔
509
    }
510

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

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

521
        return $self;
2✔
522
    }
523

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

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

534
        return $self;
65✔
535
    }
536

537
    public function getHeaders(): ?array
538
    {
539
        return $this->headers;
1,007✔
540
    }
541

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

UNCOV
547
        return $self;
1✔
548
    }
549

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

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

560
        return $self;
94✔
561
    }
562

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

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

UNCOV
573
        return $self;
1✔
574
    }
575

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

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

UNCOV
586
        return $self;
1✔
587
    }
588

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

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

599
        return $self;
5✔
600
    }
601

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

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

612
        return $self;
×
613
    }
614

615
    public function getLinks(): ?array
616
    {
617
        return $this->links;
1,013✔
618
    }
619

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

628
        return $self;
×
629
    }
630

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

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

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