I want to upgrade my api which currently uses PHP8.1, Symfony 6.1 and Api-Platform 2.6 to Api-Platform 3.0.
So I first upgraded to Api-Platform 2.7 and switched the metadata_backward_compatibility_layer flag to false.
All “getCollection” are in error now while all other endpoints are working normally.
The exception thrown is ApiPlatformExceptionResourceClassNotFoundException with the following message: Resource “AppEntityRatingAttribute” not found.
Here is the entity in question:
<?php
declare(strict_types=1);
namespace AppEntity;
use ApiPlatformMetadataPost;
use ApiPlatformMetadataGetCollection;
use ApiPlatformMetadataPatch;
use ApiPlatformMetadataGet;
use ApiPlatformMetadataApiResource;
use DoctrineORMMapping as ORM;
#[ORMEntity]
#[ORMTable("rating_attribute")]
#[ApiResource(
operations: [new Get(), new Patch(), new GetCollection(), new Post()],
paginationEnabled: false
)]
class RatingAttribute extends AbstractReadWriteProperties
{
#[ORMId]
#[ORMGeneratedValue]
#[ORMColumn(type: 'integer', nullable: true)]
private ?int $id = null;
#[ORMManyToOne(targetEntity: Rating::class)]
private Rating $rating;
#[ORMColumn(type: 'string', length: 240)]
private string $key;
#[ORMColumn(type: 'string', length: 240)]
private string $value;
#[ORMColumn(type: 'bigint', length: 240)]
private string $reviewToken;
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return Rating
*/
public function getRating(): Rating
{
return $this->rating;
}
/**
* @return string
*/
public function getKey(): string
{
return $this->key;
}
/**
* @return string
*/
public function getValue(): string
{
return $this->value;
}
/**
* @return string
*/
public function getReviewToken(): string
{
return $this->reviewToken;
}
/**
* @param Rating $rating
*
* @return RatingAttribute
*/
public function setRating(Rating $rating): RatingAttribute
{
$this->rating = $rating;
return $this;
}
/**
* @param string $key
*
* @return RatingAttribute
*/
public function setKey(string $key): RatingAttribute
{
$this->key = $key;
return $this;
}
/**
* @param string $value
*
* @return RatingAttribute
*/
public function setValue(string $value): RatingAttribute
{
$this->value = $value;
return $this;
}
/**
* @param string $reviewToken
*
* @return RatingAttribute
*/
public function setReviewToken(string $reviewToken): RatingAttribute
{
$this->reviewToken = $reviewToken;
return $this;
}
}
I don’t understand what can happen, the problem seems to come from the vendor/api-platform/core/src/Core/Metadata/Resource/Factory/ExtractorResourceMetadataFactory.php line 54
If I comment this part in this code :
if (!(class_exists($resourceClass) || interface_exists($resourceClass)) || !$resource = $this->extractor->getResources()[$resourceClass] ?? false) {
return $this->handleNotFound($parentResourceMetadata, $resourceClass);
}
everything works correctly.