Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions DependencyInjection/CompilerPass/HttpClientPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace ETSGlobal\LogBundle\DependencyInjection\CompilerPass;

use ETSGlobal\LogBundle\Tracing\Plugins\Symfony\HttpClientDecorator;
use ETSGlobal\LogBundle\Tracing\TokenCollection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
Expand All @@ -19,22 +20,22 @@
*/
class HttpClientPass implements CompilerPassInterface
{
private const TOKEN_COLLECTION_SERVICE_ID = 'ets_global_log.tracing.token_collection';
private const DECORATOR_PRIORITY = 5;

public function process(ContainerBuilder $container): void
{
if (!$container->hasDefinition('ets_global_log.tracing.token_collection')) {
if (!$container->hasDefinition(TokenCollection::class)) {
throw new \RuntimeException('The token collection service definition is missing.');
}

$taggedServices = $container->findTaggedServiceIds('http_client.client');
foreach ($taggedServices as $id => $attributes) {
foreach (array_keys($taggedServices) as $id) {
$httpClientDefinition = $container->getDefinition($id);

$decorator = new Definition(HttpClientDecorator::class);
$decorator->setDecoratedService($id);
$decorator->setDecoratedService($id, null, self::DECORATOR_PRIORITY);
$decorator->setArgument('$httpClient', $httpClientDefinition);
$decorator->setArgument('$tokenCollection', new Reference(self::TOKEN_COLLECTION_SERVICE_ID));
$decorator->setArgument('$tokenCollection', new Reference(TokenCollection::class));

$container->setDefinition(HttpClientDecorator::class, $decorator);
}
Expand Down
54 changes: 0 additions & 54 deletions DependencyInjection/CompilerPass/LoggerAwarePass.php

This file was deleted.

22 changes: 12 additions & 10 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;

/**
* @internal
*/
/** @internal */
final class Configuration implements ConfigurationInterface
{
private const DEFAULT_APP_NAME = 'default';
Expand All @@ -33,12 +31,7 @@ public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('ets_global_log');

// Keep compatibility with symfony/config < 4.2
if (\method_exists($treeBuilder, 'getRootNode')) {
$rootNode = $treeBuilder->getRootNode();
} else {
$rootNode = $treeBuilder->root('ets_global_log');
}
$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
Expand All @@ -47,7 +40,16 @@ public function getConfigTreeBuilder(): TreeBuilder
->arrayNode('http_exceptions_levels')
->defaultValue(self::DEFAULT_HTTP_EXCEPTIONS_LEVELS)
->useAttributeAsKey('name')
->prototype('scalar')->end()
->prototype('enum')->values([
Logger::DEBUG,
Logger::INFO,
Logger::NOTICE,
Logger::WARNING,
Logger::ERROR,
Logger::CRITICAL,
Logger::ALERT,
Logger::EMERGENCY,
])->end()
->end()
->arrayNode('custom_exceptions_levels')
->defaultValue([])
Expand Down
9 changes: 2 additions & 7 deletions DependencyInjection/ETSGlobalLogExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* @internal
*/
/** @internal */
final class ETSGlobalLogExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
Expand All @@ -33,7 +28,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->setParameter('ets_global_log.handlers.slack.jira_url', $config['slack_handler']['jira_url']);
$container->setParameter('ets_global_log.handlers.slack.kibana_url', $config['slack_handler']['kibana_url']);

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');
}
}
2 changes: 0 additions & 2 deletions ETSGlobalLogBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
namespace ETSGlobal\LogBundle;

use ETSGlobal\LogBundle\DependencyInjection\CompilerPass\HttpClientPass;
use ETSGlobal\LogBundle\DependencyInjection\CompilerPass\LoggerAwarePass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class ETSGlobalLogBundle extends Bundle
{
public function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new LoggerAwarePass());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 not needed since Symfony 4.2 symfony/symfony@afda3c8

$container->addCompilerPass(new HttpClientPass());
}
}
73 changes: 26 additions & 47 deletions EventSubscriber/TracingEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,67 +10,27 @@
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* @internal
*/
/** @internal */
final class TracingEventSubscriber implements EventSubscriberInterface
{
private const HIGHEST_PRIORITY = 512;
private const LOWEST_PRIORITY = -512;

/** @var TokenCollection */
private $tokenCollection;

/** @var HttpFoundation */
private $httpFoundation;

public function __construct(TokenCollection $tokenCollection, HttpFoundation $httpFoundation)
public function __construct(private TokenCollection $tokenCollection, private HttpFoundation $httpFoundation)
{
$this->tokenCollection = $tokenCollection;
$this->httpFoundation = $httpFoundation;
}

public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => [
['onKernelRequest', self::HIGHEST_PRIORITY],
],
KernelEvents::RESPONSE => [
['onKernelResponse', self::LOWEST_PRIORITY],
],
KernelEvents::TERMINATE => [
['onKernelTerminate', self::LOWEST_PRIORITY],
],
ConsoleEvents::COMMAND => [
['onConsoleCommand', self::HIGHEST_PRIORITY],
],
ConsoleEvents::TERMINATE => [
['onConsoleTerminate', self::LOWEST_PRIORITY],
],
];
}

/**
* @param GetResponseEvent|RequestEvent $event
*/
public function onKernelRequest($event): void
public function onKernelRequest(RequestEvent $event): void
{
$this->httpFoundation->setFromRequest($event->getRequest());
}

/**
* @param FilterResponseEvent|ResponseEvent $event
*/
public function onKernelResponse($event): void
public function onKernelResponse(ResponseEvent $event): void
{
$this->httpFoundation->setToResponse($event->getResponse());
}
Expand Down Expand Up @@ -98,12 +58,31 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event): void
/**
* Clears the global token.
*
* @param PostResponseEvent|TerminateEvent $event
*
* phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
*/
public function onKernelTerminate($event): void
public function onKernelTerminate(TerminateEvent $event): void
{
$this->tokenCollection->remove('global');
}

public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => [
['onKernelRequest', self::HIGHEST_PRIORITY],
],
KernelEvents::RESPONSE => [
['onKernelResponse', self::LOWEST_PRIORITY],
],
KernelEvents::TERMINATE => [
['onKernelTerminate', self::LOWEST_PRIORITY],
],
ConsoleEvents::COMMAND => [
['onConsoleCommand', self::HIGHEST_PRIORITY],
],
ConsoleEvents::TERMINATE => [
['onConsoleTerminate', self::LOWEST_PRIORITY],
],
];
}
}
Loading