Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions src/Metadata/ApiProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,35 +105,35 @@ 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,
?bool $writableLink = null,
?bool $required = null,
?bool $identifier = null,

$default = null,
$example = null,
$default = null,
$example = null,

?string $deprecationReason = null,
?bool $fetchable = null,
Expand Down Expand Up @@ -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.');
Expand All @@ -479,13 +481,18 @@ 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;
}

/**
* Represents whether the property has a subresource.
*
* @deprecated since 2.7, to be removed in 3.0
*/
public function hasSubresource(): bool
{
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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)
Expand All @@ -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
{
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}()
) {
Expand Down