Fast Forward Config utility classes

v1.1.1 2025-04-18 23:32 UTC

This package is auto-updated.

Last update: 2025-04-18 23:32:44 UTC


README

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.

โœจ Features

  • ๐Ÿ”‘ Dot notation access: config->get('app.env')
  • ๐Ÿ“ Load from arrays, directories, or providers
  • โ™ป๏ธ Lazy-loading with __invoke()
  • ๐Ÿงฉ Aggregation of multiple sources
  • ๐Ÿ—‚ Recursive directory support
  • ๐Ÿ’พ Optional PSR-16 compatible caching
  • ๐Ÿ”Œ Compatible with Laminas ConfigProviders

๐Ÿ“ฆ Installation

composer require php-fast-forward/config

๐Ÿš€ Quick Start

Load configuration from multiple sources:

use FastForward\Config\{config, configDir, configCache};
use Symfony\Component\Cache\Simple\FilesystemCache;

$config = config(
    ['app' => ['env' => 'production']],
    __DIR__ . '/config',
    \Vendor\Package\ConfigProvider::class
);

echo $config->get('app.env'); // "production"

Cache configuration using PSR-16:

$cache = new FilesystemCache();

$config = configCache(
    cache: $cache,
    ['foo' => 'bar']
);

echo $config->get('foo'); // "bar"

Load from a recursive directory:

$config = configDir(__DIR__ . '/config', recursive: true);

Use Laminas-style providers:

$config = configProvider([
    new Vendor\Package\Provider1(),
    new Vendor\Package\Provider2(),
]);

๐Ÿงช Access & Mutation

$config->set('db.host', 'localhost');
echo $config->get('db.host'); // "localhost"

$config->has('app.debug'); // true/false

print_r($config->toArray());

๐Ÿ“ Directory Structure Example

config/
โ”œโ”€โ”€ app.php
โ”œโ”€โ”€ db.php
โ””โ”€โ”€ services/
    โ””โ”€โ”€ mail.php

๐Ÿงฐ API Summary

  • config(...$configs): ConfigInterface
  • configCache(CacheInterface $cache, ...$configs): ConfigInterface
  • configDir(string $dir, bool $recursive = false, ?string $cache = null): ConfigInterface
  • configProvider(iterable $providers, ?string $cache = null): ConfigInterface

๐Ÿ›ก License

MIT ยฉ 2025 Felipe Sayรฃo Lobato Abreu