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

api-platform / core / 10330256390

10 Aug 2024 08:23AM UTC coverage: 7.643% (-0.2%) from 7.84%
10330256390

push

github

soyuka
docs: changelog v4.0.0-alpha.1

12368 of 161815 relevant lines covered (7.64%)

26.86 hits per line

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

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

257
    public function getMethod(): string
258
    {
259
        return $this->method;
2,819✔
260
    }
261

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

267
        return $self;
3✔
268
    }
269

270
    public function getUriTemplate(): ?string
271
    {
272
        return $this->uriTemplate;
2,681✔
273
    }
274

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

280
        return $self;
114✔
281
    }
282

283
    public function getTypes(): ?array
284
    {
285
        return $this->types;
2,267✔
286
    }
287

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

296
        return $self;
19✔
297
    }
298

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

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

309
        return $self;
6✔
310
    }
311

312
    public function getInputFormats()
313
    {
314
        return $this->inputFormats;
1,049✔
315
    }
316

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

322
        return $self;
106✔
323
    }
324

325
    public function getOutputFormats()
326
    {
327
        return $this->outputFormats;
2,225✔
328
    }
329

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

335
        return $self;
100✔
336
    }
337

338
    public function getUriVariables()
339
    {
340
        return $this->uriVariables;
2,612✔
341
    }
342

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

348
        return $self;
109✔
349
    }
350

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

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

361
        return $self;
7✔
362
    }
363

364
    public function getRouteName(): ?string
365
    {
366
        return $this->routeName;
2,464✔
367
    }
368

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

374
        return $self;
×
375
    }
376

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

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

387
        return $self;
6✔
388
    }
389

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

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

400
        return $self;
6✔
401
    }
402

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

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

413
        return $self;
3✔
414
    }
415

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

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

426
        return $self;
3✔
427
    }
428

429
    public function getSunset(): ?string
430
    {
431
        return $this->sunset;
2,180✔
432
    }
433

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

439
        return $self;
6✔
440
    }
441

442
    public function getAcceptPatch(): ?string
443
    {
444
        return $this->acceptPatch;
2,180✔
445
    }
446

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

452
        return $self;
45✔
453
    }
454

455
    public function getStatus(): ?int
456
    {
457
        return $this->status;
2,563✔
458
    }
459

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

465
        return $self;
320✔
466
    }
467

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

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

478
        return $self;
3✔
479
    }
480

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

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

491
        return $self;
3✔
492
    }
493

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

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

504
        return $self;
3✔
505
    }
506

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

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

517
        return $self;
83✔
518
    }
519

520
    public function getHeaders(): ?array
521
    {
522
        return $this->headers;
2,180✔
523
    }
524

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

530
        return $self;
3✔
531
    }
532

533
    public function getCacheHeaders(): ?array
534
    {
535
        return $this->cacheHeaders;
1,427✔
536
    }
537

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

543
        return $self;
100✔
544
    }
545

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

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

556
        return $self;
3✔
557
    }
558

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

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

569
        return $self;
3✔
570
    }
571

572
    public function getOpenapi(): bool|OpenApiOperation|Webhook|null
573
    {
574
        return $this->openapi;
163✔
575
    }
576

577
    public function withOpenapi(bool|OpenApiOperation|Webhook $openapi): self
578
    {
579
        $self = clone $this;
8✔
580
        $self->openapi = $openapi;
8✔
581

582
        return $self;
8✔
583
    }
584

585
    public function getExceptionToStatus(): ?array
586
    {
587
        return $this->exceptionToStatus;
395✔
588
    }
589

590
    public function withExceptionToStatus(array $exceptionToStatus): self
591
    {
592
        $self = clone $this;
1✔
593
        $self->exceptionToStatus = $exceptionToStatus;
1✔
594

595
        return $self;
1✔
596
    }
597

598
    public function getLinks(): ?array
599
    {
600
        return $this->links;
2,195✔
601
    }
602

603
    /**
604
     * @param WebLink[] $links
605
     */
606
    public function withLinks(array $links): self
607
    {
608
        $self = clone $this;
×
609
        $self->links = $links;
×
610

611
        return $self;
×
612
    }
613
}
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