aphiria/aphiria

Aphiria 框架

v1.0.0-alpha9 2023-09-24 17:24 UTC

README

Coverage Status

注意:此框架尚不稳定。

简介

Aphiria 是一组小型、解耦的 PHP 库,组成 REST API 框架。它简化了内容协商,不会渗入你的代码,允许你编写易于表达的代码。Aphiria 还提供以下功能:

// Define some controller endpoints
class UserController extends Controller
{
    public function __construct(private IUserService $users) {}

    #[Post('/users')]
    public function createUser(User $user): IResponse
    {
        $this->users->create($user);
        
        return $this->created("/users/{$user->id}", $user);
    }

    #[Get('/users/:id')]
    #[AuthorizeRoles('admin')]
    public function getUserById(int $id): User
    {
        return $this->users->getById($id);
    }
}

// Bind your dependency
$container->bindInstance(IUserService::class, new UserService());

// Run an integration test
$postResponse = $this->post('/users', new User('Dave'));
$user = $this->readResponseBodyAs(User::class, $postResponse);
$admin = (new PrincipalBuilder('example.com'))->withRoles('admin')
    ->build();
$getResponse = $this->actingAs($admin, fn () => $this->get("/users/$user->id"));
$this->assertParsedBodyEquals($user, $getResponse);

安装

通过 Composer 创建 Aphiria 应用

composer create-project aphiria/app --prefer-dist --stability dev

有关更多详细信息,请参阅 文档

文档

完整文档可在 Aphiria 网站 上找到。

需求

  • PHP >= 8.3

贡献

我们感谢对 Aphiria 的任何和所有贡献。请阅读 文档 了解如何贡献。

社区

如果您对 Aphiria 有任何一般性的问题或评论,请加入我们的 GitHub 讨论

目录结构

Aphiria 采用单仓库组织。每个库都包含在 src/{library} 中,并包含 srctests 目录。

许可

此软件受 MIT 许可证许可。请参阅 LICENSE 了解更多信息。

作者

Aphiria 由 David Young 创建和主要编写。