Aplus Framework Docs

Config
in package

Class Config.

Table of Contents

$configs  : array<string|int, mixed>
$configsDir  : string|null
$persistence  : array<string|int, mixed>
$suffix  : string
__construct()  : mixed
Config constructor.
add()  : array<string|int, mixed>
Add configs to a service instance.
get()  : array<string|int, mixed>|null
Get configs by a service instance.
getAll()  : array<string, array<string, array<string|int, mixed>>>
Get all configs.
getDir()  : string|null
Get the base directory.
getInstances()  : array<string, array<string, mixed>>|null
Get service instances configs.
load()  : static
Load a config file.
set()  : array<string|int, mixed>
Set configs to a service instance.
setDir()  : static
Set the base directory.
setMany()  : static
Set many configs in one call.
getPersistentConfigs()  : array<string|int, mixed>
Get configs with persistence.
replacePersistence()  : void
Replace configs with persistent configs.
setPersistence()  : void
Set persistent configs.

Properties

$configs

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

$configsDir

protected string|null $configsDir = null

$persistence

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

$suffix

protected string $suffix

Methods

__construct()

Config constructor.

public __construct([array<string, array<string, array<string|int, mixed>>>|string|null $configs = null ][, array<string, array<string, array<string|int, mixed>>> $persistence = [] ][, string $suffix = '.php' ]) : mixed
Parameters
$configs : array<string, array<string, array<string|int, mixed>>>|string|null = null

An array to set many configs, the config base directory or null

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

Configs that will always overwrite custom added, loaded or set configs

$suffix : string = '.php'

The services filenames suffix used when the config directory is set

Return values
mixed

add()

Add configs to a service instance.

public add(string $name, array<string|int, mixed> $configs[, string $instance = 'default' ]) : array<string|int, mixed>

NOTE: IF the service instance already exists, the configs will be merged

Parameters
$name : string

The service name

$configs : array<string|int, mixed>

The service configs

$instance : string = 'default'

The service instance

Return values
array<string|int, mixed>

The service instance configs

get()

Get configs by a service instance.

public get(string $name[, string $instance = 'default' ]) : array<string|int, mixed>|null
Parameters
$name : string

The service name

$instance : string = 'default'

The service instance

Tags
throws
LogicException

If the service configs are empty and the Config directory is set, and the config file is not found

Return values
array<string|int, mixed>|null

The instance configs as array or null if is not set

getAll()

Get all configs.

public getAll() : array<string, array<string, array<string|int, mixed>>>
Return values
array<string, array<string, array<string|int, mixed>>>

All many configs

getDir()

Get the base directory.

public getDir() : string|null
Return values
string|null

The directory realpath or null if it was not set

getInstances()

Get service instances configs.

public getInstances(string $name) : array<string, array<string, mixed>>|null
Parameters
$name : string

The service name

Return values
array<string, array<string, mixed>>|null

The service instance names as keys and its configs as values or null if the service is not set

load()

Load a config file.

public load(string $name) : static
Parameters
$name : string

The file name without the directory path and the suffix

Tags
throws
LogicException

If the config file is not found

Return values
static

set()

Set configs to a service instance.

public set(string $name, array<string|int, mixed> $configs[, string $instance = 'default' ]) : array<string|int, mixed>

NOTE: These configs will replace an existing instance (except persistence).

Parameters
$name : string

The service name

$configs : array<string|int, mixed>

The new configs

$instance : string = 'default'

The service instance

Return values
array<string|int, mixed>

The service instance configs

setDir()

Set the base directory.

public setDir(string $directory) : static
Parameters
$directory : string

Directory path

Tags
throws
LogicException

If the config directory is not found

Return values
static

setMany()

Set many configs in one call.

public setMany(array<string, array<string, array<string|int, mixed>>> $configs) : static

NOTE: The $configs will replace existing instances (except persistence).

Parameters
$configs : array<string, array<string, array<string|int, mixed>>>

The service names as keys and its instance configs as values

Return values
static

getPersistentConfigs()

Get configs with persistence.

protected getPersistentConfigs(string $name, string $instance) : array<string|int, mixed>
Parameters
$name : string

The service name

$instance : string

The service instance

Return values
array<string|int, mixed>

The service instance custom configs with persistent configs

replacePersistence()

Replace configs with persistent configs.

protected replacePersistence() : void
Return values
void

setPersistence()

Set persistent configs.

protected setPersistence(array<string, array<string|int, mixed>> $configs) : void
Parameters
$configs : array<string, array<string|int, mixed>>
Return values
void

Search results