aphiria/aphiria

The Aphiria framework

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

README

68747470733a2f2f7777772e617068697269612e636f6d2f696d616765732f617068697269612d6c6f676f2e737667

badge.svg Coverage Status 68747470733a2f2f73686570686572642e6465762f6769746875622f617068697269612f617068697269612f6c6576656c2e737667 68747470733a2f2f706f7365722e707567782e6f72672f617068697269612f617068697269612f762f737461626c652e737667 68747470733a2f2f706f7365722e707567782e6f72672f617068697269612f617068697269612f762f756e737461626c652e737667 68747470733a2f2f706f7365722e707567782e6f72672f617068697269612f617068697269612f6c6963656e73652e737667

Note: This framework is not stable yet.

Introduction

Aphiria is a suite of small, decoupled PHP libraries that make up a REST API framework. It simplifies content negotiation without bleeding into your code, allowing you to write expressive code. Aphiria also provides the following functionality out of the box:

// 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);

Installation

Create an Aphiria app via Composer:

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

Refer to the documentation for more details.

Documentation

Full documentation is available at the Aphiria website.

Requirements

  • PHP >= 8.3

Contributing

We appreciate any and all contributions to Aphiria. Please read the documentation to learn how to contribute.

Community

If you have general questions or comments about Aphiria, join our GitHub Discussions.

Directory Structure

Aphiria is organized as a monorepo. Each library is contained in src/{library}, and contains src and tests directories.

License

This software is licensed under the MIT license. Please read the LICENSE for more information.

Author

Aphiria was created and primarily written by David Young.