Skip to content

Commit

Permalink
Implements v1.2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Asisyas committed Jan 15, 2023
1 parent 30e16d1 commit 3a28dd8
Show file tree
Hide file tree
Showing 47 changed files with 1,108 additions and 436 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/.github export-ignore
/tests export-ignore
/phpunit.xml.dist export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/psalm.xml export-ignore

*.php diff=php
2 changes: 2 additions & 0 deletions .github/workflows/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[{*.yaml,*.yml}]
indent_size = 2
48 changes: 48 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Plugin CI
on:
push:
branches: [ 'master' ]
pull_request:

env:
PHP_CS_FIXER_IGNORE_ENV: 1
XDEBUG_MODE: coverage

jobs:
tests:
name: "Tests ${{ matrix.php-version }} deps ${{ matrix.dependency-versions }}"
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
# normal, highest, non-dev installs
php-version: [ '8.2' ]
dependency-versions: [ 'highest' ]
include:
# testing lowest PHP version with the lowest dependencies
# - php-version: '8.2'
# dependency-versions: 'lowest'

# testing dev versions with the highest PHP
- php-version: '8.2'
dependency-versions: 'highest'

steps:
- name: "Checkout code"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Composer install"
uses: "ramsey/composer-install@v2"
with:
dependency-versions: "${{ matrix.dependency-versions }}"
composer-options: "--prefer-dist --no-progress"

- name: Run tests
run: composer run test
8 changes: 7 additions & 1 deletion .gitignore
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
vendor/
.idea
vendor
composer.lock
.phpunit.result.cache
.php-cs-fixer.cache
test-coverage-report
phpunit.xml
.php-cs-fixer.php
phpstan.neon
32 changes: 32 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

if (!file_exists(__DIR__.'/src')) {
exit(0);
}

$finder = (new PhpCsFixer\Finder())
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;

return (new PhpCsFixer\Config())
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false,
'semicolon_after_instruction' => false,
'header_comment' => [
'header' => <<<EOF
This file is part of the Micro framework package.
(c) Stanislau Komar <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF
]
))
->setRiskyAllowed(true)
->setFinder($finder);
59 changes: 49 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,61 @@
{
"name": "micro/plugin-logger-monolog",
"description": "Micro Framework: Implements \"micro/plugin-logger-core\" based on Monolog.",
"description": "Micro Framework: Monolog logger adapter for \"micro/plugin-logger-core\".",
"license": "MIT",
"type": "library",
"version": "1.1",
"authors": [
{
"name": "Stanislau.Komar",
"email": "[email protected]"
}
],
"require": {
"monolog/monolog": "2.3.*",
"micro/plugin-logger-core": "^1"
"micro/kernel-boot-plugin-depended": "^1",
"micro/plugin-logger-core": "dev-master",
"monolog/monolog": "^3"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.29",
"friendsofphp/php-cs-fixer": "^3.13",
"phpstan/phpstan": "^1.9",
"phpunit/php-code-coverage": "^9.2",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^5.2"
},
"license": "MIT",
"autoload": {
"psr-4": {
"Micro\\Plugin\\Logger\\Monolog\\": "src/"
}
},
"authors": [
{
"name": "Stanislau.Komar",
"email": "[email protected]"
"autoload-dev": {
"psr-4": {
"Micro\\Plugin\\Logger\\Monolog\\Test\\Unit\\": "tests/Unit"
}
]
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true
},
"sort-packages": true
},
"scripts": {
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text",
"coverage-html": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html ./test-coverage-report",
"php-cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
"php-cs-try": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
"phpstan": "./vendor/bin/phpstan analyze --no-progress",
"phpunit": "./vendor/bin/phpunit",
"psalm": "./vendor/bin/psalm --no-progress --show-info=true",
"statics": [
"@phpstan",
"@psalm",
"@php-cs-try"
],
"test": [
"@statics",
"composer validate --strict",
"composer normalize",
"@coverage"
]
}
}
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: 7
paths:
- src
36 changes: 36 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/9.5/configuration.html#the-phpunit-element -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
failOnRisky="true"
failOnWarning="true"
>
<php>
<ini name="error_reporting" value="-1" force="true"/>
</php>
<testsuites>
<testsuite name="Unit tests">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<exclude>
<directory>src/Exception</directory>
<file>src/LoggerMonologPlugin.php</file>
</exclude>
</whitelist>
</filter>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<html outputDirectory="test-coverage-report/" />
</report>
</coverage>
</phpunit>
38 changes: 38 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>

</projectFiles>

<issueHandlers>

<UnnecessaryVarAnnotation>
<errorLevel type="suppress">
<file name="src/LoggerMonologPlugin.php"/>
</errorLevel>
</UnnecessaryVarAnnotation>

<MissingConstructor>
<errorLevel type="suppress">
<file name="src/LoggerMonologPlugin.php"/>
</errorLevel>
</MissingConstructor>

<ImplementedReturnTypeMismatch>
<errorLevel type="suppress">
<file name="src/LoggerMonologPlugin.php"/>
</errorLevel>
</ImplementedReturnTypeMismatch>
</issueHandlers>

</psalm>
32 changes: 17 additions & 15 deletions src/Business/Factory/LoggerFactory.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
<?php

/*
* This file is part of the Micro framework package.
*
* (c) Stanislau Komar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Micro\Plugin\Logger\Monolog\Business\Factory;

use Micro\Plugin\Logger\Business\Factory\LoggerFactoryInterface;
use Micro\Plugin\Logger\Configuration\LoggerProviderTypeConfigurationInterface;
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerResolverFactoryInterface;
use Monolog\Logger;
use Psr\Log\LoggerInterface;

class LoggerFactory implements LoggerFactoryInterface
readonly class LoggerFactory implements LoggerFactoryInterface
{
/**
* @param HandlerResolverFactoryInterface $handlerResolverFactory
*/
public function __construct(
private HandlerResolverFactoryInterface $handlerResolverFactory
)
{
private HandlerResolverFactoryInterface $handlerResolverFactory
) {
}

/**
* {@inheritDoc}
*/
public function create(string $loggerName): LoggerInterface
public function create(LoggerProviderTypeConfigurationInterface $loggerProviderTypeConfiguration): LoggerInterface
{
$logger = new Logger($loggerName);
$logger = new Logger($loggerProviderTypeConfiguration->getLoggerName());
$handlerCollectionGenerator = $this->handlerResolverFactory
->create($loggerName)
->create($loggerProviderTypeConfiguration)
->resolve();


$handlerCollection = iterator_to_array($handlerCollectionGenerator);

$logger->setHandlers($handlerCollection);
$logger->setHandlers(array_values($handlerCollection));

return $logger;
}
Expand Down
27 changes: 14 additions & 13 deletions src/Business/Handler/HandlerFactory.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
<?php

/*
* This file is part of the Micro framework package.
*
* (c) Stanislau Komar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Micro\Plugin\Logger\Monolog\Business\Handler;

use Micro\Component\DependencyInjection\Container;
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationFactoryInterface;
use Monolog\Handler\HandlerInterface;

class HandlerFactory implements HandlerFactoryInterface
readonly class HandlerFactory implements HandlerFactoryInterface
{
/**
* @param HandlerConfigurationFactoryInterface $handlerConfigurationFactory
*/
public function __construct(
private Container $container,
private HandlerConfigurationFactoryInterface $handlerConfigurationFactory
)
{
private Container $container,
private HandlerConfigurationFactoryInterface $handlerConfigurationFactory
) {
}

/**
* @param string $handlerName
* @return HandlerInterface
*/
public function create(string $handlerName): HandlerInterface
{
$handlerConfiguration = $this->handlerConfigurationFactory->create($handlerName);
$handlerClassName = $handlerConfiguration->getHandlerClassName();
$handlerClassName = $handlerConfiguration->getHandlerClassName();

return new $handlerClassName(
$this->container,
Expand Down
14 changes: 9 additions & 5 deletions src/Business/Handler/HandlerFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?php

/*
* This file is part of the Micro framework package.
*
* (c) Stanislau Komar <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Micro\Plugin\Logger\Monolog\Business\Handler;

use Monolog\Handler\HandlerInterface;

interface HandlerFactoryInterface
{
/**
* @param string $handlerName
*
* @return HandlerInterface
*/
public function create(string $handlerName): HandlerInterface;
}
Loading

0 comments on commit 3a28dd8

Please sign in to comment.