api-platform-tools/extended-resource

API Platform Tools:扩展api-platform/core ApiResource属性

dev-master / 0.1.x-dev 2023-10-21 21:21 UTC

This package is auto-updated.

Last update: 2024-09-21 23:32:57 UTC


README

Stand With Ukraine

安装

推荐安装方式是通过Composer

composer require api-platform-tools/extended-resource

此包需要至少PHP 8.1.0。

其他包可能包含api资源,这些资源在某些配置下可能不适合直接在项目中使用。这就是为什么ExtendedApiResource很有用,它可以覆盖默认属性中定义的部分选项。

例如,看看ApiPlatformTools\Tests\Assets\BaseResource类。它定义了api资源。如果你想iri为/api/vendor/bases,你必须做以下操作

  1. 创建一个新的类,该类扩展了你想要覆盖的资源
  2. 添加ExtendedApiResouce属性而不是ApiResource属性
  3. 仅传递你想覆盖的选项,其他选项将采用你正在扩展的资源中的值
namespace ApiPlatformTools\Tests\Assets;

use ApiPlatformTools\Attribute\ExtendedApiResource;

#[ExtendedApiResource(routePrefix: '/vendor')]
class VendorResource extends ApiPlatformTools\Tests\Assets\BaseResource
{
}

ExtendedApiResouce属性检查你正在扩展的资源,并覆盖了在扩展中给出的选项,保持其他选项与父资源中相同。

重要:您需要使用api_platform.openapi.factory装饰器禁用扩展资源,否则您将有两个基础资源实例:一个具有/api/bases iri,另一个具有/api/vendor/bases iri。