init
Table of Contents
Functions
- initConfig() : array<string|int, mixed>
- Load a toml configuration and initialize it.
- initContainer() : Container
- Initialize and build a PHP-DI container for the application.
- initDefaultTimezone() : void
- Initialize the application's default timezone.
- initDefinitions() : array<string|int, mixed>
- Initialize all DI container definitions by loading and merging PHP definition files.
- initErrors() : void
- Initialize the global PHP error settings.
- initMemoryLimit() : bool
- Initialize the default memory limit of the PHP application.
- setIniIfExists() : bool
- Set a PHP ini directive from a scalar or from a config array if the value exists and is not empty.
Functions
initConfig()
Load a toml configuration and initialize it.
initConfig([string $basePath = Char::EMPTY ][, string $file = 'config.toml' ][, callable(array<string|int, mixed>): array<string|int, mixed>|null $init = null ]) : array<string|int, mixed>
Delegates resolution to oihana\files\toml\resolveTomlConfig while preserving the previous behavior of returning an empty config when the file does not exist.
Parameters
- $basePath : string = Char::EMPTY
-
Base path of config
- $file : string = 'config.toml'
-
Config file name (with or without .toml)
- $init : callable(array<string|int, mixed>): array<string|int, mixed>|null = null
-
Initialize the application with the config definition.
Tags
Return values
array<string|int, mixed> —The config array definition.
initContainer()
Initialize and build a PHP-DI container for the application.
initContainer(string|array<string|int, mixed>|DefinitionSource ...$definitions) : Container
This function creates a ContainerBuilder, adds one or more definition sources, and returns the built Container. Definitions can be provided as:
- string: path to a PHP definition file (returning an array of definitions).
- array: an associative array of definitions.
- DefinitionSource: any PHP-DI compatible definition source.
Notes:
- Later definition sources can override entries defined earlier.
- To load multiple files from a directory, see initDefinitions().
Parameters
- $definitions : string|array<string|int, mixed>|DefinitionSource
-
One or more definition sources (file path(s), array(s), or DefinitionSource instances).
Tags
Return values
Container —The built dependency injection container.
initDefaultTimezone()
Initialize the application's default timezone.
initDefaultTimezone(string|null $timezoneId[, string $defaultTimezone = 'Europe/Paris' ]) : void
This function sets the global timezone used by all date/time functions. If $timezoneId is null, $defaultTimezone will be applied.
Notes:
- If an invalid identifier is provided, PHP will return false and emit a warning.
- Prefer passing null rather than an empty string to trigger the default timezone.
Parameters
- $timezoneId : string|null
-
Timezone identifier to apply. Use null to apply $defaultTimezone.
- $defaultTimezone : string = 'Europe/Paris'
-
Timezone to use when $timezoneId is null (default 'Europe/Paris').
Tags
initDefinitions()
Initialize all DI container definitions by loading and merging PHP definition files.
initDefinitions(string $basePath) : array<string|int, mixed>
This function scans $basePath recursively for .php files, requires each file, and merges the resulting arrays into a single definitions array. It is intended to assemble service definitions for a DI container.
Behavior:
- Only files with the "php" extension are considered.
- Files are discovered recursively in subdirectories.
- Each file must return an array; non-array returns may cause merge issues or exceptions in requireAndMergeArrays.
Parameters
- $basePath : string
-
Absolute or relative path to the root directory containing definition files.
Tags
Return values
array<string|int, mixed> —Merged definitions array.
initErrors()
Initialize the global PHP error settings.
initErrors([array<string|int, mixed>|null $init = null ][, string|null $logRootPath = null ][, int $defaultErrorLevel = E_ALL ]) : void
This function sets PHP error reporting and ini directives related to error display and logging, based on the provided configuration array and optional log root path.
It applies the following settings:
- error_reporting level (defaulting to $defaultErrorLevel if not provided)
- display_errors (ini directive)
- display_startup_errors (ini directive)
- error_log (ini directive), with an optional root path prefix
Parameters
- $init : array<string|int, mixed>|null = null
-
Optional associative array of ini settings.
- $logRootPath : string|null = null
-
Optional root directory path to prepend to error_log path if it is relative.
- $defaultErrorLevel : int = E_ALL
-
Default error reporting level to use if none is set in $init.
Tags
initMemoryLimit()
Initialize the default memory limit of the PHP application.
initMemoryLimit(string|null $memoryLimit[, string $defaultMemoryLimit = "128M" ]) : bool
This function sets the PHP memory_limit ini directive to the given value if provided, otherwise it uses the provided default memory limit.
Parameters
- $memoryLimit : string|null
-
The memory limit value to set (e.g. '256M', '1G', or '-1' for unlimited), or null to use default.
- $defaultMemoryLimit : string = "128M"
-
The default memory limit to use if $memoryLimit is null. Default is '128M'.
Tags
Return values
bool —True if the ini setting was successfully set, false otherwise.
setIniIfExists()
Set a PHP ini directive from a scalar or from a config array if the value exists and is not empty.
setIniIfExists(string $key[, array<string|int, mixed>|string|int|float|bool|null $init = [] ]) : bool
Behavior:
- If $init is an array, this function looks up $init[$key]; otherwise it treats $init as the value.
- The value is cast to string and trimmed; empty strings are ignored.
- ini_set() is invoked only if the function exists and a non-empty value is provided.
- Returns true when ini_set() is called, false otherwise.
Notes:
- Most ini values are strings; booleans are commonly expressed as "1"/"0". Passing true/false will be cast to "1"/"" by PHP.
- Use ini_get($key) to read back the effective value after setting.
Parameters
- $key : string
-
The ini key (e.g. 'display_errors', 'memory_limit').
- $init : array<string|int, mixed>|string|int|float|bool|null = []
-
A config array (looked up by $key) or a direct scalar value.
Tags
Return values
bool —True if ini_set() was called, false otherwise.