mini\Controller\AbstractController abstract class

Documentation

Base controller class with routing and response helpers

Controllers extend this class to handle HTTP requests using an internal router. Route registration uses type-aware patterns - the router analyzes method signatures to generate appropriate regex patterns for URL parameters.

Example:

class UserController extends AbstractController
{
    public function __construct()
    {
        parent::__construct();

        $this->router->get('/', $this->index(...));
        $this->router->get('/{id}/', $this->show(...));
        $this->router->post('/', $this->create(...));
    }

    public function index(): ResponseInterface
    {
        $users = User::query()->limit(100);
        return $this->respond(iterator_to_array($users));
    }

    public function show(int $id): ResponseInterface
    {
        $user = User::find($id);
        if (!$user) throw new \mini\Exceptions\NotFoundException();
        return $this->respond($user);
    }
}

Mount in Mini router:

// _routes/users/__DEFAULT__.php
return new UserController();

Inheritance

Implements: Psr\Http\Server\RequestHandlerInterface

Properties (1)

public readonly mini\Controller\Router $router

Internal router for this controller

Methods (12)

Documentation missing

PSR-15 entry point

Content negotiation response

Explicit JSON response

Explicit HTML response

Plain text response

Empty response (for 204 No Content, etc.)

Redirect response

Check if client accepts HTML

Parse Accept header into quality-weighted array

Find view template for current route

Convert controller method name to view name

Source

src/Controller/AbstractController.php:52-358