Oihana PHP

ApiTrait

Provides a controller-level `api` settings array, hydrated either from an initialization array or from a PSR-11 container entry.

The settings are exposed through the protected $api property and populated by self::initializeApi(), so API-related configuration (endpoints, keys, feature flags, etc.) can be centralized in the DI container and shared consistently across all controllers.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Properties

$api  : array<string|int, mixed>
The default api settings.

Methods

initializeApi()  : static
Initializes the internal `api` settings.

Properties

$api

The default api settings.

protected array<string|int, mixed> $api = []

Methods

initializeApi()

Initializes the internal `api` settings.

public initializeApi([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

By default, this method search in the DI container a ControllerParam::API definition to initialize the "api" property.

Parameters
$init : array<string|int, mixed> = []

Optional initialization array (e.g., ['api' => [ ... ] ] ).

$container : ContainerInterface|null = null

Optional DI container for retrieving the 'api' array representation.

Tags
throws
NotFoundExceptionInterface

If the container is used and the 'api' definition is not found in the DI container.

ContainerExceptionInterface

If the container throws an internal error.

RuntimeException

If no valid App instance is provided or found.

Return values
static

Returns the current controller instance for method chaining.

On this page

Search results