Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HypeMC committed Aug 27, 2021
0 parents commit 6595d46
Show file tree
Hide file tree
Showing 63 changed files with 2,894 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.github export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpstan.neon.dist export-ignore
/phpstan-autoload.php export-ignore
/phpunit.xml.dist export-ignore
/phpunit-deprecation-baseline.json export-ignore
114 changes: 114 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:
schedule:
- cron: '0 8 * * *'

jobs:
php-cs-fixer:
runs-on: ubuntu-latest
name: Coding Standards
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: php-cs-fixer, cs2pr

- name: PHP Coding Standards Fixer
run: php-cs-fixer fix --dry-run --format checkstyle | cs2pr

phpstan:
runs-on: ubuntu-latest
name: Static Analysis
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: phpstan

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Install PHPUnit dependencies
run: vendor/bin/simple-phpunit install

- name: PHPStan
run: phpstan analyse --no-progress

phpunit:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: [ '7.2', '7.3', '7.4', '8.0' ]
symfony-versions: [ '4.4', '5.2', '5.3' ]
composer-prefer: [ '', '--prefer-stable --prefer-lowest' ]
env:
SYMFONY_REQUIRE: ${{ matrix.symfony-versions }}.*
SYMFONY_PHPUNIT_VERSION: ${{ matrix.php-versions >= 7.4 && '9.5' || '8.5' }}
name: PHP ${{ matrix.php-versions }} and Symfony ${{ matrix.symfony-versions }} Test
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
ini-values: zend.exception_ignore_args=false
tools: flex

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.composer-prefer }}-
restore-keys: ${{ runner.os }}-composer-${{ matrix.composer-prefer }}-

- name: Install dependencies
run: composer update --prefer-dist ${{ matrix.composer-prefer }}

- name: Install PHPUnit dependencies
run: vendor/bin/simple-phpunit install

- name: Run tests with Doctrine Annotations
run: vendor/bin/simple-phpunit -v --coverage-text --coverage-clover=coverage-annotations.xml

- name: Remove Doctrine Annotations
run: composer remove --dev doctrine/annotations

- name: Run tests without Doctrine Annotations
run: vendor/bin/simple-phpunit -v --coverage-text --coverage-clover=coverage-no-annotations.xml

- name: Upload coverage to Codecov
if: ${{ success() }}
uses: codecov/codecov-action@v1
with:
files: coverage-annotations.xml,coverage-no-annotations.xml
flags: ${{ matrix.php-versions }}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Composer
composer.lock
vendor/

# PHP Coding Standards Fixer
.php-cs-fixer.php
.php-cs-fixer.cache

# PHPStan
phpstan.neon

# PHPUnit
.phpunit.result.cache
phpunit.xml
40 changes: 40 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\Import\OrderedImportsFixer;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->append([__FILE__])
;

return (new PhpCsFixer\Config())
->setUsingCache(true)
->setRules([
'@DoctrineAnnotation' => true,
'@PSR12' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'array_indentation' => true,
'compact_nullable_typehint' => true,
'declare_strict_types' => true,
'heredoc_to_nowdoc' => true,
'list_syntax' => ['syntax' => 'short'],
'no_null_property_initialization' => true,
'no_superfluous_phpdoc_tags' => true,
'nullable_type_declaration_for_default_null_value' => true,
'ordered_imports' => [
'imports_order' => [
OrderedImportsFixer::IMPORT_TYPE_CONST,
OrderedImportsFixer::IMPORT_TYPE_FUNCTION,
OrderedImportsFixer::IMPORT_TYPE_CLASS,
],
],
'pow_to_exponentiation' => true,
'single_line_throw' => false,
'ternary_to_null_coalescing' => true,
])
->setRiskyAllowed(true)
->setFinder($finder)
;
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 HypeMC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
66 changes: 66 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "bizkit/loggable-command-bundle",
"description": "Logs the output into a file by dynamically creating a dedicated Monolog file handler for each Symfony command or message handler.",
"type": "symfony-bundle",
"keywords": [
"log",
"logging",
"loggable",
"monolog",
"console",
"cli"
],
"homepage": "https://github.com/HypeMC/loggable-command-bundle",
"license": "MIT",
"authors": [
{
"name": "HypeMC",
"email": "hypemc@gmail.com"
}
],
"require": {
"php": ">=7.2",
"monolog/monolog": "^1.25.1 || ^2",
"psr/log": "^1 || ^2 || ^3",
"symfony/config": "^4.4 || ^5.2",
"symfony/console": "^4.4 || ^5.2",
"symfony/dependency-injection": "^4.4 || ^5.2",
"symfony/http-kernel": "^4.4 || ^5.2",
"symfony/monolog-bridge": "^4.4 || ^5.2",
"symfony/monolog-bundle": "^3.4",
"symfony/service-contracts": "^1.1 || ^2"
},
"require-dev": {
"doctrine/annotations": "^1.10.4",
"symfony/phpunit-bridge": "^5.2"
},
"conflict": {
"doctrine/annotations": "<1.10.4"
},
"suggest": {
"doctrine/annotations": "For configuring services with the use of an annotation"
},
"autoload": {
"psr-4": {
"Bizkit\\LoggableCommandBundle\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Bizkit\\LoggableCommandBundle\\Tests\\": "tests/"
}
},
"scripts": {
"analyse": "phpstan analyse",
"lint": "php-cs-fixer fix -v",
"test": "simple-phpunit"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-main": "1.x-dev"
}
}
}
73 changes: 73 additions & 0 deletions config/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<defaults public="false" />

<service id="Bizkit\LoggableCommandBundle\Handler\ConsoleHandler">
<argument>null</argument>
<argument /> <!-- bubble -->
<argument /> <!-- verbosity level map -->
<argument /> <!-- console formatter options -->
<call method="pushProcessor">
<argument type="service" id="bizkit_loggable_command.processor.psr_log_message" on-invalid="ignore" />
</call>
<call method="setFormatter">
<argument type="service" id="bizkit_loggable_command.formatter.console" on-invalid="ignore" />
</call>
<tag name="kernel.event_subscriber" />
</service>

<service id="Bizkit\LoggableCommandBundle\ConfigurationProvider\AttributeConfigurationProvider">
<tag name="bizkit_loggable_command.configuration_provider" priority="100" />
</service>

<service id="Bizkit\LoggableCommandBundle\ConfigurationProvider\AnnotationConfigurationProvider">
<argument type="service" id="annotation_reader" />
<tag name="bizkit_loggable_command.configuration_provider" priority="50" />
</service>

<service id="Bizkit\LoggableCommandBundle\ConfigurationProvider\DefaultConfigurationProvider">
<argument /> <!-- handler options -->
<tag name="bizkit_loggable_command.configuration_provider" priority="0" />
</service>

<service id="Bizkit\LoggableCommandBundle\ConfigurationProvider\MergedConfigurationProvider">
<argument type="tagged_iterator" tag="bizkit_loggable_command.configuration_provider" />
</service>

<service id="Bizkit\LoggableCommandBundle\ConfigurationProvider\ConfigurationProviderInterface"
alias="Bizkit\LoggableCommandBundle\ConfigurationProvider\MergedConfigurationProvider" />

<service id="Bizkit\LoggableCommandBundle\DependencyInjection\Configurator\LoggableOutputConfigurator">
<argument type="service" id="Bizkit\LoggableCommandBundle\ConfigurationProvider\ConfigurationProviderInterface" />
<argument type="service" id="Bizkit\LoggableCommandBundle\FilenameProvider\FilenameProviderInterface" />
<argument /> <!-- template logger -->
<argument type="tagged_locator" tag="bizkit_loggable_command.handler_factory" index-by="type" />
</service>

<service id="Bizkit\LoggableCommandBundle\FilenameProvider\DefaultFilenameProvider" />

<service id="Bizkit\LoggableCommandBundle\FilenameProvider\FilenameProviderInterface"
alias="Bizkit\LoggableCommandBundle\FilenameProvider\DefaultFilenameProvider" />

<service id="Bizkit\LoggableCommandBundle\HandlerFactory\AbstractHandlerFactory" abstract="true">
<argument type="service" id="bizkit_loggable_command.processor.psr_log_message" on-invalid="null" />
<argument type="service" id="bizkit_loggable_command.formatter.file" on-invalid="null" />
</service>

<service id="Bizkit\LoggableCommandBundle\HandlerFactory\StreamHandlerFactory" public="false"
parent="Bizkit\LoggableCommandBundle\HandlerFactory\AbstractHandlerFactory">
<tag name="bizkit_loggable_command.handler_factory" type="stream" />
</service>

<service id="Bizkit\LoggableCommandBundle\HandlerFactory\RotatingFileHandlerFactory" public="false"
parent="Bizkit\LoggableCommandBundle\HandlerFactory\AbstractHandlerFactory">
<tag name="bizkit_loggable_command.handler_factory" type="rotating_file" />
</service>
</services>

</container>
42 changes: 42 additions & 0 deletions phpstan-autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

$getEnvVar = static function ($name, $default = false) {
if (false !== $value = getenv($name)) {
return $value;
}

static $phpunitConfig = null;
if (null === $phpunitConfig) {
$phpunitConfigFilename = null;
if (file_exists('phpunit.xml')) {
$phpunitConfigFilename = 'phpunit.xml';
} elseif (file_exists('phpunit.xml.dist')) {
$phpunitConfigFilename = 'phpunit.xml.dist';
}

$phpunitConfig = false;
if ($phpunitConfigFilename) {
$phpunitConfig = new DomDocument();
$phpunitConfig->load($phpunitConfigFilename);
}
}

if (false !== $phpunitConfig) {
$var = new DOMXpath($phpunitConfig);
foreach ($var->query('//php/server[@name="'.$name.'"]') as $var) {
return $var->getAttribute('value');
}
foreach ($var->query('//php/env[@name="'.$name.'"]') as $var) {
return $var->getAttribute('value');
}
}

return $default;
};

$SYMFONY_PHPUNIT_DIR = $getEnvVar('SYMFONY_PHPUNIT_DIR', __DIR__.'/vendor/bin/.phpunit');
$SYMFONY_PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION');

require "$SYMFONY_PHPUNIT_DIR/phpunit-$SYMFONY_PHPUNIT_VERSION-0/vendor/autoload.php";
Loading

0 comments on commit 6595d46

Please sign in to comment.