|
| 1 | +# FastForward Config |
| 2 | + |
| 3 | +**FastForward Config** is a flexible and modern PHP configuration library built for performance, extendability, and lazy-loading behavior. It supports dot-notation keys, recursive directory loading, Laminas-compliant configuration providers, and optional PSR-16 caching. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## ✨ Features |
| 8 | + |
| 9 | +- 🔑 Dot notation access: `config->get('app.env')` |
| 10 | +- 📁 Load from arrays, directories, or providers |
| 11 | +- ♻️ Lazy-loading with `__invoke()` |
| 12 | +- 🧩 Aggregation of multiple sources |
| 13 | +- 🗂 Recursive directory support |
| 14 | +- 💾 Optional PSR-16 compatible caching |
| 15 | +- 🔌 Compatible with Laminas ConfigProviders |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## 📦 Installation |
| 20 | + |
| 21 | +```bash |
| 22 | +composer require php-fast-forward/config |
| 23 | +``` |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## 🚀 Quick Start |
| 28 | + |
| 29 | +### Load configuration from multiple sources: |
| 30 | + |
| 31 | +```php |
| 32 | +use FastForward\Config\{config, configDir, configCache}; |
| 33 | +use Symfony\Component\Cache\Simple\FilesystemCache; |
| 34 | + |
| 35 | +$config = config( |
| 36 | + ['app' => ['env' => 'production']], |
| 37 | + __DIR__ . '/config', |
| 38 | + \Vendor\Package\ConfigProvider::class |
| 39 | +); |
| 40 | + |
| 41 | +echo $config->get('app.env'); // "production" |
| 42 | +``` |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +### Cache configuration using PSR-16: |
| 47 | + |
| 48 | +```php |
| 49 | +$cache = new FilesystemCache(); |
| 50 | + |
| 51 | +$config = configCache( |
| 52 | + cache: $cache, |
| 53 | + ['foo' => 'bar'] |
| 54 | +); |
| 55 | + |
| 56 | +echo $config->get('foo'); // "bar" |
| 57 | +``` |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +### Load from a recursive directory: |
| 62 | + |
| 63 | +```php |
| 64 | +$config = configDir(__DIR__ . '/config', recursive: true); |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +### Use Laminas-style providers: |
| 70 | + |
| 71 | +```php |
| 72 | +$config = configProvider([ |
| 73 | + new Vendor\Package\Provider1(), |
| 74 | + new Vendor\Package\Provider2(), |
| 75 | +]); |
| 76 | +``` |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## 🧪 Access & Mutation |
| 81 | + |
| 82 | +```php |
| 83 | +$config->set('db.host', 'localhost'); |
| 84 | +echo $config->get('db.host'); // "localhost" |
| 85 | + |
| 86 | +$config->has('app.debug'); // true/false |
| 87 | + |
| 88 | +print_r($config->toArray()); |
| 89 | +``` |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## 📁 Directory Structure Example |
| 94 | + |
| 95 | +``` |
| 96 | +config/ |
| 97 | +├── app.php |
| 98 | +├── db.php |
| 99 | +└── services/ |
| 100 | + └── mail.php |
| 101 | +``` |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## 🧰 API Summary |
| 106 | + |
| 107 | +- `config(...$configs): ConfigInterface` |
| 108 | +- `configCache(CacheInterface $cache, ...$configs): ConfigInterface` |
| 109 | +- `configDir(string $dir, bool $recursive = false, ?string $cache = null): ConfigInterface` |
| 110 | +- `configProvider(iterable $providers, ?string $cache = null): ConfigInterface` |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## 🛡 License |
| 115 | + |
| 116 | +MIT © 2025 [Felipe Sayão Lobato Abreu](https://github.com/mentordosnerds) |
0 commit comments