将 Symfony 从 5.4 升级到 6.1 后,找不到我们的 ApiResource 路由。我有 api-platform/core 2.7.
以下是我们的路线:
Symfony 5.4
---------------------------------------------------------------------- ---------- -------- ------ ------------------------------------------------------------
Name Method Scheme Host Path
---------------------------------------------------------------------- ---------- -------- ------ ------------------------------------------------------------
...
default ANY ANY ANY /
api_genid ANY ANY ANY /.well-known/genid/{id}
api_entrypoint ANY ANY ANY /{index}.{_format}
api_doc ANY ANY ANY /docs.{_format}
api_jsonld_context ANY ANY ANY /contexts/{shortName}.{_format}
api_gift_card_solutions_incoming_order_item_webhooks_post_collection POST ANY ANY /incoming-webhooks/gift-card-solutions/orders
api_images_get_collection GET ANY ANY /images.{_format}
api_images_get_item GET ANY ANY /images/{id}.{_format}
api_orders_post_collection POST ANY ANY /orders.{_format}
api_orders_get_item GET ANY ANY /orders/{id}.{_format}
api_payment_gateway_incoming_order_intent_webhooks_post_collection POST ANY ANY /incoming-webhooks/payment-gateway/order-intents
api_products_get_collection GET ANY ANY /products.{_format}
api_products_get_item GET ANY ANY /products/{id}.{_format}
api_settings_get_collection GET ANY ANY /settings.{_format}
---------------------------------------------------------------------- ---------- -------- ------ ------------------------------------------------------------
Symfony 6.1
----------------------------------------------- ---------- -------- ------ ------------------------------------------------------------
Name Method Scheme Host Path
----------------------------------------------- ---------- -------- ------ ------------------------------------------------------------
...
default ANY ANY ANY /
api_genid ANY ANY ANY /.well-known/genid/{id}
api_entrypoint ANY ANY ANY /{index}.{_format}
api_doc ANY ANY ANY /docs.{_format}
api_jsonld_context ANY ANY ANY /contexts/{shortName}.{_format}
----------------------------------------------- ---------- -------- ------ ------------------------------------------------------------
这是我们的 ApiResource 之一:Order.php
...
#[ApiResource(
collectionOperations: [
'get' => [
'security' => "is_granted(permission('IMAGE_LIST'), object)",
],
],
itemOperations: [
'get' => [
'security' => "is_granted(permission('IMAGE_READ'), object)",
],
],
normalizationContext: ['groups' => ['image:read', 'timestamp:read', 'primary_key:read']],
)]
...
#[ORM\Entity]
#[ORM\Table(name: 'images')]
class Image extends AbstractDatabaseEntity implements ActivatableEntityInterface, ProviderAwareInterface
{
...
对于升级,使用 rector 和所有内容修复了所有弃用的内容。我们还有一个不同的项目并继续执行相同的升级步骤。
您已将代码从使用
Annotations
升级为 Attributes
。 API Platform v2.7 不支持直接开箱即用的 Attributes
,但它可以与 Annotations
配合使用。升级到 API 平台 ^3.0
或者如果您想继续使用 v2.7,请使用向后兼容性配置选项:
api_platform:
metadata_backward_compatibility_layer: false
在 v2.7 中需要使用新的元数据系统,因为默认值为 true。
在此处查看更多详细信息:升级指南