ttpryg / config
A flexible, standalone PHP configuration management library with dot-notation support.
Requires
- php: ^8.1 || ^8.2 || ^8.3
Requires (Dev)
- laravel/pint: ^1.20
- phpunit/phpunit: ^10.0
- rector/rector: ^2.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-17 14:46:18 UTC
README
A lightweight, standalone PHP configuration management library featuring dot-notation syntax, ArrayAccess support, multi-file directory loading, and database persistence (PDO / Custom Drivers).
Features
- Dot notation support: Access deeply nested values using
$config->get('database.connections.mysql.host'). - ArrayAccess Interface: Treat configuration object like an array
$config['app.name']. - Directory Auto-loader: Automatically load all
.phpconfiguration files in a directory into key-partitioned arrays. - Database Storage & Persistence: Load and save configuration directly to a database table via PDO driver (
PdoDatabaseDriver) or custom drivers. - Zero External Runtime Dependencies: Self-contained with zero external dependencies, easily portable across projects or published as a standalone composer package.
Package Structure (Composerable)
ttpryg/config/
├── composer.json
├── README.md
├── src/
│ ├── ConfigInterface.php
│ ├── ConfigRepository.php
│ ├── ConfigManager.php
│ └── Drivers/
│ ├── DatabaseDriverInterface.php
│ └── PdoDatabaseDriver.php
└── tests/
└── ConfigRepositoryTest.php
How to Reuse in Another Repository
-
Option A: Copy Folder Directly Copy the
ttpryg/config/folder into your new project and add the PSR-4 namespace to your project'scomposer.json:"autoload": { "psr-4": { "Ttpryg\\Config\\": "ttpryg/config/src/" } }
-
Option B: Path Repository (Local Composer Package) Add as a local path repository in another project's
composer.json:"repositories": [ { "type": "path", "url": "./ttpryg/config" } ], "require": { "ttpryg/config": "*" }
-
Option C: Publish to Git / Packagist Push the
ttpryg/configdirectory to its own GitHub repository (e.g.github.com/your-username/config) and require it via standard composer:composer require ttpryg/config
Quick Start Example
use Ttpryg\Config\ConfigManager; use Ttpryg\Config\ConfigRepository; use Ttpryg\Config\Drivers\PdoDatabaseDriver; // Method 1: Create manually $config = new ConfigRepository([ 'app' => [ 'name' => 'My App', 'env' => 'production', ], ]); // Access via dot-notation $appName = $config->get('app.name'); // "My App" $debug = $config->get('app.debug', false); // false (default) // Set nested values $config->set('database.mysql.host', '127.0.0.1'); // ArrayAccess syntax $config['jwt.secret'] = 'secret-key'; $secret = $config['jwt.secret']; // Method 2: Load from directory containing config PHP files $config = ConfigManager::createFromDirectory(__DIR__ . '/config'); // Method 3: Database Storage (PDO Driver) $pdo = new PDO('mysql:host=localhost;dbname=slim_db', 'root', 'password'); $dbDriver = new PdoDatabaseDriver($pdo, 'configs'); // Save config to database $config->saveToDatabase($dbDriver); // Load config from database $dbConfig = ConfigManager::createFromDatabase($dbDriver); $siteName = $dbConfig->get('site.name');