Quick Start
Entry Point for PHP-FPM runtime
Section titled “Entry Point for PHP-FPM runtime”these are provided when creating project with:
composer create-project fatjon-lleshi/antares-appindex.php
Section titled “index.php”if you downloaded the app, public/index.php is already there.
<?php
use Antares\Application;use App\Providers\AppServiceProvider;use App\Providers\RouteServiceProvider;use App\Middleware\CorsMiddleware;
require __DIR__ . '/../vendor/autoload.php';
Application::create(__DIR__ . '/..') ->providers([AppServiceProvider::class]) ->routeProviders([RouteServiceProvider::class]) ->middleware([CorsMiddleware::class]) ->run();swoole.php
Section titled “swoole.php”Runs the app on a Swoole HTTP server, booted once and kept in memory. Requires the swoole PHP extension and composer require ilexn/swoole-psr7.
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use App\Providers\AppServiceProvider;use App\Providers\RouteServiceProvider;use Antares\Application;
Application::create(__DIR__) ->providers([AppServiceProvider::class]) ->routeProviders([RouteServiceProvider::class]) ->runSwoole( host: $_ENV['SWOOLE_HOST'] ?? '0.0.0.0', port: (int) ($_ENV['SWOOLE_PORT'] ?? 8000), );run with:
php swoole.phpworker.php
Section titled “worker.php”For FrankenPHP’s worker mode.
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use App\Providers\AppServiceProvider;use App\Providers\RouteServiceProvider;use Antares\Application;
Application::create(__DIR__) ->providers([AppServiceProvider::class]) ->routeProviders([RouteServiceProvider::class]) ->runWorker();FrankenPHP runs this file itself, so don’t start it with php worker.php (that throws runWorker() requires FrankenPHP runtime). For example:
frankenphp php-server --worker worker.phpThe app is booted once per worker and then handles requests until FrankenPHP stops it. Set MAX_REQUESTS to have each worker restart after that many requests.
Define a Controller
Section titled “Define a Controller”Define routes with PHP attributes:
use Antares\Router\Attributes\Get;use Antares\Router\Attributes\Post;
class UserController{ #[Get('/users')] public function index(): array { return ['users' => []]; }
#[Post('/users', 201)] public function store(CreateUserRequest $request): UserResponse { return new UserResponse(id: 1, name: $request->name); }}Register your Controller
Section titled “Register your Controller”Add it to your route provider:
<?phpuse Antares\ServiceProvider;use Antares\Container\Container;use Antares\Router\Router;
class RouteServiceProvider implements ServiceProvider{ public function register(Container $container): void { $router = $container->make(Router::class);
$router->register(UserController::class); }}Request DTO
Section titled “Request DTO”Define a class with the #[Dto] attribute and its fields as promoted constructor parameters
use Antares\Validation\Attributes\Dto;use Antares\Validation\Attributes\NotBlank;use Antares\Validation\Attributes\Email;use Antares\Validation\Attributes\MinLength;
#[Dto]readonly class CreateUserRequest{ public function __construct( #[NotBlank] #[MinLength(2)] public string $name,
#[NotBlank] #[Email] public string $email, ) {}}Response DTO
Section titled “Response DTO”Define a class with the #[ResponseDto] attribute and its fields as promoted constructor parameters
use Antares\Serialization\Attributes\ResponseDto;use Antares\Serialization\Attributes\SerializeAs;
#[ResponseDto]readonly class UserResponse{ public function __construct( public int $id, public string $name, ) {}}That’s all it takes. Antares wires up validation, serialization, and OpenAPI Doc generation automatically from these classes. You define the contract once, everything else just makes it itself.