Download the PHP package philiprehberger/php-config-loader without Composer
On this page you can find all versions of the php package philiprehberger/php-config-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download philiprehberger/php-config-loader
More information about philiprehberger/php-config-loader
Files in philiprehberger/php-config-loader
Package php-config-loader
Short Description Load configuration from JSON and PHP files with environment variable substitution
License MIT
Homepage https://github.com/philiprehberger/php-config-loader
Informations about the package php-config-loader
PHP Config Loader
Load configuration from JSON, PHP, YAML, and TOML files with environment variable substitution.
Requirements
- PHP 8.2+
- ext-yaml (optional, required for YAML file support)
Installation
Usage
Loading a Single File
PHP config file (app.php):
JSON config file (database.json):
Dot-Notation Access
Typed Getters
Checking Key Existence
Environment Variable Substitution
Config values containing ${VAR} are resolved from environment variables at load time. Use ${VAR:default} to provide a fallback.
Loading a Directory
Load all .php, .json, .yaml, .yml, and .toml files from a directory. Each file's basename (without extension) becomes a top-level key.
Deep Merge
Combine two configurations with deep merging. Values from the second config override the first; nested arrays are merged recursively.
Flattening Nested Config
Convert nested configuration into a flat associative array with dot-notation keys.
Configuration Validation
Validate config values against a set of rules. Rules are pipe-separated.
Supported rules: required, string, int, bool, float.
API
| Method | Return Type | Description |
|---|---|---|
ConfigLoader::load(string $path) |
Config |
Load a single config file (PHP, JSON, YAML, TOML) |
ConfigLoader::loadDirectory(string $dir) |
Config |
Load all config files from a directory |
Config::get(string $key, mixed $default = null) |
mixed |
Get value by dot-notation key |
Config::string(string $key, string $default = '') |
string |
Get string value |
Config::int(string $key, int $default = 0) |
int |
Get integer value |
Config::bool(string $key, bool $default = false) |
bool |
Get boolean value |
Config::float(string $key, float $default = 0.0) |
float |
Get float value |
Config::array(string $key, array $default = []) |
array |
Get array value |
Config::has(string $key) |
bool |
Check if key exists |
Config::all() |
array |
Get all config data |
Config::keys() |
array |
Get all top-level configuration keys |
Config::merge(Config $other) |
Config |
Deep merge with another config |
Config::flatten(string $separator = '.') |
array |
Flatten nested config to dot-notation key-value pairs |
Config::validate(array $rules) |
array |
Validate config against rules, returns violation messages |
Development
Support
If you find this project useful:
License
MIT