Skip to content

Commit

Permalink
fix(metadata): reader should be nullable
Browse files Browse the repository at this point in the history
fixes #5371
  • Loading branch information
soyuka committed Jan 26, 2023
1 parent 67dcf62 commit cbe7355
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class AnnotationSubresourceMetadataFactory implements PropertyMetadataFact
private $reader;
private $decorated;

public function __construct(Reader $reader, PropertyMetadataFactoryInterface $decorated)
public function __construct(Reader $reader = null, PropertyMetadataFactoryInterface $decorated)
{
$this->reader = $reader;
$this->decorated = $decorated;
Expand All @@ -56,6 +56,10 @@ public function create(string $resourceClass, string $property, array $options =
return $this->updateMetadata($attributes[0]->newInstance(), $propertyMetadata, $resourceClass, $property);
}

if (!$this->reader) {
return $propertyMetadata;
}

$annotation = $this->reader->getPropertyAnnotation($reflectionProperty, ApiSubresource::class);
if ($annotation instanceof ApiSubresource) {
trigger_deprecation('api-platform/core', '2.7', sprintf('Declare a new resource instead of using ApiSubresource on the property "%s".', $property));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="api_platform.metadata.resource.name_collection_factory.annotation" decorates="api_platform.metadata.resource.name_collection_factory" class="ApiPlatform\Core\Metadata\Resource\Factory\AnnotationResourceNameCollectionFactory" public="false">
<argument type="service" id="annotation_reader" />
<argument type="service" id="annotation_reader" on-invalid="null" />
<argument>%api_platform.resource_class_directories%</argument>
<argument type="service" id="api_platform.metadata.resource.name_collection_factory.annotation.inner" />
</service>

<service id="api_platform.metadata.resource.metadata_factory.annotation" decorates="api_platform.metadata.resource.metadata_factory" decoration-priority="40" class="ApiPlatform\Core\Metadata\Resource\Factory\AnnotationResourceMetadataFactory" public="false">
<argument type="service" id="annotation_reader" />
<argument type="service" id="annotation_reader" on-invalid="null" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory.annotation.inner" />
<argument>%api_platform.defaults%</argument>
</service>

<service id="api_platform.metadata.resource.filter_metadata_factory.annotation" decorates="api_platform.metadata.resource.metadata_factory" decoration-priority="20" class="ApiPlatform\Core\Metadata\Resource\Factory\AnnotationResourceFilterMetadataFactory" public="false">
<argument type="service" id="annotation_reader" />
<argument type="service" id="annotation_reader" on-invalid="null" />
<argument type="service" id="api_platform.metadata.resource.filter_metadata_factory.annotation.inner" />
</service>

<service id="api_platform.metadata.subresource.metadata_factory.annotation.legacy" class="ApiPlatform\Core\Metadata\Property\Factory\AnnotationSubresourceMetadataFactory" decorates="api_platform.metadata.property.metadata_factory.legacy" decoration-priority="30" public="false">
<argument type="service" id="annotation_reader" />
<argument type="service" id="annotation_reader" on-invalid="null" />
<argument type="service" id="api_platform.metadata.subresource.metadata_factory.annotation.legacy.inner" />
</service>

<service id="api_platform.metadata.property.metadata_factory.annotation.legacy" class="ApiPlatform\Core\Metadata\Property\Factory\AnnotationPropertyMetadataFactory" decorates="api_platform.metadata.property.metadata_factory.legacy" decoration-priority="20" public="false">
<argument type="service" id="annotation_reader" />
<argument type="service" id="annotation_reader" on-invalid="null" />
<argument type="service" id="api_platform.metadata.property.metadata_factory.annotation.legacy.inner" />
</service>
</services>
Expand Down

0 comments on commit cbe7355

Please sign in to comment.