Oihana PHP System

ConfigTrait

Trait ConfigTrait

Provides functionality for managing a configuration setup.

Table of Contents

Constants

CONFIG  = 'config'
The 'config' key for initialization arrays.
CONFIG_PATH  = 'configPath'
The 'configPath' key for initialization arrays.

Properties

$config  : array<string|int, mixed>
$configPath  : string

Methods

initConfig()  : static
Initialize the configuration from an array or a DI container.
initConfigPath()  : static
Initialize the configuration path from an array or a DI container.

Constants

CONFIG

The 'config' key for initialization arrays.

public mixed CONFIG = 'config'

CONFIG_PATH

The 'configPath' key for initialization arrays.

public mixed CONFIG_PATH = 'configPath'

Properties

$config

public array<string|int, mixed> $config = []

The config reference.

$configPath

public string $configPath = \oihana\enums\Char::EMPTY

The base path of the file to load an external config.

Methods

initConfig()

Initialize the configuration from an array or a DI container.

public initConfig([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

Example usage:

$this->initConfig( ['config' => ['db_host' => 'localhost']] ) ;
echo $this->config['db_host'] ; // 'localhost'

// Using a DI container
$container->set( 'my_config' , ['db_name' => 'prod'] ) ;
$this->initConfig( ['config' => 'my_config' ] , $container ) ;
echo $this->config[ 'db_name' ] ; // 'prod'
Parameters
$init : array<string|int, mixed> = []

Initialization array that may contain 'config' key.

$container : ContainerInterface|null = null

Optional DI container to resolve config entries.

Tags
throws
DependencyException
throws
NotFoundException
throws
NotFoundExceptionInterface
throws
ContainerExceptionInterface
Return values
static

Returns the current instance for method chaining.

initConfigPath()

Initialize the configuration path from an array or a DI container.

public initConfigPath([array<string|int, mixed> $init = [] ][, ContainerInterface|null $container = null ]) : static

Example usage:

$this->initConfigPath(['configPath' => '/etc/myservice/config']);
echo $this->configPath; // '/etc/myservice/config'

// Using a DI container
$container->set('configPath', '/etc/prod/config');
$this->initConfigPath([], $container);
echo $this->configPath; // '/etc/prod/config'
Parameters
$init : array<string|int, mixed> = []

Initialization array that may contain 'configPath' key.

$container : ContainerInterface|null = null

Optional DI container to resolve path entries.

Tags
throws
DependencyException
throws
NotFoundException
throws
NotFoundExceptionInterface
throws
ContainerExceptionInterface
Return values
static

Returns the current instance for method chaining.


        
On this page

Search results