Config class

Framework\Config\Config

Class Config.

Defined in libraries/config/src/Config.php

Properties #

$configs
-
$configsDir
-
$persistence
-
$suffix
-
$debugCollector
-

$configs

protected array $configs = array ( )

$configsDir

protected ?string $configsDir = NULL

$persistence

protected array $persistence = array ( )

$suffix

protected string $suffix

$debugCollector

protected \Framework\Config\Debug\ConfigCollector $debugCollector

Methods #

__construct()
Config constructor.
add()
Add configs to a service instance.
get()
Get configs by a service instance.
getAll()
Get all configs.
getDir()
Get the base directory.
getInstances()
Get service instances configs.
load()
Load a config file.
set()
Set configs to a service instance.
setDebugCollector()
-
setDir()
Set the base directory.
setMany()
Set many configs in one call.
getPersistentConfigs()
Get configs with persistence.
loadFile()
-
replacePersistence()
Replace configs with persistent configs.
setPersistence()
Set persistent configs.

__construct()

public function __construct(array|string|null $configs = NULL, array $persistence = array ( ), string $suffix = '.php')

Config constructor.

Parameters
  • array|string|null $configs - An array to set many configs, the config base directory or null
  • array $persistence - Configs that will always overwrite custom added, loaded or set configs
  • string $suffix - The services filenames suffix used when the config directory is set

add()

public function add(string $name, array $configs, string $instance = 'default'): array

Add configs to a service instance.

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

Parameters
  • string $name - The service name
  • array $configs - The service configs
  • string $instance - The service instance
Returns array - The service instance configs

get()

public function get(string $name, string $instance = 'default'): ?array

Get configs by a service instance.

Parameters
  • string $name - The service name
  • string $instance - The service instance
Returns ?array - The instance configs as array or null if is not set
throws
LogicException If the service configs are empty and the Config directory is set, and the config file is not found

getAll()

public function getAll(): array

Get all configs.

Returns array - All many configs

getDir()

public function getDir(): ?string

Get the base directory.

Returns ?string - The directory realpath or null if it was not set

getInstances()

public function getInstances(string $name): ?array

Get service instances configs.

Parameters
  • string $name - The service name
Returns ?array - The service instance names as keys and its configs as values or null if the service is not set

load()

public function load(string $name): static

Load a config file.

Parameters
  • string $name - The file name without the directory path and the suffix
Returns static
throws
LogicException If the config file is not found

set()

public function set(string $name, array $configs, string $instance = 'default'): array

Set configs to a service instance.

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

Parameters
  • string $name - The service name
  • array $configs - The new configs
  • string $instance - The service instance
Returns array - The service instance configs

setDebugCollector()

public function setDebugCollector(\Framework\Config\Debug\ConfigCollector $debugCollector): static
Parameters
  • \Framework\Config\Debug\ConfigCollector $debugCollector
Returns static

setDir()

public function setDir(string $directory): static

Set the base directory.

Parameters
  • string $directory - Directory path
Returns static
throws
LogicException If the config directory is not found

setMany()

public function setMany(array $configs): static

Set many configs in one call.

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

Parameters
  • array $configs - The service names as keys and its instance configs as values
Returns static

getPersistentConfigs()

protected function getPersistentConfigs(string $name, string $instance): array

Get configs with persistence.

Parameters
  • string $name - The service name
  • string $instance - The service instance
Returns array - The service instance custom configs with persistent configs

loadFile()

protected function loadFile(string $name): static
Parameters
  • string $name
Returns static

replacePersistence()

protected function replacePersistence(): void

Replace configs with persistent configs.

Returns void

setPersistence()

protected function setPersistence(array $configs): void

Set persistent configs.

Parameters
  • array $configs
Returns void