Introduction

What Is It?

Aphiria is a suite of decoupled libraries that help you write expressive REST APIs without bleeding into your code base. Let's look at an example controller.

final class UserController extends Controller
{
    // Assume this is from your domain
    private IUserService $users;

    public function __construct(IUserService $users)
    {
        $this->users = $users;
    }

    public function createUser(UserDto $userDto): IHttpResponseMessage
    {
        $user = $this->users->createUser($userDto->email, $userDto->password);

        return $this->created("users/{$user->id}", $user);
    }

    public function getUser(int $id): User
    {
        return $this->users->getUserById($id);
    }
}

In createUser(), Aphiria uses content negotiation to deserialize the request body to a UserDto. Likewise, Aphiria determines how to serialize the user in getUser() to whatever format the client wants (eg JSON). This is all done with zero configuration of your plain-old PHP objects (POPOs).

Now, we'll actually set up our app to include these endpoints. Let's say we need a bootstrapper so that an instance of IUserService can be injected into the controller. Easy.

$appBuilder->withBootstrappers(fn () => [new UserServiceBootstrapper]);
$appBuilder->withRoutes(function (RouteBuilderRegistry $routes) {
    $routes->post('users')
        ->toMethod(UserController::class, 'createUser');

    $routes->get('users/:id')
        ->toMethod(UserController::class, 'getUser');
});

The application builder simplifies registering all bootstrappers, routes, and other parts of your application in a modular way.

Hopefully, these examples demonstrate how easy it is to build an application with Aphiria.

Getting Started

To get up and running, follow our installation guide to create a skeleton app that uses Aphiria. Then, learn how to define some routes, create some controllers, and configure your dependencies. From there, you can browse the docs in any order you choose, although the order they're listed in might be the best way to read them.

Another PHP Framework?

Great question. The idea for Aphiria was conceived after using ASP.NET Core. Its expressive syntax, intuitive models, and simple configuration inspired me to see if I could find these things in a PHP framework. I looked at frameworks (even Opulence), and usually found at least one major problem with them all:

I spent months sketching out the ideal syntax. As I waded into the depths of development, though, I started to realize that my ideas were a fundamental shift from Opulence. For example:

After more than a year of development, a whole new framework was emerging - Aphiria. I honestly believe it is the most intuitive, expressive PHP framework to date. It enables developers to build powerful APIs without getting in the way. I invite you to browse some of the documentation and see for yourself.