API Reference
ConfigRepository
WPZylos\Framework\Config\ConfigRepository
Configuration repository with dot-notation access and typed accessors.
__construct(array $items = [])
Create a new configuration repository.
| Parameter | Type | Default | Description |
|---|---|---|---|
$items | array | [] | Initial configuration items |
$config = new ConfigRepository(['app' => ['name' => 'My Plugin']]);
get(string $key, mixed $default = null): mixed
Get a configuration value using dot notation.
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Configuration key (e.g. 'app.debug') |
$default | mixed | null | Default value if key not found |
Returns: mixed - The configuration value or default.
$config->get('app.name'); // 'My Plugin'
$config->get('missing', 'default'); // 'default'
set(string $key, mixed $value): void
Set a configuration value using dot notation.
| Parameter | Type | Description |
|---|---|---|
$key | string | Configuration key |
$value | mixed | Value to set |
$config->set('app.version', '2.0.0');
has(string $key): bool
Check if a configuration key exists.
| Parameter | Type | Description |
|---|---|---|
$key | string | Configuration key |
Returns: bool
$config->has('app.name'); // true
all(): array
Get all configuration items.
Returns: array - All configuration items.
$items = $config->all();
string(string $key, string $default = ''): string
Get a value cast to string.
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Configuration key |
$default | string | '' | Default value |
Returns: string
$config->string('app.name'); // 'My Plugin'
$config->string('missing', 'fallback'); // 'fallback'
int(string $key, int $default = 0): int
Get a value cast to integer.
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Configuration key |
$default | int | 0 | Default value |
Returns: int
$config->int('database.port', 3306); // 3306
float(string $key, float $default = 0.0): float
Get a value cast to float.
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Configuration key |
$default | float | 0.0 | Default value |
Returns: float
$config->float('rate.tax', 0.15); // 0.15
bool(string $key, bool $default = false): bool
Get a value cast to boolean. Recognizes string values 'true', '1', 'yes', 'on' as true.
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Configuration key |
$default | bool | false | Default value |
Returns: bool
$config->bool('app.debug'); // true
$config->bool('missing', false); // false
array(string $key, array $default = []): array
Get a value as an array. Returns the default if the stored value is not an array.
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Configuration key |
$default | array | [] | Default value |
Returns: array
$config->array('app.providers', []); // ['Provider1', 'Provider2']
loadDirectory(string $path): void
Load all PHP configuration files from a directory. Each file should return an array. The filename (without .php extension) becomes the top-level configuration key.
| Parameter | Type | Description |
|---|---|---|
$path | string | Directory path |
$config->loadDirectory(__DIR__ . '/config');
// config/app.php -> $config->get('app.*')
Silently returns if the directory does not exist.
merge(array $items): void
Deep-merge items into the repository using array_replace_recursive.
| Parameter | Type | Description |
|---|---|---|
$items | array | Items to merge |
$config->merge(['app' => ['version' => '2.0']]);
EnvLoader
WPZylos\Framework\Config\EnvLoader
Parses .env files and optionally sets environment variables. Handles comments, quoted values, escape sequences, and special values.
__construct(bool $setEnv = true, bool $setPutenv = false)
Create a new environment loader.
| Parameter | Type | Default | Description |
|---|---|---|---|
$setEnv | bool | true | Set values in $_ENV |
$setPutenv | bool | false | Set values via putenv() |
$env = new EnvLoader(setEnv: true, setPutenv: false);
load(string $path): bool
Load and parse a .env file. Does not throw if the file is missing.
| Parameter | Type | Description |
|---|---|---|
$path | string | Path to .env file |
Returns: bool - true if loaded successfully, false if missing or unreadable.
$env->load(__DIR__ . '/.env');
get(string $key, ?string $default = null): ?string
Get a parsed environment value.
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Variable name |
$default | ?string | null | Default value |
Returns: ?string
$env->get('APP_DEBUG'); // 'true'
$env->get('MISSING', 'fallback'); // 'fallback'
has(string $key): bool
Check if a variable was parsed from the .env file.
| Parameter | Type | Description |
|---|---|---|
$key | string | Variable name |
Returns: bool
$env->has('APP_DEBUG'); // true
all(): array
Get all parsed environment values.
Returns: array
$values = $env->all();
static env(string $key, mixed $default = null): mixed
Static helper to get an environment value from any source. Checks $_ENV first, then getenv().
| Parameter | Type | Default | Description |
|---|---|---|---|
$key | string | - | Variable name |
$default | mixed | null | Default value |
Returns: mixed
EnvLoader::env('APP_DEBUG', false);
ConfigServiceProvider
WPZylos\Framework\Config\ConfigServiceProvider extends WPZylos\Framework\Core\ServiceProvider
Registers the configuration system in the application container.
register(ApplicationInterface $app): void
Registers the config repository as a singleton. During registration:
- Creates a new
ConfigRepositoryinstance - Loads
.envfrom the plugin root viaEnvLoader - Loads config files from the
@configpath vialoadDirectory() - Binds a
'config'alias to theConfigRepositorysingleton
| Parameter | Type | Description |
|---|---|---|
$app | ApplicationInterface | Application instance |
// After registration:
$config = $app->make(ConfigRepository::class);
$config = $app->make('config');