Skip to content

Commit cb7998c

Browse files
Merge pull request #1 from InitPHP/2.x
Add PHP 8.0, 8.1, 8.2, 8.3, 8.4 to CI matrix
2 parents c95abc9 + 21a078e commit cb7998c

24 files changed

Lines changed: 2531 additions & 242 deletions

.github/workflows/ci.yml

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

.gitignore

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

.php-cs-fixer.dist.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$finder = PhpCsFixer\Finder::create()
6+
->in(__DIR__ . '/src')
7+
->in(__DIR__ . '/tests')
8+
->name('*.php');
9+
10+
return (new PhpCsFixer\Config())
11+
->setRiskyAllowed(true)
12+
->setRules([
13+
'@PSR12' => true,
14+
'array_syntax' => ['syntax' => 'short'],
15+
'declare_strict_types' => true,
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' => ['elements' => ['arrays']],
23+
'native_function_invocation' => false,
24+
'native_constant_invocation' => false,
25+
'phpdoc_align' => ['align' => 'left'],
26+
'phpdoc_separation' => true,
27+
'phpdoc_trim' => true,
28+
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
29+
])
30+
->setFinder($finder);

CHANGELOG.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Changelog
2+
3+
All notable changes to `initphp/logger` are documented here.
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
9+
### Added
10+
11+
- Full PSR-3 v3 compliance: every handler now implements
12+
`Psr\Log\LoggerInterface` directly, including `Logger`, which previously
13+
relied on `__call()` for dispatch.
14+
- `Throwable` rendering for context placeholders — any `\Throwable` value in
15+
the context array is rendered as `Class(code): message in file:line`.
16+
- `string|\Stringable` accepted as message type across all handlers.
17+
- `FileLogger`:
18+
- Automatic creation of the parent directory (mode `0775`).
19+
- Concurrent-safe writes via `FILE_APPEND | LOCK_EX`.
20+
- `getPath()` accessor returning the token-interpolated path.
21+
- `PDOLogger`:
22+
- Table-name validation against `/^[A-Za-z_][A-Za-z0-9_]*$/` to prevent
23+
identifier injection.
24+
- Distinct, specific error messages for each invalid construction path.
25+
- `getTable()` accessor.
26+
- `Logger`:
27+
- At least one logger is now required at construction time.
28+
- Variadic `LoggerInterface` typing — non-`LoggerInterface` arguments raise
29+
`TypeError` instead of being silently dropped.
30+
- `getLoggers()` accessor.
31+
- Comprehensive PHPUnit test suite (45 tests, 80 assertions).
32+
- PHPStan (`level: max`) and PHP-CS-Fixer (PSR-12) configured and CI-enforced.
33+
- GitHub Actions CI matrix: PHP 8.0 / 8.1 / 8.2 / 8.3 / 8.4.
34+
- `docs/` directory with eight topic guides (getting started, file logger,
35+
PDO logger, multi-logger, custom handlers, PSR-3 context, recipes, testing).
36+
37+
### Changed
38+
39+
- **Minimum PHP version raised to 8.0** (was 5.6). PHP 8.0+ is required for
40+
PSR-3 v3 anyway.
41+
- **`psr/log` constraint bumped to `^3.0`** (was the pinned `1.1.4`).
42+
- All source files now declare `strict_types=1` and use property/parameter/
43+
return-type declarations.
44+
- `Logger` is now `final`. Sub-classing it was never documented; users who
45+
need to customise fan-out behaviour should compose with `LoggerInterface`.
46+
- Log lines emitted by `FileLogger` now terminate with `PHP_EOL` instead of
47+
beginning with one — the previous behaviour produced a stray empty line at
48+
the top of every log file and made tailing awkward.
49+
50+
### Fixed
51+
52+
- `HelperTrait::$levels` no longer contains `LogLevel::WARNING` twice; the
53+
list now mirrors the canonical eight PSR-3 levels in severity order.
54+
- `FileLogger` no longer silently swallows write failures with the `@`
55+
operator; failures are reported through `error_log()`.
56+
- `FileLogger` rejects missing/empty/non-string `path` options at
57+
construction with a clear `InvalidArgumentException`, instead of failing
58+
obliquely at the first write.
59+
- `PDOLogger` raises specific, actionable `InvalidArgumentException` messages
60+
for each missing or wrongly-typed option (previously a single generic
61+
"It must be a PDO object." message was thrown for several distinct
62+
failures).
63+
- `PDOLogger` uses `Psr\Log\InvalidArgumentException` consistently per
64+
PSR-3 §1.1 (the previous code imported it but threw the SPL variant).
65+
- `PDOLogger::__destruct` removed — manually nulling an injected PDO is not
66+
the logger's responsibility and could mislead readers about ownership.
67+
68+
### Removed
69+
70+
- `Logger::__call()` magic dispatch. The class now implements
71+
`LoggerInterface` properly.
72+
73+
**Behaviour change for callers:** Previously, calling an unknown method on
74+
`Logger` (e.g. `$logger->banana()`) silently no-op'd via `__call()`.
75+
Such calls now raise `Error: Call to undefined method
76+
InitPHP\Logger\Logger::banana()` at the PHP level. Legitimate PSR-3 calls
77+
(`emergency()``debug()`, `log()`) are unaffected.
78+
79+
## 1.0 - 2022-03-11
80+
81+
Initial release.

0 commit comments

Comments
 (0)