Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
bernard-ng authored Sep 3, 2024
2 parents 13b1370 + ed0e4a2 commit 1d8eed6
Show file tree
Hide file tree
Showing 23 changed files with 926 additions and 878 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,43 @@ on:
pull_request:

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

- name: Setup PHP
uses: shivammathur/setup-php@v2

with:
php-version: 8.3
coverage: none
tools: php-cs-fixer, cs2pr

- name: Run PHP-CS-Fixer
run: php-cs-fixer fix --dry-run --format checkstyle | cs2pr

test:
runs-on: ubuntu-latest
name: PHPUnit Tests
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
monolog: [ '1.*', '2.*' ]
include:
- php: '7.4'
deps: lowest
deprecations: max[self]=0
- php: '8.1'
monolog: '3.*'
- php: '8.2'
monolog: '3.*'
- php: '8.3'
monolog: '3.*'
- php: '8.4'
deps: highest
monolog: '3.*'
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor
.php-cs-fixer.cache
composer.phar
composer.lock
phpunit.xml
Expand Down
38 changes: 38 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

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

$fileHeaderComment = <<<'EOF'
This file is part of the Symfony package.
(c) Fabien Potencier <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

return (new PhpCsFixer\Config())
->setRules([
'@PHP71Migration' => true,
'@PHPUnit75Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'protected_to_private' => false,
'header_comment' => ['header' => $fileHeaderComment],
'modernize_strpos' => false,
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']],
])
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in([__DIR__])
->append([__FILE__])
)
;
8 changes: 4 additions & 4 deletions DependencyInjection/Compiler/AddProcessorsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ public function process(ContainerBuilder $container)
foreach ($container->findTaggedServiceIds('monolog.processor') as $id => $tags) {
foreach ($tags as $tag) {
if (!empty($tag['channel']) && !empty($tag['handler'])) {
throw new \InvalidArgumentException(sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id));
throw new \InvalidArgumentException(\sprintf('you cannot specify both the "handler" and "channel" attributes for the "monolog.processor" tag on service "%s"', $id));
}

if (!empty($tag['handler'])) {
$definition = $container->findDefinition(sprintf('monolog.handler.%s', $tag['handler']));
$definition = $container->findDefinition(\sprintf('monolog.handler.%s', $tag['handler']));
$parentDef = $definition;
while (!$parentDef->getClass() && $parentDef instanceof ChildDefinition) {
$parentDef = $container->findDefinition($parentDef->getParent());
}
$class = $container->getParameterBag()->resolveValue($parentDef->getClass());
if (!method_exists($class, 'pushProcessor')) {
throw new \InvalidArgumentException(sprintf('The "%s" handler does not accept processors', $tag['handler']));
throw new \InvalidArgumentException(\sprintf('The "%s" handler does not accept processors', $tag['handler']));
}
} elseif (!empty($tag['channel'])) {
if ('app' === $tag['channel']) {
$definition = $container->getDefinition('monolog.logger');
} else {
$definition = $container->getDefinition(sprintf('monolog.logger.%s', $tag['channel']));
$definition = $container->getDefinition(\sprintf('monolog.logger.%s', $tag['channel']));
}
} else {
$definition = $container->getDefinition('monolog.logger_prototype');
Expand Down
5 changes: 1 addition & 4 deletions DependencyInjection/Compiler/AddSwiftMailerTransportPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

/**
Expand All @@ -25,9 +25,6 @@
*/
class AddSwiftMailerTransportPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$handlers = $container->getParameter('monolog.swift_mailer.handlers');
Expand Down
10 changes: 5 additions & 5 deletions DependencyInjection/Compiler/DebugHandlerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Monolog\Logger;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Monolog\Logger;
use Symfony\Component\DependencyInjection\Reference;

/**
* Adds the DebugHandler when the profiler is enabled and kernel.debug is true.
Expand All @@ -31,7 +31,7 @@ class DebugHandlerPass implements CompilerPassInterface

public function __construct(LoggerChannelPass $channelPass)
{
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', E_USER_DEPRECATED);
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.12 and will be removed in 4.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', \E_USER_DEPRECATED);

$this->channelPass = $channelPass;
}
Expand All @@ -51,7 +51,7 @@ public function process(ContainerBuilder $container)

foreach ($this->channelPass->getChannels() as $channel) {
$container
->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel)
->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel)
->addMethodCall('pushHandler', [new Reference('monolog.handler.debug')]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/FixEmptyLoggerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function process(ContainerBuilder $container)
{
$container->register('monolog.handler.null_internal', 'Monolog\Handler\NullHandler');
foreach ($this->channelPass->getChannels() as $channel) {
$def = $container->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel);
$def = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel);
foreach ($def->getMethodCalls() as $method) {
if ('pushHandler' === $method[0]) {
continue 2;
Expand Down
17 changes: 7 additions & 10 deletions DependencyInjection/Compiler/LoggerChannelPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class LoggerChannelPass implements CompilerPassInterface
{
protected $channels = ['app'];

/**
* {@inheritDoc}
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('monolog.logger')) {
Expand All @@ -49,7 +46,7 @@ public function process(ContainerBuilder $container)
$resolvedChannel = $container->getParameterBag()->resolveValue($tag['channel']);

$definition = $container->getDefinition($id);
$loggerId = sprintf('monolog.logger.%s', $resolvedChannel);
$loggerId = \sprintf('monolog.logger.%s', $resolvedChannel);
$this->createLogger($resolvedChannel, $loggerId, $container);

foreach ($definition->getArguments() as $index => $argument) {
Expand Down Expand Up @@ -84,10 +81,10 @@ public function process(ContainerBuilder $container)

// create additional channels
foreach ($container->getParameter('monolog.additional_channels') as $chan) {
if ($chan === 'app') {
if ('app' === $chan) {
continue;
}
$loggerId = sprintf('monolog.logger.%s', $chan);
$loggerId = \sprintf('monolog.logger.%s', $chan);
$this->createLogger($chan, $loggerId, $container);
$container->getDefinition($loggerId)->setPublic(true);
}
Expand All @@ -98,7 +95,7 @@ public function process(ContainerBuilder $container)
foreach ($handlersToChannels as $handler => $channels) {
foreach ($this->processChannels($channels) as $channel) {
try {
$logger = $container->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel);
$logger = $container->getDefinition('app' === $channel ? 'monolog.logger' : 'monolog.logger.'.$channel);
} catch (InvalidArgumentException $e) {
$msg = 'Monolog configuration error: The logging channel "'.$channel.'" assigned to the "'.substr($handler, 16).'" handler does not exist.';
throw new \InvalidArgumentException($msg, 0, $e);
Expand Down Expand Up @@ -133,20 +130,20 @@ protected function processChannels(?array $configuration)
}

/**
* Create new logger from the monolog.logger_prototype
* Create new logger from the monolog.logger_prototype.
*
* @return void
*/
protected function createLogger(string $channel, string $loggerId, ContainerBuilder $container)
{
if (!in_array($channel, $this->channels)) {
if (!\in_array($channel, $this->channels)) {
$logger = new ChildDefinition('monolog.logger_prototype');
$logger->replaceArgument(0, $channel);
$container->setDefinition($loggerId, $logger);
$this->channels[] = $channel;
}

$parameterName = $channel . 'Logger';
$parameterName = $channel.'Logger';

$container->registerAliasForArgument($loggerId, LoggerInterface::class, $parameterName);
}
Expand Down
Loading

0 comments on commit 1d8eed6

Please sign in to comment.