Skip to main content

PSX

An innovative PHP framework dedicated to build fully typed REST APIs.

Typed controller

Fully typed controller classes.

Client SDK

Client SDK generator

OpenAPI

OpenAPI generator

Model

Generate model classes based on a TypeSchema specification

Symfony DI

Uses the Symfony DI container component

Doctrine DBAL

Works with Doctrine DBAL and migrations


Controller

PSX allows you to define complete type-safe controllers which map every value from the HTTP request to an argument. This idea is inspired by great frameworks like Spring or NestJS.

src/Controller/Population.php
class Population extends ControllerAbstract
{
#[Get]
#[Path('/population')]
public function getAll(#[Query] ?int $startIndex = null, #[Query] ?int $count = null): Model\PopulationCollection
{
// @TODO return population entries
}

#[Post]
#[Path('/population')]
#[StatusCode(201)]
public function create(#[Body] Model\Population $payload): Model\Message
{
// @TODO create population entry
}
}

Dependency Injection

A key concept in PSX is dependency injection. Internally we use the Symfony DependencyInjection Component to automatically inject all dependencies into your controller so that you can build a clean architecture.

src/Controller/Population.php
class Population extends ControllerAbstract
{
public function __construct(private MyService $myService)
{
}

#[Post]
#[Path('/population')]
#[StatusCode(201)]
public function create(#[Body] Model\Population $payload): Model\Message
{
$id = $this->myService->create($payload);

$message = new Model\Message();
$message->setSuccess(true);
$message->setMessage('Population record successfully created');
$message->setId($id);
return $message;
}
}

Client SDK

One of the innovative features of PSX is, that you can automatically generate a client SDK for your API. Through a simple command you can generate a complete type-safe client SDK to communicate with your API.

Console
php bin/psx generate:sdk spec-openapi
php bin/psx generate:sdk client-typescript
php bin/psx generate:sdk client-php