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\LogMiddleware;
require __DIR__ . '/../vendor/autoload.php';
Application::create(__DIR__ . '/..') ->providers([AppServiceProvider::class]) ->routeProviders([RouteServiceProvider::class]) ->middleware([CorsMiddleware::class]) ->run();swoole.php
Section titled “swoole.php”provides swoole runtime with workers (requires php swoole extension)
<?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”provides FrankenPHP runtime with workers
<?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();run with:
php worker.phpDefine 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”Define routes with PHP attributes:
<?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 readonly class with Attribute #[Dto] and parameter constructor promotion
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 readonly class with Attribute #[ResponseDto] and parameter constructor promotion
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.