LanguagesTrait
Trait LanguagesTrait
Provides a helper method to initialize and store the list of supported languages for a controller.
This trait manages:
- The
$languagesproperty containing valid language codes. - The initialization of
$languagesfrom 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
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
Return values
static —Returns the current instance for method chaining.