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

api-platform / core / 10729306835

05 Sep 2024 10:46PM UTC coverage: 7.655% (-0.01%) from 7.665%
10729306835

push

github

web-flow
Merge pull request #6586 from soyuka/merge-342

Merge 3.4

0 of 54 new or added lines in 12 files covered. (0.0%)

8760 existing lines in 277 files now uncovered.

12505 of 163357 relevant lines covered (7.66%)

22.84 hits per line

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

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

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

261
    public function getMethod(): string
262
    {
UNCOV
263
        return $this->method;
2,240✔
264
    }
265

266
    public function withMethod(string $method): self
267
    {
268
        $self = clone $this;
×
269
        $self->method = $method;
×
270

271
        return $self;
×
272
    }
273

274
    public function getUriTemplate(): ?string
275
    {
UNCOV
276
        return $this->uriTemplate;
2,228✔
277
    }
278

279
    public function withUriTemplate(?string $uriTemplate = null)
280
    {
UNCOV
281
        $self = clone $this;
33✔
UNCOV
282
        $self->uriTemplate = $uriTemplate;
33✔
283

UNCOV
284
        return $self;
33✔
285
    }
286

287
    public function getTypes(): ?array
288
    {
UNCOV
289
        return $this->types;
1,853✔
290
    }
291

292
    /**
293
     * @param string[]|string $types
294
     */
295
    public function withTypes($types): self
296
    {
UNCOV
297
        $self = clone $this;
7✔
UNCOV
298
        $self->types = (array) $types;
7✔
299

UNCOV
300
        return $self;
7✔
301
    }
302

303
    public function getFormats()
304
    {
UNCOV
305
        return $this->formats;
34✔
306
    }
307

308
    public function withFormats($formats = null): self
309
    {
UNCOV
310
        $self = clone $this;
3✔
UNCOV
311
        $self->formats = $formats;
3✔
312

UNCOV
313
        return $self;
3✔
314
    }
315

316
    public function getInputFormats()
317
    {
UNCOV
318
        return $this->inputFormats;
944✔
319
    }
320

321
    public function withInputFormats($inputFormats = null): self
322
    {
UNCOV
323
        $self = clone $this;
34✔
UNCOV
324
        $self->inputFormats = $inputFormats;
34✔
325

UNCOV
326
        return $self;
34✔
327
    }
328

329
    public function getOutputFormats()
330
    {
UNCOV
331
        return $this->outputFormats;
1,850✔
332
    }
333

334
    public function withOutputFormats($outputFormats = null): self
335
    {
UNCOV
336
        $self = clone $this;
34✔
UNCOV
337
        $self->outputFormats = $outputFormats;
34✔
338

UNCOV
339
        return $self;
34✔
340
    }
341

342
    public function getUriVariables()
343
    {
UNCOV
344
        return $this->uriVariables;
2,150✔
345
    }
346

347
    public function withUriVariables($uriVariables): self
348
    {
UNCOV
349
        $self = clone $this;
34✔
UNCOV
350
        $self->uriVariables = $uriVariables;
34✔
351

UNCOV
352
        return $self;
34✔
353
    }
354

355
    public function getRoutePrefix(): ?string
356
    {
UNCOV
357
        return $this->routePrefix;
72✔
358
    }
359

360
    public function withRoutePrefix(string $routePrefix): self
361
    {
UNCOV
362
        $self = clone $this;
4✔
UNCOV
363
        $self->routePrefix = $routePrefix;
4✔
364

UNCOV
365
        return $self;
4✔
366
    }
367

368
    public function getRouteName(): ?string
369
    {
UNCOV
370
        return $this->routeName;
2,048✔
371
    }
372

373
    public function withRouteName(?string $routeName): self
374
    {
375
        $self = clone $this;
×
376
        $self->routeName = $routeName;
×
377

378
        return $self;
×
379
    }
380

381
    public function getDefaults(): ?array
382
    {
UNCOV
383
        return $this->defaults;
72✔
384
    }
385

386
    public function withDefaults(array $defaults): self
387
    {
388
        $self = clone $this;
×
389
        $self->defaults = $defaults;
×
390

391
        return $self;
×
392
    }
393

394
    public function getRequirements(): ?array
395
    {
UNCOV
396
        return $this->requirements;
72✔
397
    }
398

399
    public function withRequirements(array $requirements): self
400
    {
401
        $self = clone $this;
×
402
        $self->requirements = $requirements;
×
403

404
        return $self;
×
405
    }
406

407
    public function getOptions(): ?array
408
    {
UNCOV
409
        return $this->options;
72✔
410
    }
411

412
    public function withOptions(array $options): self
413
    {
414
        $self = clone $this;
×
415
        $self->options = $options;
×
416

417
        return $self;
×
418
    }
419

420
    public function getStateless(): ?bool
421
    {
UNCOV
422
        return $this->stateless;
72✔
423
    }
424

425
    public function withStateless($stateless): self
426
    {
427
        $self = clone $this;
×
428
        $self->stateless = $stateless;
×
429

430
        return $self;
×
431
    }
432

433
    public function getSunset(): ?string
434
    {
UNCOV
435
        return $this->sunset;
1,826✔
436
    }
437

438
    public function withSunset(string $sunset): self
439
    {
UNCOV
440
        $self = clone $this;
3✔
UNCOV
441
        $self->sunset = $sunset;
3✔
442

UNCOV
443
        return $self;
3✔
444
    }
445

446
    public function getAcceptPatch(): ?string
447
    {
UNCOV
448
        return $this->acceptPatch;
1,826✔
449
    }
450

451
    public function withAcceptPatch(string $acceptPatch): self
452
    {
UNCOV
453
        $self = clone $this;
24✔
UNCOV
454
        $self->acceptPatch = $acceptPatch;
24✔
455

UNCOV
456
        return $self;
24✔
457
    }
458

459
    public function getStatus(): ?int
460
    {
UNCOV
461
        return $this->status;
2,129✔
462
    }
463

464
    public function withStatus(int $status): self
465
    {
UNCOV
466
        $self = clone $this;
245✔
UNCOV
467
        $self->status = $status;
245✔
468

UNCOV
469
        return $self;
245✔
470
    }
471

472
    public function getHost(): ?string
473
    {
UNCOV
474
        return $this->host;
72✔
475
    }
476

477
    public function withHost(string $host): self
478
    {
479
        $self = clone $this;
×
480
        $self->host = $host;
×
481

482
        return $self;
×
483
    }
484

485
    public function getSchemes(): ?array
486
    {
UNCOV
487
        return $this->schemes;
72✔
488
    }
489

490
    public function withSchemes(array $schemes): self
491
    {
492
        $self = clone $this;
×
493
        $self->schemes = $schemes;
×
494

495
        return $self;
×
496
    }
497

498
    public function getCondition(): ?string
499
    {
UNCOV
500
        return $this->condition;
72✔
501
    }
502

503
    public function withCondition(string $condition): self
504
    {
505
        $self = clone $this;
×
506
        $self->condition = $condition;
×
507

508
        return $self;
×
509
    }
510

511
    public function getController(): ?string
512
    {
UNCOV
513
        return $this->controller;
76✔
514
    }
515

516
    public function withController(string $controller): self
517
    {
UNCOV
518
        $self = clone $this;
33✔
UNCOV
519
        $self->controller = $controller;
33✔
520

UNCOV
521
        return $self;
33✔
522
    }
523

524
    public function getHeaders(): ?array
525
    {
UNCOV
526
        return $this->headers;
1,826✔
527
    }
528

529
    public function withHeaders(array $headers): self
530
    {
UNCOV
531
        $self = clone $this;
3✔
UNCOV
532
        $self->headers = $headers;
3✔
533

UNCOV
534
        return $self;
3✔
535
    }
536

537
    public function getCacheHeaders(): ?array
538
    {
UNCOV
539
        return $this->cacheHeaders;
1,135✔
540
    }
541

542
    public function withCacheHeaders(array $cacheHeaders): self
543
    {
UNCOV
544
        $self = clone $this;
34✔
UNCOV
545
        $self->cacheHeaders = $cacheHeaders;
34✔
546

UNCOV
547
        return $self;
34✔
548
    }
549

550
    public function getPaginationViaCursor(): ?array
551
    {
UNCOV
552
        return $this->paginationViaCursor;
362✔
553
    }
554

555
    public function withPaginationViaCursor(array $paginationViaCursor): self
556
    {
UNCOV
557
        $self = clone $this;
3✔
UNCOV
558
        $self->paginationViaCursor = $paginationViaCursor;
3✔
559

UNCOV
560
        return $self;
3✔
561
    }
562

563
    public function getHydraContext(): ?array
564
    {
UNCOV
565
        return $this->hydraContext;
46✔
566
    }
567

568
    public function withHydraContext(array $hydraContext): self
569
    {
UNCOV
570
        $self = clone $this;
3✔
UNCOV
571
        $self->hydraContext = $hydraContext;
3✔
572

UNCOV
573
        return $self;
3✔
574
    }
575

576
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
577
    {
UNCOV
578
        return $this->openapi;
70✔
579
    }
580

581
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): self
582
    {
UNCOV
583
        $self = clone $this;
5✔
UNCOV
584
        $self->openapi = $openapi;
5✔
585

UNCOV
586
        return $self;
5✔
587
    }
588

589
    public function getExceptionToStatus(): ?array
590
    {
UNCOV
591
        return $this->exceptionToStatus;
266✔
592
    }
593

594
    public function withExceptionToStatus(array $exceptionToStatus): self
595
    {
UNCOV
596
        $self = clone $this;
1✔
UNCOV
597
        $self->exceptionToStatus = $exceptionToStatus;
1✔
598

UNCOV
599
        return $self;
1✔
600
    }
601

602
    public function getLinks(): ?array
603
    {
UNCOV
604
        return $this->links;
1,842✔
605
    }
606

607
    /**
608
     * @param WebLink[] $links
609
     */
610
    public function withLinks(array $links): self
611
    {
612
        $self = clone $this;
×
613
        $self->links = $links;
×
614

615
        return $self;
×
616
    }
617
}
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