hierone / config
Powerful and flexible configuration management system for PHP applications
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/hierone/config
Requires
- php: ^8.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.0
Suggests
- psr/cache: For PSR-6 compatible cache implementations
- psr/simple-cache: For PSR-16 compatible cache implementations
README
A powerful configuration management system for PHP applications. Load configuration from multiple sources with validation, caching, and dot notation access.
Installation
composer require hierone/config
Quick Start
use Hierone\Component\Config\Manager; // Auto-load config files from directory $config = Manager::create('/path/to/config'); // Or load manually $manager = new Manager(); $manager->load('/path/to/config.php'); $manager->load('/path/to/.env'); $manager->load('env'); // Environment variables // Access with dot notation $dbHost = $manager->get('database.host', 'localhost'); $appName = $manager->getString('app.name'); $debugMode = $manager->getBool('app.debug', false);
Features
- Multiple Sources: PHP files, JSON, .env files, environment variables, arrays
- Dot Notation: Access nested values with
app.database.host
- Type Conversion:
getString()
,getInt()
,getBool()
,getFloat()
,getArray()
- Validation: Schema-based validation with custom rules
- Caching: Performance optimization with TTL and tags
- Merging: Priority-based configuration merging
Usage Examples
Load Configuration
// PHP file: config.php return [ 'app' => ['name' => 'My App', 'debug' => true], 'database' => ['host' => 'localhost', 'port' => 3306] ]; $manager->load('/path/to/config.php'); echo $manager->get('app.name'); // "My App"
Environment Variables
// Load all environment variables $manager->load('env'); // Load with prefix (APP_DEBUG becomes app.debug) $manager->load('env', ['prefix' => 'APP_']);
Validation
use Hierone\Component\Config\Validator\SchemaValidator; $manager->setValidator(new SchemaValidator()); $schema = [ 'required' => ['app', 'database'], 'properties' => [ 'app' => [ 'properties' => [ 'name' => ['type' => 'string', 'minLength' => 1] ] ] ] ]; $manager->load('/path/to/config.php', ['schema' => $schema]);
Caching
use Hierone\Component\Config\Cache\ArrayCache; $manager->setCache(new ArrayCache()); $manager->load('/path/to/config.php', ['cache_ttl' => 3600]);
Requirements
- PHP 8.2+
License
MIT