Skip to content

Commit 7f284bb

Browse files
Merge pull request #1 from InitPHP/2.x
2.x
2 parents 1c6876e + a5f7531 commit 7f284bb

36 files changed

Lines changed: 2160 additions & 445 deletions

.editorconfig

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

.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* text=auto eol=lf
2+
3+
# Files to exclude from the distributed Composer package.
4+
/.editorconfig export-ignore
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.github export-ignore
8+
/.php-cs-fixer.dist.php export-ignore
9+
/phpstan.neon.dist export-ignore
10+
/phpunit.xml.dist export-ignore
11+
/tests export-ignore
12+
/docs export-ignore

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, "feat/*", "fix/*"]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
tests:
11+
name: PHP ${{ matrix.php }} on ${{ matrix.os }}
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os: [ubuntu-latest]
17+
php: ["8.1", "8.2", "8.3", "8.4"]
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php }}
26+
coverage: xdebug
27+
tools: composer:v2
28+
29+
- name: Validate composer.json
30+
run: composer validate --strict
31+
32+
- name: Get Composer cache directory
33+
id: composer-cache
34+
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
35+
36+
- name: Cache Composer packages
37+
uses: actions/cache@v4
38+
with:
39+
path: ${{ steps.composer-cache.outputs.dir }}
40+
key: ${{ runner.os }}-php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
41+
restore-keys: |
42+
${{ runner.os }}-php${{ matrix.php }}-composer-
43+
44+
- name: Install dependencies
45+
run: composer install --prefer-dist --no-progress --no-interaction
46+
47+
- name: Run test suite
48+
run: vendor/bin/phpunit --testdox
49+
50+
static-analysis:
51+
name: Static analysis (PHPStan)
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v4
55+
56+
- name: Setup PHP
57+
uses: shivammathur/setup-php@v2
58+
with:
59+
php-version: "8.3"
60+
tools: composer:v2
61+
62+
- name: Install dependencies
63+
run: composer install --prefer-dist --no-progress --no-interaction
64+
65+
- name: PHPStan
66+
run: vendor/bin/phpstan analyse --no-progress
67+
68+
code-style:
69+
name: Code style (PHP-CS-Fixer)
70+
runs-on: ubuntu-latest
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Setup PHP
75+
uses: shivammathur/setup-php@v2
76+
with:
77+
php-version: "8.1"
78+
tools: composer:v2
79+
80+
- name: Install dependencies
81+
run: composer install --prefer-dist --no-progress --no-interaction
82+
83+
- name: PHP-CS-Fixer (dry-run)
84+
run: vendor/bin/php-cs-fixer fix --dry-run --diff

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
/.vscode/
33
/.vs/
44
/vendor/
5-
/composer.lock
5+
/build/
6+
/composer.lock
7+
/.phpunit.cache/
8+
/.phpunit.result.cache
9+
/.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$finder = PhpCsFixer\Finder::create()
6+
->in([__DIR__ . '/src', __DIR__ . '/tests'])
7+
->name('*.php');
8+
9+
return (new PhpCsFixer\Config())
10+
->setRiskyAllowed(true)
11+
->setRules([
12+
'@PSR12' => true,
13+
'@PHP81Migration' => true,
14+
'declare_strict_types' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'no_unused_imports' => true,
17+
'ordered_imports' => [
18+
'sort_algorithm' => 'alpha',
19+
'imports_order' => ['class', 'function', 'const'],
20+
],
21+
'single_quote' => true,
22+
'trailing_comma_in_multiline' => true,
23+
'no_trailing_whitespace' => true,
24+
'no_whitespace_in_blank_line' => true,
25+
'blank_line_after_opening_tag' => true,
26+
'blank_line_before_statement' => ['statements' => ['return']],
27+
'method_chaining_indentation' => true,
28+
'native_function_invocation' => false,
29+
'phpdoc_align' => ['align' => 'vertical'],
30+
'phpdoc_separation' => true,
31+
'phpdoc_trim' => true,
32+
'no_superfluous_phpdoc_tags' => false,
33+
])
34+
->setFinder($finder)
35+
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache');

CHANGELOG.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Changelog
2+
3+
All notable changes to `initphp/config` are documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [2.0.0]
9+
10+
A correctness and modernisation release. It contains intentional
11+
backward-incompatible changes; review the **Changed** and **Removed**
12+
sections before upgrading from 1.x.
13+
14+
### Added
15+
16+
- `InitPHP\Config\AbstractConfig` — shared base implementing the common
17+
read/write contract for both `Library` and `Classes`.
18+
- `InitPHP\Config\Exceptions\ConfigException` — a dedicated
19+
`RuntimeException` with named constructors, thrown by every loader on
20+
failure (previously a generic `\Exception` was used).
21+
- `Library::replace()` — discard the whole tree and install a new one.
22+
- `Library::remove()` and `Config::remove()` — removal is now reachable
23+
from every entry point (it previously existed only on `Classes`).
24+
- `Config::reset()` — discard the shared facade instance (chiefly for
25+
test isolation).
26+
- Full test suite (PHPUnit), static analysis (PHPStan level 8), coding
27+
standard (PHP-CS-Fixer), and a GitHub Actions CI pipeline.
28+
- Developer documentation under `docs/`.
29+
30+
### Changed
31+
32+
- **Requires PHP 8.1+** (was 7.4+).
33+
- **Requires `initphp/parameterbag` `^2.0`** (was `^1.0`). The package now
34+
explicitly opts into case-insensitive keys so the documented behaviour
35+
is preserved against ParameterBag v2's case-sensitive default.
36+
- `setClass()` now imports an **object's runtime property values** when
37+
given an instance (it previously imported class defaults in both
38+
cases).
39+
- `setArray()` / `setFile()` with a `null`/empty name now **merge into the
40+
root** instead of replacing the entire tree. Use `Library::replace()`
41+
for the old replace-all behaviour.
42+
- `Library::close()` now resets to a usable empty bag (dotted-path and
43+
case-insensitive options preserved) instead of leaving the instance in
44+
an unusable state.
45+
46+
### Fixed
47+
48+
- `setDir()` applied its name prefix with inverted logic, so files were
49+
loaded under the wrong keys (e.g. `setDir('app', …)` did not produce
50+
`app.*` keys). The prefix is now applied correctly.
51+
- Object-style access (`$library->db`) silently collapsed every array
52+
element onto a single property, returning only the last value. It now
53+
builds a correct, recursively nested `stdClass`.
54+
- The `Config` facade tied the shared singleton's lifetime to instance
55+
destruction, which could leave it in a fatal, unusable state. The
56+
facade is now a pure static utility with explicit `reset()`.
57+
58+
### Removed
59+
60+
- The `Config` facade's instance API (`__construct`, `__destruct`,
61+
`__get`, `__call`, `__debugInfo`). The facade is now static-only and
62+
cannot be instantiated.
63+
- `Library::set(null, …)` as a replace-all shortcut — use
64+
`Library::replace()`.
65+
66+
## [1.0]
67+
68+
- Initial release.

0 commit comments

Comments
 (0)