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

api-platform / core / 10972064847

21 Sep 2024 11:06AM UTC coverage: 7.462% (-0.4%) from 7.833%
10972064847

push

github

web-flow
fix(laravel): installation command, fix config overwrites (#6649)

added the installation command, but as a bug fix since configs are currently getting overwritten.

Closes: #6645

0 of 9 new or added lines in 2 files covered. (0.0%)

307 existing lines in 30 files now uncovered.

12303 of 164886 relevant lines covered (7.46%)

27.02 hits per line

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

91.23
/src/Metadata/ApiProperty.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 Symfony\Component\PropertyInfo\Type;
17

18
/**
19
 * ApiProperty annotation.
20
 *
21
 * @author Kévin Dunglas <dunglas@gmail.com>
22
 */
23
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT | \Attribute::TARGET_CLASS)]
24
final class ApiProperty
25
{
26
    /**
27
     * @param bool|null               $readableLink            https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
28
     * @param bool|null               $writableLink            https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
29
     * @param bool|null               $required                https://api-platform.com/docs/admin/validation/#client-side-validation
30
     * @param bool|null               $identifier              https://api-platform.com/docs/core/identifiers/
31
     * @param mixed                   $example                 https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
32
     * @param string|null             $deprecationReason       https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
33
     * @param bool|null               $fetchEager              https://api-platform.com/docs/core/performance/#eager-loading
34
     * @param array|null              $jsonldContext           https://api-platform.com/docs/core/extending-jsonld-context/#extending-json-ld-and-hydra-contexts
35
     * @param array|null              $openapiContext          https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
36
     * @param bool|null               $push                    https://api-platform.com/docs/core/push-relations/
37
     * @param string|\Stringable|null $security                https://api-platform.com/docs/core/security
38
     * @param string|\Stringable|null $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
39
     * @param string[]                $types                   the RDF types of this property
40
     * @param string[]                $iris
41
     * @param Type[]                  $builtinTypes
42
     * @param string|null             $uriTemplate             (experimental) whether to return the subRessource collection IRI instead of an iterable of IRI
43
     * @param string|null             $property                The property name
44
     */
45
    public function __construct(
46
        private ?string $description = null,
47
        private ?bool $readable = null,
48
        private ?bool $writable = null,
49
        private ?bool $readableLink = null,
50
        private ?bool $writableLink = null,
51
        private ?bool $required = null,
52
        private ?bool $identifier = null,
53
        private mixed $default = null,
54
        private mixed $example = null,
55
        /**
56
         * The `deprecationReason` option deprecates the current operation with a deprecation message.
57
         *
58
         * <div data-code-selector>
59
         *
60
         * ```php
61
         * <?php
62
         * // api/src/Entity/Review.php
63
         * use ApiPlatform\Metadata\ApiProperty;
64
         * use ApiPlatform\Metadata\ApiResource;
65
         *
66
         * #[ApiResource]
67
         * class Review
68
         * {
69
         *     #[ApiProperty(deprecationReason: "Use the rating property instead")]
70
         *     public string $letter;
71
         * }
72
         * ```
73
         *
74
         * ```yaml
75
         * # api/config/api_platform/properties.yaml
76
         * properties:
77
         *     App\Entity\Review:
78
         *         letter:
79
         *             deprecationReason: 'Create a Book instead'
80
         * ```
81
         *
82
         * ```xml
83
         * <?xml version="1.0" encoding="UTF-8" ?>
84
         * <!-- api/config/api_platform/properties.xml -->
85
         *
86
         * <properties
87
         *         xmlns="https://api-platform.com/schema/metadata/properties-3.0"
88
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
89
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0
90
         *         https://api-platform.com/schema/metadata/properties-3.0.xsd">
91
         *     <property resource="App\Entity\Review" name="letter" deprecationReason="Create a Book instead" />
92
         * </properties>
93
         * ```
94
         *
95
         * </div>
96
         *
97
         * - With JSON-lD / Hydra, [an `owl:deprecated` annotation property](https://www.w3.org/TR/owl2-syntax/#Annotation_Properties) will be added to the appropriate data structure
98
         * - With Swagger / OpenAPI, [a `deprecated` property](https://swagger.io/docs/specification/2-0/paths-and-operations/) will be added
99
         * - With GraphQL, the [`isDeprecated` and `deprecationReason` properties](https://facebook.github.io/graphql/June2018/#sec-Deprecation) will be added to the schema
100
         */
101
        private ?string $deprecationReason = null,
102
        private ?bool $fetchable = null,
103
        private ?bool $fetchEager = null,
104
        private ?array $jsonldContext = null,
105
        private ?array $openapiContext = null,
106
        private ?array $jsonSchemaContext = null,
107
        private ?bool $push = null,
108
        /**
109
         * The `security` option defines the access to the current property, on normalization process, based on Symfony Security.
110
         * It receives an `object` variable related to the current object, and a `property` variable related to the current property.
111
         *
112
         * <div data-code-selector>
113
         *
114
         * ```php
115
         * <?php
116
         * // api/src/Entity/Review.php
117
         * use ApiPlatform\Metadata\ApiProperty;
118
         * use ApiPlatform\Metadata\ApiResource;
119
         *
120
         * #[ApiResource]
121
         * class Review
122
         * {
123
         *     #[ApiProperty(security: 'is_granted("ROLE_ADMIN")')]
124
         *     public string $letter;
125
         * }
126
         * ```
127
         *
128
         * ```yaml
129
         * # api/config/api_platform/properties.yaml
130
         * properties:
131
         *     App\Entity\Review:
132
         *         letter:
133
         *             security: 'is_granted("ROLE_ADMIN")'
134
         * ```
135
         *
136
         * ```xml
137
         * <?xml version="1.0" encoding="UTF-8" ?>
138
         * <!-- api/config/api_platform/properties.xml -->
139
         *
140
         * <properties
141
         *         xmlns="https://api-platform.com/schema/metadata/properties-3.0"
142
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
143
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0
144
         *         https://api-platform.com/schema/metadata/properties-3.0.xsd">
145
         *     <property resource="App\Entity\Review" name="letter" security="is_granted('ROLE_ADMIN')" />
146
         * </properties>
147
         * ```
148
         *
149
         * </div>
150
         */
151
        private string|\Stringable|null $security = null,
152
        /**
153
         * The `securityPostDenormalize` option defines access to the current property after the denormalization process, based on Symfony Security.
154
         * It receives an `object` variable related to the current object, and a `property` variable related to the current property.
155
         *
156
         * <div data-code-selector>
157
         *
158
         * ```php
159
         * <?php
160
         * // api/src/Entity/Review.php
161
         * use ApiPlatform\Metadata\ApiProperty;
162
         * use ApiPlatform\Metadata\ApiResource;
163
         *
164
         * #[ApiResource]
165
         * class Review
166
         * {
167
         *     #[ApiProperty(securityPostDenormalize: 'is_granted("ROLE_ADMIN")')]
168
         *     public string $letter;
169
         * }
170
         * ```
171
         *
172
         * ```yaml
173
         * # api/config/api_platform/properties.yaml
174
         * properties:
175
         *     App\Entity\Review:
176
         *         letter:
177
         *             securityPostDenormalize: 'is_granted("ROLE_ADMIN")'
178
         * ```
179
         *
180
         * ```xml
181
         * <?xml version="1.0" encoding="UTF-8" ?>
182
         * <!-- api/config/api_platform/properties.xml -->
183
         *
184
         * <properties
185
         *         xmlns="https://api-platform.com/schema/metadata/properties-3.0"
186
         *         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
187
         *         xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0
188
         *         https://api-platform.com/schema/metadata/properties-3.0.xsd">
189
         *     <property resource="App\Entity\Review" name="letter" securityPostDenormalize="is_granted('ROLE_ADMIN')" />
190
         * </properties>
191
         * ```
192
         *
193
         * </div>
194
         */
195
        private string|\Stringable|null $securityPostDenormalize = null,
196
        private array|string|null $types = null,
197
        /*
198
         * The related php types.
199
         */
200
        private ?array $builtinTypes = null,
201
        private ?array $schema = null,
202
        private ?bool $initializable = null,
203
        private $iris = null,
204
        private ?bool $genId = null,
205
        private ?string $uriTemplate = null,
206
        private ?string $property = null,
207
        private ?string $policy = null,
208
        private array $extraProperties = [],
209
    ) {
210
        if (\is_string($types)) {
838✔
211
            $this->types = (array) $types;
×
212
        }
213
    }
214

215
    public function getProperty(): ?string
216
    {
217
        return $this->property;
190✔
218
    }
219

220
    public function withProperty(string $property): self
221
    {
222
        $self = clone $this;
×
223
        $self->property = $property;
×
224

225
        return $self;
×
226
    }
227

228
    public function getDescription(): ?string
229
    {
230
        return $this->description;
1,007✔
231
    }
232

233
    public function withDescription(string $description): self
234
    {
235
        $self = clone $this;
286✔
236
        $self->description = $description;
286✔
237

238
        return $self;
286✔
239
    }
240

241
    public function isReadable(): ?bool
242
    {
243
        return $this->readable;
2,429✔
244
    }
245

246
    public function withReadable(bool $readable): self
247
    {
248
        $self = clone $this;
742✔
249
        $self->readable = $readable;
742✔
250

251
        return $self;
742✔
252
    }
253

254
    public function isWritable(): ?bool
255
    {
256
        return $this->writable;
1,290✔
257
    }
258

259
    public function withWritable(bool $writable): self
260
    {
261
        $self = clone $this;
733✔
262
        $self->writable = $writable;
733✔
263

264
        return $self;
733✔
265
    }
266

267
    public function isReadableLink(): ?bool
268
    {
269
        return $this->readableLink;
1,058✔
270
    }
271

272
    public function withReadableLink(bool $readableLink): self
273
    {
274
        $self = clone $this;
311✔
275
        $self->readableLink = $readableLink;
311✔
276

277
        return $self;
311✔
278
    }
279

280
    public function isWritableLink(): ?bool
281
    {
282
        return $this->writableLink;
441✔
283
    }
284

285
    public function withWritableLink(bool $writableLink): self
286
    {
287
        $self = clone $this;
308✔
288
        $self->writableLink = $writableLink;
308✔
289

290
        return $self;
308✔
291
    }
292

293
    public function isRequired(): ?bool
294
    {
295
        return $this->required;
1,135✔
296
    }
297

298
    public function withRequired(bool $required): self
299
    {
300
        $self = clone $this;
814✔
301
        $self->required = $required;
814✔
302

303
        return $self;
814✔
304
    }
305

306
    public function isIdentifier(): ?bool
307
    {
308
        return $this->identifier;
766✔
309
    }
310

311
    public function withIdentifier(bool $identifier): self
312
    {
313
        $self = clone $this;
543✔
314
        $self->identifier = $identifier;
543✔
315

316
        return $self;
543✔
317
    }
318

319
    public function getDefault()
320
    {
321
        return $this->default;
679✔
322
    }
323

324
    public function withDefault($default): self
325
    {
326
        $self = clone $this;
328✔
327
        $self->default = $default;
328✔
328

329
        return $self;
328✔
330
    }
331

332
    public function getExample(): mixed
333
    {
334
        return $this->example;
676✔
335
    }
336

337
    public function withExample(mixed $example): self
338
    {
339
        $self = clone $this;
12✔
340
        $self->example = $example;
12✔
341

342
        return $self;
12✔
343
    }
344

345
    public function getDeprecationReason(): ?string
346
    {
347
        return $this->deprecationReason;
1,007✔
348
    }
349

350
    public function withDeprecationReason($deprecationReason): self
351
    {
352
        $self = clone $this;
39✔
353
        $self->deprecationReason = $deprecationReason;
39✔
354

355
        return $self;
39✔
356
    }
357

358
    public function isFetchable(): ?bool
359
    {
360
        return $this->fetchable;
190✔
361
    }
362

363
    public function withFetchable($fetchable): self
364
    {
365
        $self = clone $this;
×
366
        $self->fetchable = $fetchable;
×
367

368
        return $self;
×
369
    }
370

371
    public function getFetchEager(): ?bool
372
    {
373
        return $this->fetchEager;
329✔
374
    }
375

376
    public function withFetchEager($fetchEager): self
377
    {
378
        $self = clone $this;
4✔
379
        $self->fetchEager = $fetchEager;
4✔
380

381
        return $self;
4✔
382
    }
383

384
    public function getJsonldContext(): ?array
385
    {
386
        return $this->jsonldContext;
331✔
387
    }
388

389
    public function withJsonldContext($jsonldContext): self
390
    {
391
        $self = clone $this;
21✔
392
        $self->jsonldContext = $jsonldContext;
21✔
393

394
        return $self;
21✔
395
    }
396

397
    public function getOpenapiContext(): ?array
398
    {
399
        return $this->openapiContext;
676✔
400
    }
401

402
    public function withOpenapiContext($openapiContext): self
403
    {
404
        $self = clone $this;
15✔
405
        $self->openapiContext = $openapiContext;
15✔
406

407
        return $self;
15✔
408
    }
409

410
    public function getJsonSchemaContext(): ?array
411
    {
412
        return $this->jsonSchemaContext;
265✔
413
    }
414

415
    public function withJsonSchemaContext($jsonSchemaContext): self
416
    {
417
        $self = clone $this;
24✔
418
        $self->jsonSchemaContext = $jsonSchemaContext;
24✔
419

420
        return $self;
24✔
421
    }
422

423
    public function getPush(): ?bool
424
    {
425
        return $this->push;
410✔
426
    }
427

428
    public function withPush($push): self
429
    {
430
        $self = clone $this;
14✔
431
        $self->push = $push;
14✔
432

433
        return $self;
14✔
434
    }
435

436
    public function getSecurity(): ?string
437
    {
438
        return $this->security instanceof \Stringable ? (string) $this->security : $this->security;
2,315✔
439
    }
440

441
    public function withSecurity($security): self
442
    {
443
        $self = clone $this;
18✔
444
        $self->security = $security;
18✔
445

446
        return $self;
18✔
447
    }
448

449
    public function getSecurityPostDenormalize(): ?string
450
    {
451
        return $this->securityPostDenormalize instanceof \Stringable ? (string) $this->securityPostDenormalize : $this->securityPostDenormalize;
717✔
452
    }
453

454
    public function withSecurityPostDenormalize($securityPostDenormalize): self
455
    {
456
        $self = clone $this;
20✔
457
        $self->securityPostDenormalize = $securityPostDenormalize;
20✔
458

459
        return $self;
20✔
460
    }
461

462
    public function getTypes(): ?array
463
    {
464
        return $this->types;
814✔
465
    }
466

467
    /**
468
     * @param string[]|string $types
469
     */
470
    public function withTypes(array|string $types = []): self
471
    {
472
        $self = clone $this;
100✔
473
        $self->types = (array) $types;
100✔
474

475
        return $self;
100✔
476
    }
477

478
    /**
479
     * @return Type[]
480
     */
481
    public function getBuiltinTypes(): ?array
482
    {
483
        return $this->builtinTypes;
2,679✔
484
    }
485

486
    /**
487
     * @param Type[] $builtinTypes
488
     */
489
    public function withBuiltinTypes(array $builtinTypes = []): self
490
    {
491
        $self = clone $this;
763✔
492
        $self->builtinTypes = $builtinTypes;
763✔
493

494
        return $self;
763✔
495
    }
496

497
    public function getSchema(): ?array
498
    {
499
        return $this->schema;
931✔
500
    }
501

502
    public function withSchema(array $schema = []): self
503
    {
504
        $self = clone $this;
790✔
505
        $self->schema = $schema;
790✔
506

507
        return $self;
790✔
508
    }
509

510
    public function withInitializable(?bool $initializable): self
511
    {
512
        $self = clone $this;
676✔
513
        $self->initializable = $initializable;
676✔
514

515
        return $self;
676✔
516
    }
517

518
    public function isInitializable(): ?bool
519
    {
520
        return $this->initializable;
1,105✔
521
    }
522

523
    public function getExtraProperties(): ?array
524
    {
525
        return $this->extraProperties;
1,034✔
526
    }
527

528
    public function withExtraProperties(array $extraProperties = []): self
529
    {
530
        $self = clone $this;
205✔
531
        $self->extraProperties = $extraProperties;
205✔
532

533
        return $self;
205✔
534
    }
535

536
    /**
537
     * Gets IRI of this property.
538
     */
539
    public function getIris()
540
    {
541
        return $this->iris;
331✔
542
    }
543

544
    /**
545
     * Returns a new instance with the given IRI.
546
     *
547
     * @param string|string[] $iris
548
     */
549
    public function withIris(string|array $iris): self
550
    {
551
        $metadata = clone $this;
41✔
552
        $metadata->iris = (array) $iris;
41✔
553

554
        return $metadata;
41✔
555
    }
556

557
    /**
558
     * Whether to generate a skolem iri on anonymous resources.
559
     */
560
    public function getGenId()
561
    {
562
        return $this->genId;
1,016✔
563
    }
564

565
    public function withGenId(bool $genId): self
566
    {
567
        $metadata = clone $this;
13✔
568
        $metadata->genId = $genId;
13✔
569

570
        return $metadata;
13✔
571
    }
572

573
    /**
574
     * Whether to return the subRessource collection IRI instead of an iterable of IRI.
575
     *
576
     * @experimental
577
     */
578
    public function getUriTemplate(): ?string
579
    {
580
        return $this->uriTemplate;
1,414✔
581
    }
582

583
    public function withUriTemplate(?string $uriTemplate): self
584
    {
UNCOV
585
        $metadata = clone $this;
15✔
UNCOV
586
        $metadata->uriTemplate = $uriTemplate;
15✔
587

UNCOV
588
        return $metadata;
15✔
589
    }
590

591
    public function getPolicy(): ?string
592
    {
593
        return $this->policy;
2,217✔
594
    }
595

596
    public function withPolicy(?string $policy): static
597
    {
598
        $self = clone $this;
×
599
        $self->policy = $policy;
×
600

601
        return $self;
×
602
    }
603
}
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