Documentation

ApiV1
in package

Main API V1 handler class.

Uses a route map to dispatch requests to module-specific handlers resolved from the DI container.

Table of Contents

Constants

HANDLER_MAP  = ['auth' => \Lwt\Modules\User\Http\UserApiHandler::class, 'languages' => \Lwt\Modules\Language\Http\LanguageApiHandler::class, 'review' => \Lwt\Modules\Review\Http\ReviewApiHandler::class, 'settings' => \Lwt\Modules\Admin\Http\AdminApiHandler::class, 'tags' => \Lwt\Modules\Tags\Http\TagApiHandler::class, 'terms' => \Lwt\Modules\Vocabulary\Http\VocabularyApiRouter::class, 'word-families' => \Lwt\Modules\Vocabulary\Http\WordFamilyApiHandler::class, 'texts' => \Lwt\Modules\Text\Http\TextApiHandler::class, 'feeds' => \Lwt\Modules\Feed\Http\FeedApiHandler::class, 'books' => \Lwt\Modules\Book\Http\BookApiHandler::class, 'local-dictionaries' => \Lwt\Modules\Dictionary\Http\DictionaryApiHandler::class, 'youtube' => \Lwt\Modules\Text\Http\YouTubeApiHandler::class, 'tts' => \Lwt\Modules\Language\Infrastructure\NlpServiceHandler::class, 'whisper' => \Lwt\Modules\Text\Http\WhisperApiHandler::class]
Map of top-level route names to handler classes.
PUBLIC_ENDPOINTS  = ['auth/login' => true, 'auth/register' => true, 'version' => true]
Endpoints that do not require authentication.
RELEASE_DATE  = "2026-01-10"
VERSION  = "3.0.0"

Properties

$container  : Container

Methods

__construct()  : mixed
handle()  : void
Handle the incoming API request.
handleRequest()  : void
Static entry point for handling requests.
dispatch()  : JsonResponse
Dispatch a request to the appropriate handler.
getRequestBody()  : array<string, mixed>
Get request body data based on HTTP method.
handleInlineEndpoints()  : JsonResponse|null
Handle simple inline endpoints that don't warrant a full handler.
handleSentencesGet()  : JsonResponse
Handle GET /sentences-with-term requests.
isPublicEndpoint()  : bool
Check if an endpoint is public (does not require authentication).
parseJsonBody()  : array<string, mixed>
Parse JSON body for PUT/DELETE requests.
parseQueryParams()  : array<string, mixed>
validateAuth()  : JsonResponse|null
Validate authentication for the current request.

Constants

HANDLER_MAP

Map of top-level route names to handler classes.

private array<string, ApiRoutableInterface>> HANDLER_MAP = ['auth' => \Lwt\Modules\User\Http\UserApiHandler::class, 'languages' => \Lwt\Modules\Language\Http\LanguageApiHandler::class, 'review' => \Lwt\Modules\Review\Http\ReviewApiHandler::class, 'settings' => \Lwt\Modules\Admin\Http\AdminApiHandler::class, 'tags' => \Lwt\Modules\Tags\Http\TagApiHandler::class, 'terms' => \Lwt\Modules\Vocabulary\Http\VocabularyApiRouter::class, 'word-families' => \Lwt\Modules\Vocabulary\Http\WordFamilyApiHandler::class, 'texts' => \Lwt\Modules\Text\Http\TextApiHandler::class, 'feeds' => \Lwt\Modules\Feed\Http\FeedApiHandler::class, 'books' => \Lwt\Modules\Book\Http\BookApiHandler::class, 'local-dictionaries' => \Lwt\Modules\Dictionary\Http\DictionaryApiHandler::class, 'youtube' => \Lwt\Modules\Text\Http\YouTubeApiHandler::class, 'tts' => \Lwt\Modules\Language\Infrastructure\NlpServiceHandler::class, 'whisper' => \Lwt\Modules\Text\Http\WhisperApiHandler::class]

Each handler implements ApiRoutableInterface. The route method (routeGet, routePost, routePut, routeDelete) receives the full fragments array and request params.

PUBLIC_ENDPOINTS

Endpoints that do not require authentication.

private array<string, bool> PUBLIC_ENDPOINTS = ['auth/login' => true, 'auth/register' => true, 'version' => true]

RELEASE_DATE

private mixed RELEASE_DATE = "2026-01-10"

VERSION

private mixed VERSION = "3.0.0"

Properties

Methods

__construct()

public __construct([Container|null $container = null ]) : mixed
Parameters
$container : Container|null = null

handle()

Handle the incoming API request.

public handle(string $method, string $uri, array<string, mixed>|null $postData) : void
Parameters
$method : string

HTTP method

$uri : string

Request URI

$postData : array<string, mixed>|null

POST data (also used for PUT/DELETE with JSON body)

handleRequest()

Static entry point for handling requests.

public static handleRequest() : void

dispatch()

Dispatch a request to the appropriate handler.

private dispatch(string $method, array<int, string> $fragments, array<string, mixed> $params) : JsonResponse
Parameters
$method : string

HTTP method

$fragments : array<int, string>

Endpoint path segments

$params : array<string, mixed>

Request parameters

Return values
JsonResponse

getRequestBody()

Get request body data based on HTTP method.

private static getRequestBody(string $method) : array<string, mixed>
Parameters
$method : string

HTTP method

Return values
array<string, mixed>

handleInlineEndpoints()

Handle simple inline endpoints that don't warrant a full handler.

private handleInlineEndpoints(string $method, string $resource, array<int, string> $fragments, array<string, mixed> $params) : JsonResponse|null

Also handles cross-cutting endpoints that map to a handler under a different route name than the handler's primary resource.

Parameters
$method : string

HTTP method

$resource : string

Top-level route name

$fragments : array<int, string>

Endpoint path segments

$params : array<string, mixed>

Request parameters

Return values
JsonResponse|null

Response if handled, null to continue to HANDLER_MAP

handleSentencesGet()

Handle GET /sentences-with-term requests.

private handleSentencesGet(LanguageApiHandler $lang, array<int, string> $fragments, array<string, mixed> $params) : JsonResponse
Parameters
$lang : LanguageApiHandler

Language handler

$fragments : array<int, string>

Endpoint path segments

$params : array<string, mixed>

Query parameters

Return values
JsonResponse

isPublicEndpoint()

Check if an endpoint is public (does not require authentication).

private isPublicEndpoint(string $endpoint) : bool
Parameters
$endpoint : string

The endpoint path

Return values
bool

parseJsonBody()

Parse JSON body for PUT/DELETE requests.

private static parseJsonBody() : array<string, mixed>
Return values
array<string, mixed>

Parsed body data

parseQueryParams()

private parseQueryParams(string $uri) : array<string, mixed>
Parameters
$uri : string
Return values
array<string, mixed>

validateAuth()

Validate authentication for the current request.

private validateAuth() : JsonResponse|null
Return values
JsonResponse|null

Error response or null if valid


        
On this page

Search results