diff --git a/src/Metadata/ApiProperty.php b/src/Metadata/ApiProperty.php index 9e64682b58e..95f6061f4a9 100644 --- a/src/Metadata/ApiProperty.php +++ b/src/Metadata/ApiProperty.php @@ -105,26 +105,26 @@ final class ApiProperty private $extraProperties; /** - * @param string $description - * @param bool $readable - * @param bool $writable - * @param bool $readableLink - * @param bool $writableLink - * @param bool $required - * @param bool $identifier - * @param string|int|float|bool|array $default - * @param string|int|float|bool|array|null $example - * @param string $deprecationReason - * @param bool $fetchable - * @param bool $fetchEager - * @param array $jsonldContext - * @param array $openapiContext - * @param bool $push - * @param string $security - * @param string $securityPostDenormalize + * @param string $description + * @param bool $readable + * @param bool $writable + * @param bool $readableLink + * @param bool $writableLink + * @param bool $required + * @param bool $identifier + * @param string|int|float|bool|array $default + * @param string|int|float|bool|array $example + * @param string $deprecationReason + * @param bool $fetchable + * @param bool $fetchEager + * @param array $jsonldContext + * @param array $openapiContext + * @param bool $push + * @param string $security + * @param string $securityPostDenormalize */ public function __construct( - $description = null, + ?string $description = null, ?bool $readable = null, ?bool $writable = null, ?bool $readableLink = null, @@ -132,8 +132,8 @@ public function __construct( ?bool $required = null, ?bool $identifier = null, - $default = null, - $example = null, + $default = null, + $example = null, ?string $deprecationReason = null, ?bool $fetchable = null, @@ -469,7 +469,9 @@ public function withExtraProperties(array $extraProperties = []): self return $self; } - /** TODO: backward compatibility layer with previous PropertyMetadata to be removed in 3.0 */ + /** + * @deprecated since 2.7, to be removed in 3.0 + */ public function withSubresource(SubresourceMetadata $subresourceMetadata): self { trigger_deprecation('api-platform/core', '2.7', 'Declaring a subresource on a property is deprecated, use alternate URLs instead.'); @@ -479,6 +481,9 @@ public function withSubresource(SubresourceMetadata $subresourceMetadata): self return $self; } + /** + * @deprecated since 2.7, to be removed in 3.0 + */ public function getSubresource(): ?SubresourceMetadata { return $this->extraProperties['subresource'] ?? null; @@ -486,6 +491,8 @@ public function getSubresource(): ?SubresourceMetadata /** * Represents whether the property has a subresource. + * + * @deprecated since 2.7, to be removed in 3.0 */ public function hasSubresource(): bool { @@ -533,6 +540,8 @@ public function withChildInherited(string $childInherited): self /** * Gets IRI of this property. + * + * @deprecated since 2.7, to be removed in 3.0, use getTypes instead */ public function getIri(): ?string { @@ -541,6 +550,8 @@ public function getIri(): ?string /** * Returns a new instance with the given IRI. + * + * @deprecated since 2.7, to be removed in 3.0, use withTypes instead */ public function withIri(string $iri = null): self { @@ -555,6 +566,8 @@ public function withIri(string $iri = null): self /** * Gets an attribute. * + * @deprecated since 2.7, to be removed in 3.0, use getExtraProperties instead + * * @param mixed|null $defaultValue */ public function getAttribute(string $key, $defaultValue = null) @@ -576,6 +589,8 @@ public function getAttribute(string $key, $defaultValue = null) /** * Gets attributes. + * + * @deprecated since 2.7, to be removed in 3.0, renamed as getExtraProperties */ public function getAttributes(): ?array { @@ -584,9 +599,13 @@ public function getAttributes(): ?array /** * Returns a new instance with the given attribute. + * + * @deprecated since 2.7, to be removed in 3.0, renamed as withExtraProperties */ public function withAttributes(array $attributes): self { + trigger_deprecation('api-platform/core', '2.7', sprintf('"%s::%s" is deprecated since 2.7 and will be removed in 3.0.', __CLASS__, __METHOD__)); + $metadata = clone $this; return $this->withDeprecatedAttributes($metadata, $attributes); diff --git a/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php b/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php index 8d94d2f7845..c1a2d26ad56 100644 --- a/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php +++ b/src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php @@ -104,8 +104,14 @@ private function createMetadata(ApiProperty $attribute, ApiProperty $propertyMet foreach (get_class_methods(ApiProperty::class) as $method) { if ( + // TODO: remove these checks for deprecated methods in 3.0 'getAttribute' !== $method && 'isChildInherited' !== $method && + 'getSubresource' !== $method && + 'getIri' !== $method && + 'getAttributes' !== $method && + // end of deprecated methods + preg_match('/^(?:get|is)(.*)/', $method, $matches) && null !== $val = $attribute->{$method}() ) {