Skip to content

Commit 3058fd3

Browse files
authored
Merge pull request #3 from Micro-PHP/v1.2
Implements v1.2 version
2 parents 30e16d1 + 80cf88b commit 3058fd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1108
-436
lines changed

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
/phpunit.xml.dist export-ignore
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.php-cs-fixer.dist.php export-ignore
7+
/psalm.xml export-ignore
8+
9+
*.php diff=php

.github/workflows/.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[{*.yaml,*.yml}]
2+
indent_size = 2

.github/workflows/ci.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Plugin CI
2+
on:
3+
push:
4+
branches: [ 'master' ]
5+
pull_request:
6+
7+
env:
8+
PHP_CS_FIXER_IGNORE_ENV: 1
9+
XDEBUG_MODE: coverage
10+
11+
jobs:
12+
tests:
13+
name: "Tests ${{ matrix.php-version }} deps ${{ matrix.dependency-versions }}"
14+
runs-on: ubuntu-22.04
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
# normal, highest, non-dev installs
20+
php-version: [ '8.2' ]
21+
dependency-versions: [ 'highest' ]
22+
include:
23+
# testing lowest PHP version with the lowest dependencies
24+
# - php-version: '8.2'
25+
# dependency-versions: 'lowest'
26+
27+
# testing dev versions with the highest PHP
28+
- php-version: '8.2'
29+
dependency-versions: 'highest'
30+
31+
steps:
32+
- name: "Checkout code"
33+
uses: "actions/checkout@v2"
34+
35+
- name: "Install PHP"
36+
uses: "shivammathur/setup-php@v2"
37+
with:
38+
coverage: "none"
39+
php-version: "${{ matrix.php-version }}"
40+
41+
- name: "Composer install"
42+
uses: "ramsey/composer-install@v2"
43+
with:
44+
dependency-versions: "${{ matrix.dependency-versions }}"
45+
composer-options: "--prefer-dist --no-progress"
46+
47+
- name: Run tests
48+
run: composer run test

.gitignore

100755100644
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
vendor/
1+
.idea
2+
vendor
23
composer.lock
34
.phpunit.result.cache
5+
.php-cs-fixer.cache
6+
test-coverage-report
7+
phpunit.xml
8+
.php-cs-fixer.php
9+
phpstan.neon

.php-cs-fixer.dist.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
if (!file_exists(__DIR__.'/src')) {
4+
exit(0);
5+
}
6+
7+
$finder = (new PhpCsFixer\Finder())
8+
->in(__DIR__.'/src')
9+
->in(__DIR__.'/tests')
10+
;
11+
12+
return (new PhpCsFixer\Config())
13+
->setRules(array(
14+
'@Symfony' => true,
15+
'@Symfony:risky' => true,
16+
'strict_param' => true,
17+
'array_syntax' => ['syntax' => 'short'],
18+
'protected_to_private' => false,
19+
'semicolon_after_instruction' => false,
20+
'header_comment' => [
21+
'header' => <<<EOF
22+
This file is part of the Micro framework package.
23+
24+
(c) Stanislau Komar <[email protected]>
25+
26+
For the full copyright and license information, please view the LICENSE
27+
file that was distributed with this source code.
28+
EOF
29+
]
30+
))
31+
->setRiskyAllowed(true)
32+
->setFinder($finder);

composer.json

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,61 @@
11
{
22
"name": "micro/plugin-logger-monolog",
3-
"description": "Micro Framework: Implements \"micro/plugin-logger-core\" based on Monolog.",
3+
"description": "Micro Framework: Monolog logger adapter for \"micro/plugin-logger-core\".",
4+
"license": "MIT",
45
"type": "library",
5-
"version": "1.1",
6+
"authors": [
7+
{
8+
"name": "Stanislau.Komar",
9+
"email": "[email protected]"
10+
}
11+
],
612
"require": {
7-
"monolog/monolog": "2.3.*",
8-
"micro/plugin-logger-core": "^1"
13+
"micro/kernel-boot-plugin-depended": "^1",
14+
"micro/plugin-logger-core": "dev-master",
15+
"monolog/monolog": "^3"
16+
},
17+
"require-dev": {
18+
"ergebnis/composer-normalize": "^2.29",
19+
"friendsofphp/php-cs-fixer": "^3.13",
20+
"phpstan/phpstan": "^1.9",
21+
"phpunit/php-code-coverage": "^9.2",
22+
"phpunit/phpunit": "^9.5",
23+
"vimeo/psalm": "^5.2"
924
},
10-
"license": "MIT",
1125
"autoload": {
1226
"psr-4": {
1327
"Micro\\Plugin\\Logger\\Monolog\\": "src/"
1428
}
1529
},
16-
"authors": [
17-
{
18-
"name": "Stanislau.Komar",
19-
"email": "[email protected]"
30+
"autoload-dev": {
31+
"psr-4": {
32+
"Micro\\Plugin\\Logger\\Monolog\\Test\\Unit\\": "tests/Unit"
2033
}
21-
]
34+
},
35+
"config": {
36+
"allow-plugins": {
37+
"ergebnis/composer-normalize": true
38+
},
39+
"sort-packages": true
40+
},
41+
"scripts": {
42+
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text",
43+
"coverage-html": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html ./test-coverage-report",
44+
"php-cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
45+
"php-cs-try": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
46+
"phpstan": "./vendor/bin/phpstan analyze --no-progress",
47+
"phpunit": "./vendor/bin/phpunit",
48+
"psalm": "./vendor/bin/psalm --no-progress --show-info=true",
49+
"statics": [
50+
"@phpstan",
51+
"@psalm",
52+
"@php-cs-try"
53+
],
54+
"test": [
55+
"@statics",
56+
"composer validate --strict",
57+
"composer normalize",
58+
"@coverage"
59+
]
60+
}
2261
}

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: 7
3+
paths:
4+
- src

phpunit.xml.dist

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- https://phpunit.readthedocs.io/en/9.5/configuration.html#the-phpunit-element -->
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
5+
backupGlobals="false"
6+
bootstrap="vendor/autoload.php"
7+
colors="true"
8+
failOnRisky="true"
9+
failOnWarning="true"
10+
>
11+
<php>
12+
<ini name="error_reporting" value="-1" force="true"/>
13+
</php>
14+
<testsuites>
15+
<testsuite name="Unit tests">
16+
<directory>tests/Unit</directory>
17+
</testsuite>
18+
</testsuites>
19+
<filter>
20+
<whitelist>
21+
<directory suffix=".php">src/</directory>
22+
<exclude>
23+
<directory>src/Exception</directory>
24+
<file>src/LoggerMonologPlugin.php</file>
25+
</exclude>
26+
</whitelist>
27+
</filter>
28+
<coverage>
29+
<include>
30+
<directory suffix=".php">src</directory>
31+
</include>
32+
<report>
33+
<html outputDirectory="test-coverage-report/" />
34+
</report>
35+
</coverage>
36+
</phpunit>

psalm.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="2"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
15+
</projectFiles>
16+
17+
<issueHandlers>
18+
19+
<UnnecessaryVarAnnotation>
20+
<errorLevel type="suppress">
21+
<file name="src/LoggerMonologPlugin.php"/>
22+
</errorLevel>
23+
</UnnecessaryVarAnnotation>
24+
25+
<MissingConstructor>
26+
<errorLevel type="suppress">
27+
<file name="src/LoggerMonologPlugin.php"/>
28+
</errorLevel>
29+
</MissingConstructor>
30+
31+
<ImplementedReturnTypeMismatch>
32+
<errorLevel type="suppress">
33+
<file name="src/LoggerMonologPlugin.php"/>
34+
</errorLevel>
35+
</ImplementedReturnTypeMismatch>
36+
</issueHandlers>
37+
38+
</psalm>

src/Business/Factory/LoggerFactory.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
<?php
22

3+
/*
4+
* This file is part of the Micro framework package.
5+
*
6+
* (c) Stanislau Komar <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Micro\Plugin\Logger\Monolog\Business\Factory;
413

514
use Micro\Plugin\Logger\Business\Factory\LoggerFactoryInterface;
15+
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
616
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerResolverFactoryInterface;
717
use Monolog\Logger;
818
use Psr\Log\LoggerInterface;
919

10-
class LoggerFactory implements LoggerFactoryInterface
20+
readonly class LoggerFactory implements LoggerFactoryInterface
1121
{
12-
/**
13-
* @param HandlerResolverFactoryInterface $handlerResolverFactory
14-
*/
1522
public function __construct(
16-
private HandlerResolverFactoryInterface $handlerResolverFactory
17-
)
18-
{
23+
private HandlerResolverFactoryInterface $handlerResolverFactory
24+
) {
1925
}
2026

21-
/**
22-
* {@inheritDoc}
23-
*/
24-
public function create(string $loggerName): LoggerInterface
27+
public function create(LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration): LoggerInterface
2528
{
26-
$logger = new Logger($loggerName);
29+
$logger = new Logger($loggerProviderTypeConfiguration->getLoggerName());
2730
$handlerCollectionGenerator = $this->handlerResolverFactory
28-
->create($loggerName)
31+
->create($loggerProviderTypeConfiguration)
2932
->resolve();
3033

31-
3234
$handlerCollection = iterator_to_array($handlerCollectionGenerator);
3335

34-
$logger->setHandlers($handlerCollection);
36+
$logger->setHandlers(array_values($handlerCollection));
3537

3638
return $logger;
3739
}

0 commit comments

Comments
 (0)