rekalogika/api-lite
Composer 安装命令:
composer require rekalogika/api-lite
包简介
A set of tools to simplify working with API Platform in your projects. Comes with guides, patterns, and practical examples for building API Platform-based projects.
README 文档
README
A set of tools to simplify working with API Platform in your projects. Comes with guides, patterns, and practical examples for building API Platform-based projects.
Apply existing knowledge, experience, and patterns of working with Symfony controllers to API Platform state providers and processors. Decouple your persistence layer from the API frontend layer. Apply Domain-Driven Design (DDD) principles to your API Platform-based projects, as well as other architectural patterns and best practices, including SOLID, onion architecture, clean architecture, hexagonal architecture, and others.
'Lite' means we are refraining from using all of API Platform's features and automations in favor of better readability, simplicity, and flexibility.
Full documentation is available at rekalogika.dev/api-lite.
Motivation
API Platform documentation encourages developers to use plain old PHP objects (POPOs) or data transfer objects (DTOs) as the models for API communication, instead of using domain entities directly for this purpose. But it does not establish a practical working patterns for that approach.
Practically all the examples and demos we find on the Internet still
attach ApiResource to Doctrine entities.
Sometimes API Platform can feel very rigid. It can be difficult to figure out how to accomplish things outside its conventions. There are ways around any problem, just not always immediately obvious. It can feel like that we just want to express what we need by writing a PHP code, not by figuring out the correct combination of attributes to use.
Those coming from Symfony controllers might find API Platform's approach very different, but it does not have to be.
Installation
composer require rekalogika/api-lite
Synopsis
use Doctrine\Common\Collections\Collection; use Rekalogika\ApiLite\State\AbstractProvider; use Rekalogika\Mapper\CollectionInterface; #[ApiResource( shortName: 'Book', operations: [ new Get( uriTemplate: '/books/{id}', provider: BookProvider::class ), ] )] class BookDto { public ?Uuid $id = null; public ?string $title = null; public ?string $description = null; /** * @var ?CollectionInterface<int,ReviewDto> */ public ?CollectionInterface $reviews = null; } /** * @extends AbstractProvider<BookDto> */ class BookProvider extends AbstractProvider { public function __construct( private BookRepository $bookRepository ) { } public function provide( Operation $operation, array $uriVariables = [], array $context = [] ): object|array|null { $book = $this->bookRepository ->find($uriVariables['id'] ?? null) ?? throw new NotFoundException('Book not found'); $this->denyAccessUnlessGranted('view', $book); return $this->map($book, BookDto::class); } }
To-Do List
- Figure out & implement filtering.
Documentation
License
MIT
rekalogika/api-lite 适用场景与选型建议
rekalogika/api-lite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.41k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2024 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「api」 「ddd」 「dto」 「api-platform」 「openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rekalogika/api-lite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rekalogika/api-lite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rekalogika/api-lite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Value Objects Library
The bundle for easy using json-rpc api on your project
Build a domain-oriented application on Laravel Framework
A PSR-7 compatible library for making CRUD API endpoints
Symfony bundle for broadway/broadway.
Provides Symfony param converters for mediagone/types-common package.
统计信息
- 总下载量: 2.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-28