Configs
in package
implements
ConfigsInterface
Uses
WhitelistTrait
Interfaces, Classes, Traits and Enums
Table of Contents
- $config : mixed
- Configuration array used by the application.
- $appPath : string
- The absolute path to the application directory.
- $configCache : array<string|int, mixed>
- Cache for loaded configurations.
- $configsPath : string
- The absolute path to the application configurations directory.
- $defaultMiddlewares : array<string|int, mixed>
- Default middlewares applied to the application.
- $defaultWhitelist : array<string|int, mixed>
- Default whitelist settings for the application.
- $frameworkConfigsPath : string
- The absolute path to the framework's configuration files.
- __construct() : mixed
- Constructor for the configuration manager.
- addConfig() : void
- app() : static
- Loads the `app` options separately to avoid side effects.
- appOptions() : array<string|int, mixed>
- clearConfigCache() : void
- Clear the configuration cache or optionally for a specific key.
- dbAdminer() : void
- Load the Adminer script.
- defaultConfigPath() : mixed
- envTenantId() : string|null
- get() : mixed
- getActivePlugins() : mixed
- getAppPath() : mixed
- getConfig() : DotAccess|null
- Get a loaded configuration by key.
- getConfigsDir() : mixed
- getDefault() : array<string|int, null|mixed|(null|bool|mixed|(null|bool|int|mixed|string|string[])[]|string)[]>
- getTenantFilePath() : null|array<string|int, null|mixed|(null|bool|mixed|(null|false|int|mixed|string)[]|string)[]|string>|string
- Retrieves the path for a tenant-specific file, with an option to enforce strict finding.
- init() : self
- Initializes the configuration manager with a specific application path.
- isInProdEnvironment() : bool
- Determines if the application is running in a production environment.
- isPhpFile() : bool
- Determines if a given file is a PHP file by checking its extension and searching for valid PHP opening tags in its content.
- isProd() : bool
- Determines if the given environment is a production environment.
- json() : mixed
- load() : void
- Load a configuration file by name.
- loadArrayFile() : array<string|int, mixed>
- Safely require a file that should return an array.
- updateConfigCache() : void
- Add to the configuration cache.
- wpdb() : mixed
- appSettingsFileArray() : array<string|int, mixed>
- getConfigsPath() : mixed
- getDefaultWhitelist() : array<string|int, array<string|int, string>>
- loadConfigFile() : null|DotAccess
- Loads and merges a JSON configuration file into the configuration cache.
- multiMerge() : array<string|int, mixed>
- Merges two multi-dimensional arrays recursively.
- refreshConfig() : static
- setEnvWhitelist() : array<string|int, mixed>
- setMiddlewares() : array<string|int, mixed>
- dbUrl() : string
- Generates a hashed Adminer URL using a specified hashing algorithm.
- getDefaultMiddlewares() : mixed
Properties
$config
Configuration array used by the application.
public
mixed
$config
Gives us back an array with DotAccess
Configuration settings.
$appPath
The absolute path to the application directory.
protected
string
$appPath
Path to the application directory.
$configCache
Cache for loaded configurations.
protected
array<string|int, mixed>
$configCache
= []
An array holding cached configuration data.
$configsPath
The absolute path to the application configurations directory.
protected
string
$configsPath
Path to the configuration directory.
$defaultMiddlewares
Default middlewares applied to the application.
protected
static array<string|int, mixed>
$defaultMiddlewares
Default middlewares.
$defaultWhitelist
Default whitelist settings for the application.
protected
static array<string|int, mixed>
$defaultWhitelist
Default whitelist settings.
$frameworkConfigsPath
The absolute path to the framework's configuration files.
protected
static string
$frameworkConfigsPath
Path to the framework's configuration directory.
Methods
__construct()
Constructor for the configuration manager.
public
__construct([array<string|int, mixed> $preloadConfigs = ['tenancy', 'tenants', 'kiosk', 'shortinit'] ][, null|string $appPath = null ]) : mixed
Initializes the application paths, framework configuration paths, and preloads specific configuration files. Also sets default values for the whitelist and middlewares, and caches the configuration.
Parameters
- $preloadConfigs : array<string|int, mixed> = ['tenancy', 'tenants', 'kiosk', 'shortinit']
-
Optional. List of configuration files to preload. Defaults to ['tenancy', 'tenants', 'kiosk'].
- $appPath : null|string = null
-
Optional. Custom application directory path. If not provided, defaults to the
APP_DIR_PATH
constant.
Return values
mixed —addConfig()
public
addConfig(string $file) : void
Parameters
- $file : string
-
The base name of the configuration file (without the
.json
extension).
Return values
void —app()
Loads the `app` options separately to avoid side effects.
public
app() : static
This method initializes the app
configuration options and caches it.
Afterward, it refreshes the entire configuration.
Return values
static —Returns the current instance of the class after refreshing the configuration.
appOptions()
public
appOptions() : array<string|int, mixed>
Return values
array<string|int, mixed> —clearConfigCache()
Clear the configuration cache or optionally for a specific key.
public
clearConfigCache([string|null $key = null ]) : void
Parameters
- $key : string|null = null
Return values
void —dbAdminer()
Load the Adminer script.
public
static dbAdminer() : void
Tags
Return values
void —defaultConfigPath()
public
static defaultConfigPath() : mixed
Return values
mixed —envTenantId()
public
static envTenantId() : string|null
Return values
string|null —get()
public
get([string|null $key = null ][, mixed $default = null ]) : mixed
Parameters
- $key : string|null = null
- $default : mixed = null
Return values
mixed —getActivePlugins()
public
getActivePlugins() : mixed
Return values
mixed —getAppPath()
public
getAppPath() : mixed
Return values
mixed —getConfig()
Get a loaded configuration by key.
public
getConfig(string $key) : DotAccess|null
Parameters
- $key : string
Return values
DotAccess|null —getConfigsDir()
public
getConfigsDir() : mixed
Return values
mixed —getDefault()
public
static getDefault() : array<string|int, null|mixed|(null|bool|mixed|(null|bool|int|mixed|string|string[])[]|string)[]>
Tags
Return values
array<string|int, null|mixed|(null|bool|mixed|(null|bool|int|mixed|string|string[])[]|string)[]> —getTenantFilePath()
Retrieves the path for a tenant-specific file, with an option to enforce strict finding.
public
getTenantFilePath(string $dir[, bool $find_or_fail = false ]) : null|array<string|int, null|mixed|(null|bool|mixed|(null|false|int|mixed|string)[]|string)[]|string>|string
In a multi-tenant application, this function attempts to find a file specific to the current tenant. If the file is not found and 'find_or_fail' is set to true, the function will return null. If the tenant-specific file does not exist (and 'find_or_fail' is false), it falls back to a default file path. If neither file is found, or the application is not in multi-tenant mode, null is returned.
Parameters
- $dir : string
-
The directory within the app path where the file should be located.
- $find_or_fail : bool = false
-
Whether to fail if the tenant-specific file is not found.
Tags
Return values
null|array<string|int, null|mixed|(null|bool|mixed|(null|false|int|mixed|string)[]|string)[]|string>|string —init()
Initializes the configuration manager with a specific application path.
public
static init([string $appPath = null ]) : self
Creates a new instance of the class, preloading the default configuration files ('tenancy', 'tenants', 'kiosk') and setting the provided application path.
Parameters
- $appPath : string = null
-
The absolute path to the application directory.
Return values
self —Returns an instance of the class.
isInProdEnvironment()
Determines if the application is running in a production environment.
public
static isInProdEnvironment([array<string|int, mixed> $prodEnvironments = ['secure', 'sec', 'production', 'prod'] ]) : bool
This method checks the current environment against a list of production
environment identifiers. The list of identifiers can be configured via the
prod
configuration key or will default to common production identifiers
such as 'secure', 'sec', 'production', and 'prod'.
Parameters
- $prodEnvironments : array<string|int, mixed> = ['secure', 'sec', 'production', 'prod']
Return values
bool —True if the application is in a production environment, false otherwise.
isPhpFile()
Determines if a given file is a PHP file by checking its extension and searching for valid PHP opening tags in its content.
public
static isPhpFile(string $filePath[, int $readBytes = 1024 ]) : bool
Parameters
- $filePath : string
-
The file path or filename.
- $readBytes : int = 1024
-
Maximum number of bytes to read from the start of the file (default: 1024).
Return values
bool —True if the file is recognized as a PHP file, False otherwise.
isProd()
Determines if the given environment is a production environment.
public
static isProd(null|string $environment[, array<string|int, mixed> $production = ['secure', 'sec', 'production', 'prod'] ]) : bool
This method checks whether the provided environment string matches
one of the predefined production environment names. If the environment
is null
, it defaults to assuming a production environment for safety,
ensuring sensitive data is not accidentally exposed.
Parameters
- $environment : null|string
-
The current environment name. Can be
null
. - $production : array<string|int, mixed> = ['secure', 'sec', 'production', 'prod']
-
An array of environment names that are considered production. Defaults to ['secure', 'sec', 'production', 'prod'].
Return values
bool —Returns true
if the environment is null
or matches one
of the production names, otherwise returns false
.
json()
public
json([string|null $filePath = null ]) : mixed
Parameters
- $filePath : string|null = null
Return values
mixed —load()
Load a configuration file by name.
public
static load(string $file) : void
Parameters
- $file : string
-
The configuration file name (without extension).
Tags
Return values
void —loadArrayFile()
Safely require a file that should return an array.
public
static loadArrayFile(string $filePath) : array<string|int, mixed>
Parameters
- $filePath : string
-
The path to the PHP file that returns an array.
Tags
Return values
array<string|int, mixed> —The array loaded from the file.
updateConfigCache()
Add to the configuration cache.
public
updateConfigCache(string $key, DotAccess $item) : void
Parameters
- $key : string
- $item : DotAccess
Return values
void —wpdb()
public
static wpdb([string|null $tableNameNoPrefix = null ]) : mixed
Parameters
- $tableNameNoPrefix : string|null = null
Return values
mixed —appSettingsFileArray()
protected
appSettingsFileArray() : array<string|int, mixed>
Return values
array<string|int, mixed> —getConfigsPath()
protected
getConfigsPath(string $appPath) : mixed
Parameters
- $appPath : string
Return values
mixed —getDefaultWhitelist()
protected
static getDefaultWhitelist() : array<string|int, array<string|int, string>>
Tags
Return values
array<string|int, array<string|int, string>> —loadConfigFile()
Loads and merges a JSON configuration file into the configuration cache.
protected
loadConfigFile(string $file[, null|string $defaultPath = null ]) : null|DotAccess
This method attempts to load a configuration file from multiple sources,
merges configuration data from user-defined and default paths, and caches
the result for future use. Special handling is provided for composer.json
,
which is directly processed if it exists.
Parameters
- $file : string
-
The base name of the configuration file (without the
.json
extension). - $defaultPath : null|string = null
-
Optional. A fallback path to look for the configuration file if it is not found in the user-defined configuration path. Defaults to the result of
self::defaultConfigPath()
.
Tags
Return values
null|DotAccess —Returns an instance of DotAccess
containing the merged configuration data,
or null
if the configuration file does not exist.
multiMerge()
Merges two multi-dimensional arrays recursively.
protected
static multiMerge(array<string|int, mixed> $array1, array<string|int, mixed> $array2) : array<string|int, mixed>
This function will recursively merge the values of $array2
into $array1
.
If the same key exists in both arrays, and both corresponding values are arrays,
the values are recursively merged.
Otherwise, values from $array2
will overwrite those in $array1
.
Parameters
- $array1 : array<string|int, mixed>
-
The base array that will be merged into.
- $array2 : array<string|int, mixed>
-
The array with values to merge into
$array1
.
Return values
array<string|int, mixed> —The merged array.
refreshConfig()
protected
refreshConfig() : static
Return values
static —setEnvWhitelist()
protected
setEnvWhitelist(array<string|int, mixed> $defaultWhitelist) : array<string|int, mixed>
Parameters
- $defaultWhitelist : array<string|int, mixed>
Return values
array<string|int, mixed> —setMiddlewares()
protected
setMiddlewares(array<string|int, mixed> $defaultMiddlewares) : array<string|int, mixed>
Parameters
- $defaultMiddlewares : array<string|int, mixed>
Return values
array<string|int, mixed> —dbUrl()
Generates a hashed Adminer URL using a specified hashing algorithm.
private
static dbUrl(string $hashAlgo) : string
Parameters
- $hashAlgo : string
-
The hashing algorithm to use (e.g., 'fnv1a64', 'sha256', 'md5').
Return values
string —The hashed database URL.
getDefaultMiddlewares()
private
static getDefaultMiddlewares() : mixed