13
13
14
14
namespace ApiPlatform \Metadata ;
15
15
16
- use ApiPlatform \Core \Metadata \Property \SubresourceMetadata ;
17
- use ApiPlatform \Metadata \Property \DeprecationMetadataTrait ;
18
16
use Symfony \Component \PropertyInfo \Type ;
19
- use Symfony \Component \Serializer \NameConverter \CamelCaseToSnakeCaseNameConverter ;
20
17
21
18
/**
22
19
* ApiProperty annotation.
26
23
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::TARGET_PARAMETER )]
27
24
final class ApiProperty
28
25
{
29
- use DeprecationMetadataTrait;
30
-
31
26
/**
32
27
* @var string
33
28
*/
@@ -96,27 +91,29 @@ final class ApiProperty
96
91
97
92
private $ schema ;
98
93
private $ initializable ;
94
+ private $ iri ;
99
95
100
96
/**
101
97
* @var array
102
98
*/
103
99
private $ extraProperties ;
104
100
105
101
/**
106
- * @param bool|null $readableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
107
- * @param bool|null $writableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
108
- * @param bool|null $required https://api-platform.com/docs/admin/validation/#client-side-validation
109
- * @param bool|null $identifier https://api-platform.com/docs/core/identifiers/
110
- * @param string|null $default
111
- * @param string|null $example https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
112
- * @param string|null $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
113
- * @param bool|null $fetchEager https://api-platform.com/docs/core/performance/#eager-loading
114
- * @param array|null $jsonldContext https://api-platform.com/docs/core/extending-jsonld-context/#extending-json-ld-and-hydra-contexts
115
- * @param array|null $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
116
- * @param bool|null $push https://api-platform.com/docs/core/push-relations/
117
- * @param string|null $security https://api-platform.com/docs/core/security
118
- * @param string|null $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
119
- * @param array|null $types the RDF types of this property
102
+ * @param bool|null $readableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
103
+ * @param bool|null $writableLink https://api-platform.com/docs/core/serialization/#force-iri-with-relations-of-the-same-type-parentchilds-relations
104
+ * @param bool|null $required https://api-platform.com/docs/admin/validation/#client-side-validation
105
+ * @param bool|null $identifier https://api-platform.com/docs/core/identifiers/
106
+ * @param string|null $default
107
+ * @param string|null $example https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
108
+ * @param string|null $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
109
+ * @param bool|null $fetchEager https://api-platform.com/docs/core/performance/#eager-loading
110
+ * @param array|null $jsonldContext https://api-platform.com/docs/core/extending-jsonld-context/#extending-json-ld-and-hydra-contexts
111
+ * @param array|null $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
112
+ * @param bool|null $push https://api-platform.com/docs/core/push-relations/
113
+ * @param string|null $security https://api-platform.com/docs/core/security
114
+ * @param string|null $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
115
+ * @param array|null $types the RDF types of this property
116
+ * @param bool|string|null $iri the IRI representing the property, can be `false` to remove the generated "@id"
120
117
*/
121
118
public function __construct (
122
119
?string $ description = null ,
@@ -144,6 +141,8 @@ public function __construct(
144
141
?array $ schema = null ,
145
142
?bool $ initializable = null ,
146
143
144
+ $ iri = null ,
145
+
147
146
// attributes
148
147
array $ extraProperties = []
149
148
) {
@@ -169,6 +168,7 @@ public function __construct(
169
168
$ this ->builtinTypes = $ builtinTypes ;
170
169
$ this ->schema = $ schema ;
171
170
$ this ->initializable = $ initializable ;
171
+ $ this ->iri = $ iri ;
172
172
$ this ->extraProperties = $ extraProperties ;
173
173
}
174
174
@@ -467,169 +467,23 @@ public function withExtraProperties(array $extraProperties = []): self
467
467
return $ self ;
468
468
}
469
469
470
- /**
471
- * @deprecated since 2.7, to be removed in 3.0
472
- */
473
- public function withSubresource (SubresourceMetadata $ subresourceMetadata ): self
474
- {
475
- trigger_deprecation ('api-platform/core ' , '2.7 ' , 'Declaring a subresource on a property is deprecated, use alternate URLs instead. ' );
476
- $ self = clone $ this ;
477
- $ self ->extraProperties ['subresource ' ] = $ subresourceMetadata ;
478
-
479
- return $ self ;
480
- }
481
-
482
- /**
483
- * @deprecated since 2.7, to be removed in 3.0
484
- */
485
- public function getSubresource (): ?SubresourceMetadata
486
- {
487
- return $ this ->extraProperties ['subresource ' ] ?? null ;
488
- }
489
-
490
- /**
491
- * Represents whether the property has a subresource.
492
- *
493
- * @deprecated since 2.7, to be removed in 3.0
494
- */
495
- public function hasSubresource (): bool
496
- {
497
- return isset ($ this ->extraProperties ['subresource ' ]);
498
- }
499
-
500
- /**
501
- * @deprecated since 2.6, to be removed in 3.0
502
- */
503
- public function getChildInherited (): ?string
504
- {
505
- return $ this ->extraProperties ['childInherited ' ] ?? null ;
506
- }
507
-
508
- /**
509
- * @deprecated since 2.6, to be removed in 3.0
510
- */
511
- public function hasChildInherited (): bool
512
- {
513
- return isset ($ this ->extraProperties ['childInherited ' ]);
514
- }
515
-
516
- /**
517
- * @deprecated since 2.4, to be removed in 3.0
518
- */
519
- public function isChildInherited (): ?string
520
- {
521
- trigger_deprecation ('api-platform/core ' , '2.4 ' , sprintf ('"%s::%s" is deprecated since 2.4 and will be removed in 3.0. ' , __CLASS__ , __METHOD__ ));
522
-
523
- return $ this ->getChildInherited ();
524
- }
525
-
526
- /**
527
- * @deprecated since 2.6, to be removed in 3.0
528
- */
529
- public function withChildInherited (string $ childInherited ): self
530
- {
531
- trigger_deprecation ('api-platform/core ' , '2.6 ' , sprintf ('"%s::%s" is deprecated since 2.6 and will be removed in 3.0. ' , __CLASS__ , __METHOD__ ));
532
-
533
- $ metadata = clone $ this ;
534
- $ metadata ->extraProperties ['childInherited ' ] = $ childInherited ;
535
-
536
- return $ metadata ;
537
- }
538
-
539
470
/**
540
471
* Gets IRI of this property.
541
- *
542
- * @deprecated since 2.7, to be removed in 3.0, use getTypes instead
543
472
*/
544
- public function getIri (): ? string
473
+ public function getIri ()
545
474
{
546
- return $ this ->types [ 0 ] ?? null ;
475
+ return $ this ->iri ;
547
476
}
548
477
549
478
/**
550
479
* Returns a new instance with the given IRI.
551
480
*
552
- * @deprecated since 2.7, to be removed in 3.0, use withTypes instead
553
- */
554
- public function withIri (string $ iri = null ): self
555
- {
556
- trigger_deprecation ('api-platform/core ' , '2.7 ' , sprintf ('"%s::%s" is deprecated since 2.7 and will be removed in 3.0, use Type instead. ' , __CLASS__ , __METHOD__ ));
557
-
558
- $ metadata = clone $ this ;
559
- $ metadata ->types = [$ iri ];
560
-
561
- return $ metadata ;
562
- }
563
-
564
- /**
565
- * Gets an attribute.
566
- *
567
- * @deprecated since 2.7, to be removed in 3.0, use getExtraProperties instead
568
- *
569
- * @param mixed|null $defaultValue
481
+ * @param mixed $iri
570
482
*/
571
- public function getAttribute ( string $ key , $ defaultValue = null )
483
+ public function withIri ( $ iri ): self
572
484
{
573
- trigger_deprecation ('api-platform/core ' , '2.7 ' , sprintf ('"%s::%s" is deprecated since 2.7 and will be removed in 3.0. ' , __CLASS__ , __METHOD__ ));
574
-
575
- if (!$ this ->camelCaseToSnakeCaseNameConverter ) {
576
- $ this ->camelCaseToSnakeCaseNameConverter = new CamelCaseToSnakeCaseNameConverter ();
577
- }
578
-
579
- $ propertyName = $ this ->camelCaseToSnakeCaseNameConverter ->denormalize ($ key );
580
-
581
- if (isset ($ this ->{$ propertyName })) {
582
- return $ this ->{$ propertyName } ?? $ defaultValue ;
583
- }
584
-
585
- return $ this ->extraProperties [$ key ] ?? $ defaultValue ;
586
- }
587
-
588
- /**
589
- * Gets attributes.
590
- *
591
- * @deprecated since 2.7, to be removed in 3.0, renamed as getExtraProperties
592
- */
593
- public function getAttributes (): ?array
594
- {
595
- return $ this ->extraProperties ;
596
- }
597
-
598
- /**
599
- * Returns a new instance with the given attribute.
600
- *
601
- * @deprecated since 2.7, to be removed in 3.0, renamed as withExtraProperties
602
- */
603
- public function withAttributes (array $ attributes ): self
604
- {
605
- trigger_deprecation ('api-platform/core ' , '2.7 ' , sprintf ('"%s::%s" is deprecated since 2.7 and will be removed in 3.0. ' , __CLASS__ , __METHOD__ ));
606
-
607
- $ metadata = clone $ this ;
608
-
609
- return $ this ->withDeprecatedAttributes ($ metadata , $ attributes );
610
- }
611
-
612
- /**
613
- * Gets type.
614
- *
615
- * @deprecated since 2.7, to be removed in 3.0, renamed as getBuiltinTypes
616
- */
617
- public function getType (): ?Type
618
- {
619
- return $ this ->builtinTypes [0 ] ?? null ;
620
- }
621
-
622
- /**
623
- * Returns a new instance with the given type.
624
- *
625
- * @deprecated since 2.7, to be removed in 3.0, renamed as withBuiltinTypes
626
- */
627
- public function withType (Type $ type ): self
628
- {
629
- trigger_deprecation ('api-platform/core ' , '2.7 ' , sprintf ('"%s::%s" is deprecated since 2.7 and will be removed in 3.0, use builtinTypes instead. ' , __CLASS__ , __METHOD__ ));
630
-
631
485
$ metadata = clone $ this ;
632
- $ metadata ->builtinTypes = [ $ type ] ;
486
+ $ metadata ->iri = $ iri ;
633
487
634
488
return $ metadata ;
635
489
}
0 commit comments