Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Symfony 7 #289

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 11 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,48 @@ jobs:
name: PHP-CS-Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga

build:
name: Build
runs-on: Ubuntu-20.04
runs-on: Ubuntu-22.04
strategy:
fail-fast: false
matrix:
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
php: ['8.1', '8.2', '8.3']
composer: ['']
phpunit: ['']
deprecation: ['']
symfony: ['']
stability: ['']
include:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 8.0
composer: --prefer-stable --prefer-lowest
deprecation: max[direct]=0
- php: 7.1
- php: 8.1
composer: --prefer-stable --prefer-lowest
deprecation: max[direct]=0

# symfony version
- php: 8.0
symfony: '^3.0'
- php: 8.0
symfony: '^4.0'
- php: 8.0
symfony: '^5.0'
- php: 8.3
symfony: '^6.4'
- php: 8.3
symfony: '^7.0'

# dev
- php: 8.0
- php: 8.3
stability: 'dev'

steps:
- name: Set up PHP
uses: shivammathur/setup-php@2.7.0
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: flex

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup stability
if: matrix.stability != ''
Expand Down
4 changes: 1 addition & 3 deletions Command/NotifyDeploymentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ class NotifyDeploymentCommand extends Command
public const EXIT_UNAUTHORIZED = 2;
public const EXIT_HTTP_ERROR = 3;

protected static $defaultName = 'newrelic:notify-deployment';

private $newrelic;

public function __construct(Config $newrelic)
{
$this->newrelic = $newrelic;

parent::__construct();
parent::__construct('newrelic:notify-deployment');
}

protected function configure(): void
Expand Down
6 changes: 3 additions & 3 deletions EkinoNewRelicBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

class EkinoNewRelicBundle extends Bundle
{
public function build(ContainerBuilder $container)
public function build(ContainerBuilder $container): void
{
parent::build($container);

$container->addCompilerPass(new MonologHandlerPass());
}

public function boot()
public function boot(): void
{
parent::boot();

Expand All @@ -36,7 +36,7 @@ public function boot()
}
}

public function shutdown()
public function shutdown(): void
{
if ($this->container->has(DeprecationListener::class)) {
$this->container->get(DeprecationListener::class)->unregister();
Expand Down
9 changes: 2 additions & 7 deletions Listener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\KernelEvents;

Expand Down Expand Up @@ -44,17 +43,13 @@ public static function getSubscribedEvents(): array
*/
public function onKernelException(KernelExceptionEvent $event): void
{
$exception = method_exists($event, 'getThrowable') ? $event->getThrowable() : $event->getException();
$exception = $event->getThrowable();
if (!$exception instanceof HttpExceptionInterface) {
$this->interactor->noticeThrowable($exception);
}
}
}

if (!class_exists(KernelExceptionEvent::class)) {
if (class_exists(ExceptionEvent::class)) {
class_alias(ExceptionEvent::class, KernelExceptionEvent::class);
} else {
class_alias(GetResponseForExceptionEvent::class, KernelExceptionEvent::class);
}
class_alias(ExceptionEvent::class, KernelExceptionEvent::class);
}
9 changes: 2 additions & 7 deletions Listener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface;
use Ekino\NewRelicBundle\TransactionNamingStrategy\TransactionNamingStrategyInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
Expand Down Expand Up @@ -112,14 +111,10 @@ public function setIgnoreTransaction(KernelRequestEvent $event): void
*/
private function isEventValid(KernelRequestEvent $event): bool
{
return HttpKernelInterface::MASTER_REQUEST === $event->getRequestType();
return HttpKernelInterface::MAIN_REQUEST === $event->getRequestType();
}
}

if (!class_exists(KernelRequestEvent::class)) {
if (class_exists(RequestEvent::class)) {
class_alias(RequestEvent::class, KernelRequestEvent::class);
} else {
class_alias(GetResponseEvent::class, KernelRequestEvent::class);
}
class_alias(RequestEvent::class, KernelRequestEvent::class);
}
30 changes: 7 additions & 23 deletions Listener/ResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,18 @@
use Ekino\NewRelicBundle\Twig\NewRelicExtension;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class ResponseListener implements EventSubscriberInterface
{
private $newRelic;
private $interactor;
private $instrument;
private $symfonyCache;
private $newRelicTwigExtension;

public function __construct(
Config $newRelic,
NewRelicInteractorInterface $interactor,
bool $instrument = false,
bool $symfonyCache = false,
NewRelicExtension $newRelicTwigExtension = null
private Config $newRelic,
private NewRelicInteractorInterface $interactor,
private bool $instrument = false,
private bool $symfonyCache = false,
private ?NewRelicExtension $newRelicTwigExtension = null,
) {
$this->newRelic = $newRelic;
$this->interactor = $interactor;
$this->instrument = $instrument;
$this->symfonyCache = $symfonyCache;
$this->newRelicTwigExtension = $newRelicTwigExtension;
}

public static function getSubscribedEvents(): array
Expand All @@ -55,7 +43,7 @@ public static function getSubscribedEvents(): array

public function onKernelResponse(KernelResponseEvent $event): void
{
$isMainRequest = method_exists($event, 'isMainRequest') ? $event->isMainRequest() : $event->isMasterRequest();
$isMainRequest = $event->isMainRequest();

if (!$isMainRequest) {
return;
Expand Down Expand Up @@ -113,9 +101,5 @@ public function onKernelResponse(KernelResponseEvent $event): void
}

if (!class_exists(KernelResponseEvent::class)) {
if (class_exists(ResponseEvent::class)) {
class_alias(ResponseEvent::class, KernelResponseEvent::class);
} else {
class_alias(FilterResponseEvent::class, KernelResponseEvent::class);
}
class_alias(ResponseEvent::class, KernelResponseEvent::class);
}
3 changes: 2 additions & 1 deletion Logging/AdaptiveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Ekino\NewRelicBundle\Logging;

use Monolog\Handler\NewRelicHandler;
use Monolog\LogRecord;
use Psr\Log\LogLevel;

class AdaptiveHandler extends NewRelicHandler
Expand All @@ -28,7 +29,7 @@ public function __construct(
parent::__construct($level, $bubble, $appName, $explodeArrays, $transactionName);
}

protected function write(array $record): void
protected function write(LogRecord $record): void
{
if (!$this->isNewRelicEnabled()) {
return;
Expand Down
30 changes: 14 additions & 16 deletions Tests/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function registerBundles(): iterable
* (From MicroKernelTrait)
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(function (ContainerBuilder $container) {
$container->loadFromExtension('framework', [
Expand All @@ -100,21 +100,19 @@ public function registerContainerConfiguration(LoaderInterface $loader)
],
]);

// Not setting the router to utf8 is deprecated in symfony 5.1
if (Kernel::VERSION_ID >= 50100) {
// Fix deprecations in symfony 6
if (Kernel::VERSION_ID >= 60100) {
$container->loadFromExtension('framework', [
'router' => ['utf8' => true],
]);
}

// Not setting the "framework.session.storage_factory_id" configuration option is deprecated in symfony 5.3
if (Kernel::VERSION_ID >= 50300) {
$container->loadFromExtension('framework', [
'session' => ['storage_factory_id' => 'session.storage.factory.mock_file'],
]);
} else {
$container->loadFromExtension('framework', [
'session' => ['storage_id' => 'session.storage.mock_file'],
'http_method_override' => false,
'handle_all_throwables' => true,
'session' => [
'cookie_secure' => 'auto',
'cookie_samesite' => 'lax',
'handler_id' => null,
],
'php_errors' => [
'log' => true,
],
]);
}

Expand All @@ -140,7 +138,7 @@ protected function buildContainer(): ContainerBuilder
$container = parent::buildContainer();

$container->addCompilerPass(new class() implements CompilerPassInterface {
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
foreach ($container->getDefinitions() as $id => $definition) {
if (preg_match('|Ekino.*|i', $id)) {
Expand Down
4 changes: 2 additions & 2 deletions Tests/BundleInitializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
*/
class BundleInitializationTest extends TestCase
{
protected function getBundleClass()
protected function getBundleClass(): string
{
return EkinoNewRelicBundle::class;
}

public function testInitBundle()
public function testInitBundle(): void
{
$kernel = new AppKernel(uniqid('cache'));
$kernel->boot();
Expand Down
8 changes: 4 additions & 4 deletions Tests/Listener/CommandListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class CommandListenerTest extends TestCase
{
public function testCommandMarkedAsBackgroundJob()
public function testCommandMarkedAsBackgroundJob(): void
{
if (!class_exists('Symfony\Component\Console\Event\ConsoleCommandEvent')) {
$this->markTestSkipped('Console Events is only available from Symfony 2.3');
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testCommandMarkedAsBackgroundJob()
$listener->onConsoleCommand($event);
}

public function testIgnoreBackgroundJob()
public function testIgnoreBackgroundJob(): void
{
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
$interactor->expects($this->never())->method('startTransaction');
Expand All @@ -84,7 +84,7 @@ public function testIgnoreBackgroundJob()
$listener->onConsoleCommand($event);
}

public function testConsoleError()
public function testConsoleError(): void
{
$exception = new \Exception('', 1);

Expand All @@ -103,7 +103,7 @@ public function testConsoleError()
$listener->onConsoleError($event);
}

public function testConsoleErrorsWithThrowable()
public function testConsoleErrorsWithThrowable(): void
{
$exception = new \Error();

Expand Down
12 changes: 6 additions & 6 deletions Tests/Listener/DeprecationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class DeprecationListenerTest extends TestCase
{
public function testDeprecationIsReported()
public function testDeprecationIsReported(): void
{
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
$interactor->expects($this->once())->method('noticeThrowable')->with(
Expand All @@ -39,7 +39,7 @@ public function testDeprecationIsReported()
}
}

public function testDeprecationIsReportedRegardlessErrorReporting()
public function testDeprecationIsReportedRegardlessErrorReporting(): void
{
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
$interactor->expects($this->once())->method('noticeThrowable');
Expand All @@ -58,7 +58,7 @@ public function testDeprecationIsReportedRegardlessErrorReporting()
}
}

public function testOtherErrorAreIgnored()
public function testOtherErrorAreIgnored(): void
{
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
$interactor->expects($this->never())->method('noticeThrowable');
Expand All @@ -75,7 +75,7 @@ public function testOtherErrorAreIgnored()
}
}

public function testInitialHandlerIsCalled()
public function testInitialHandlerIsCalled(): void
{
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
$interactor->expects($this->once())->method('noticeThrowable');
Expand All @@ -95,7 +95,7 @@ public function testInitialHandlerIsCalled()
}
}

public function testUnregisterRemovesHandler()
public function testUnregisterRemovesHandler(): void
{
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();
$interactor->expects($this->never())->method('noticeThrowable');
Expand All @@ -112,7 +112,7 @@ public function testUnregisterRemovesHandler()
}
}

public function testUnregisterRestorePreviousHandler()
public function testUnregisterRestorePreviousHandler(): void
{
$interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock();

Expand Down
Loading