alexandrebulete/ddd-apiplatform-bridge
最新稳定版本:1.0.0
Composer 安装命令:
composer require alexandrebulete/ddd-apiplatform-bridge
包简介
API Platform bridge for DDD Foundation - Pure PHP, no framework dependency
README 文档
README
API Platform bridge for DDD Foundation. Provides State providers, processors, and pagination utilities.
Pure PHP - No framework dependency. Can be used with Symfony or Laravel (future).
Installation
composer require alexandrebulete/ddd-apiplatform-bridge
For Symfony integration, also install:
composer require alexandrebulete/ddd-apiplatform-bundle
Structure
src/
└── State/
└── Paginator.php
Usage
Paginator
A generic paginator implementing API Platform's PaginatorInterface:
use AlexandreBulete\DddApiPlatformBridge\State\Paginator; use AlexandreBulete\DddFoundation\Application\Query\QueryBusInterface; class GetPostsProvider implements ProviderInterface { public function __construct( private QueryBusInterface $queryBus, ) {} public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null { $repository = $this->queryBus->ask(new GetPostsQuery( page: $context['filters']['page'] ?? 1, itemsPerPage: $context['filters']['itemsPerPage'] ?? 30, )); $paginator = $repository->paginator(); if (null === $paginator) { return iterator_to_array($repository); } return new Paginator( items: $paginator, currentPage: $paginator->getCurrentPage(), itemsPerPage: $paginator->getItemsPerPage(), lastPage: $paginator->getLastPage(), totalItems: $paginator->getTotalItems(), ); } }
Usage with API Platform Resources
use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; #[ApiResource( operations: [ new GetCollection( provider: GetPostsProvider::class, ), ], )] class PostResource { public function __construct( public string $id, public string $title, public string $content, ) {} }
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-26