Oihana PHP System

LanguagesTrait

Trait LanguagesTrait

Provides a helper method to initialize and store the list of supported languages for a controller.

This trait manages:

  • The $languages property containing valid language codes.
  • The initialization of $languages from an array or a PSR-11 container.

Example usage:

$this->initializeLanguages(['languages' => ['fr', 'en']]);

// Or with a PSR-11 container
$this->initializeLanguages([], $container);

// Access the languages
echo $this->languages; // ['fr', 'en']
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

LANGUAGES  = 'languages'
Key used to initialize languages in an array or container.

Properties

$languages  : array<string|int, string>
Array of valid language codes supported by the controller.

Methods

initializeLanguages()  : static
Initialize the internal `$languages` property from an array or a PSR-11 container.

Constants

LANGUAGES

Key used to initialize languages in an array or container.

public mixed LANGUAGES = 'languages'

Properties

$languages

Array of valid language codes supported by the controller.

public array<string|int, string> $languages = []

Methods

initializeLanguages()

Initialize the internal `$languages` property from an array or a PSR-11 container.

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

This method first checks the provided $init array for a key 'languages'. If not found, it optionally checks a PSR-11 container for fallback configuration.

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

Optional array with key 'languages' containing supported language codes.

$container : ContainerInterface|null = null

Optional PSR-11 container for fallback configuration.

Tags
throws
ContainerExceptionInterface

If the container fails to retrieve the languages.

throws
NotFoundExceptionInterface

If the requested languages key is not found in the container.

Return values
static

Returns the current instance for method chaining.


        
On this page

Search results