Skip to content

Commit 532a53d

Browse files
committed
First commit!
0 parents  commit 532a53d

27 files changed

+1770
-0
lines changed

.docheader

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file is part of php-fast-forward/config.
3+
*
4+
* This source file is subject to the license bundled
5+
* with this source code in the file LICENSE.
6+
*
7+
* @link https://github.com/php-fast-forward/config
8+
* @copyright Copyright (c) 2025-%year% Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
9+
* @license https://opensource.org/licenses/MIT MIT License
10+
*/

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
/.github/ export-ignore
3+
/tests/ export-ignore
4+
/.docheader export-ignore
5+
/.dockerignore export-ignore
6+
/.editorconfig export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/.php-cs-fixer.php export-ignore
10+
/docker-compose export-ignore
11+
/Dockerfile export-ignore
12+
/infection.json5 export-ignore
13+
/phpunit.xml export-ignore

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea/
2+
public/
3+
vendor/
4+
composer.lock
5+
*.cache

.php-cs-fixer.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/config.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/config
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
use CoiSA\PhpCsFixer\PhpCsFixer;
17+
18+
$paths = [
19+
__FILE__,
20+
__DIR__,
21+
];
22+
23+
$header = file_get_contents(__DIR__ . '/.docheader');
24+
25+
return PhpCsFixer::create($paths, $header);

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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)

composer.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "fast-forward/config",
3+
"description": "Fast Forward Config utility classes",
4+
"license": "MIT",
5+
"type": "library",
6+
"authors": [
7+
{
8+
"name": "Felipe Sayão Lobato Abreu",
9+
"email": "github@mentordosnerds.com"
10+
}
11+
],
12+
"require": {
13+
"php": "^8.1",
14+
"dflydev/dot-access-data": "^3.0",
15+
"laminas/laminas-config-aggregator": "^1.13",
16+
"psr/simple-cache": "^3.0"
17+
},
18+
"require-dev": {
19+
"coisa/php-cs-fixer": "^2.1",
20+
"phpspec/prophecy-phpunit": "^2.3",
21+
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5"
22+
},
23+
"minimum-stability": "stable",
24+
"autoload": {
25+
"files": [
26+
"src/functions.php"
27+
],
28+
"psr-4": {
29+
"FastForward\\Config\\": "src/"
30+
}
31+
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"FastForward\\Config\\Tests\\": "tests/"
35+
}
36+
},
37+
"config": {
38+
"sort-packages": true
39+
},
40+
"extra": {
41+
"branch-alias": {
42+
"dev-main": "1.x-dev"
43+
}
44+
},
45+
"scripts": {
46+
"cs-check": "php-cs-fixer fix --dry-run --diff",
47+
"cs-fix": "php-cs-fixer fix",
48+
"mutation-testing": "infection --threads=4",
49+
"pre-commit": [
50+
"@cs-check",
51+
"@static-analysis",
52+
"@tests"
53+
],
54+
"static-analysis": "phpstan analyse --level 5 src",
55+
"tests": "phpunit --testdox"
56+
}
57+
}

phpunit.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
executionOrder="depends,defects"
6+
shortenArraysForExportThreshold="10"
7+
requireCoverageMetadata="true"
8+
beStrictAboutCoverageMetadata="true"
9+
beStrictAboutOutputDuringTests="true"
10+
displayDetailsOnPhpunitDeprecations="true"
11+
failOnPhpunitDeprecation="true"
12+
failOnRisky="true"
13+
failOnWarning="true">
14+
<testsuites>
15+
<testsuite name="Fast Forward Config test suite">
16+
<directory>tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
20+
<include>
21+
<directory>src</directory>
22+
</include>
23+
</source>
24+
<coverage>
25+
<report>
26+
<clover outputFile="public/coverage/clover.xml"/>
27+
<html outputDirectory="public/coverage" lowUpperBound="35" highLowerBound="70"/>
28+
<text outputFile="php://stdout"/>
29+
</report>
30+
</coverage>
31+
<logging>
32+
<testdoxHtml outputFile="public/coverage/testdox.html"/>
33+
</logging>
34+
</phpunit>

src/AggregateConfig.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of php-fast-forward/config.
7+
*
8+
* This source file is subject to the license bundled
9+
* with this source code in the file LICENSE.
10+
*
11+
* @link https://github.com/php-fast-forward/config
12+
* @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
13+
* @license https://opensource.org/licenses/MIT MIT License
14+
*/
15+
16+
namespace FastForward\Config;
17+
18+
/**
19+
* Class AggregateConfig.
20+
*
21+
* Represents an aggregated configuration loader that combines multiple configuration sources.
22+
* This class MUST be used to merge multiple configurations into a single, unified configuration structure.
23+
*
24+
* It SHALL lazily load and resolve configuration data only when invoked.
25+
*/
26+
final class AggregateConfig implements ConfigInterface
27+
{
28+
use LazyLoadConfigTrait;
29+
30+
/**
31+
* @var ConfigInterface[] A list of configuration providers to be aggregated.
32+
* Each configuration MUST implement ConfigInterface.
33+
*/
34+
private readonly array $configs;
35+
36+
/**
37+
* AggregateConfig constructor.
38+
*
39+
* Constructs a new instance by accepting a variadic list of configuration objects.
40+
* These configuration objects MUST implement the ConfigInterface.
41+
*
42+
* @param ConfigInterface ...$configs One or more configuration instances to aggregate.
43+
*/
44+
public function __construct(ConfigInterface ...$configs)
45+
{
46+
$this->configs = $configs;
47+
}
48+
49+
/**
50+
* Invokes the configuration aggregator.
51+
*
52+
* This method SHALL initialize a new ArrayConfig instance and populate it
53+
* with the values from each provided configuration source.
54+
*
55+
* It MUST return a fully merged configuration in the form of a ConfigInterface implementation.
56+
*
57+
* @return ConfigInterface the resulting merged configuration object
58+
*/
59+
public function __invoke(): ConfigInterface
60+
{
61+
$arrayConfig = new ArrayConfig();
62+
63+
foreach ($this->configs as $config) {
64+
$arrayConfig->set($config->toArray());
65+
}
66+
67+
return $arrayConfig;
68+
}
69+
}

0 commit comments

Comments
 (0)