Skip to content

Quick Start

these are provided when creating project with:

Terminal window
composer create-project fatjon-lleshi/antares-app

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

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:

Terminal window
php swoole.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:

Terminal window
php worker.php

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

Define routes with PHP attributes:

<?php
use 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);
}
}

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,
) {}
}

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.