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

remove supported symfony below 5 #288

Open
wants to merge 1 commit 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
8 changes: 5 additions & 3 deletions Command/NotifyDeploymentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
namespace Ekino\NewRelicBundle\Command;

use Ekino\NewRelicBundle\NewRelic\Config;
use RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'newrelic:notify-deployment', description: 'Notifies New Relic that a new deployment has been made')]
class NotifyDeploymentCommand extends Command
{
public const EXIT_NO_APP_NAMES = 1;
Expand All @@ -27,7 +30,7 @@ class NotifyDeploymentCommand extends Command

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

private $newrelic;
private Config $newrelic;

public function __construct(Config $newrelic)
{
Expand Down Expand Up @@ -57,7 +60,6 @@ protected function configure(): void
'Text annotation for the deployment — notes for you', null
),
])
->setDescription('Notifies New Relic that a new deployment has been made')
;
}

Expand Down Expand Up @@ -120,7 +122,7 @@ public function performRequest(string $api_key, string $payload, ?string $api_ho
error_reporting($level);
if (false === $content) {
$error = error_get_last();
throw new \RuntimeException($error['message']);
throw new RuntimeException($error['message']);
}

$response = [
Expand Down
10 changes: 7 additions & 3 deletions Listener/CommandListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@

class CommandListener implements EventSubscriberInterface
{
private $interactor;
private $config;
private $ignoredCommands;
private NewRelicInteractorInterface $interactor;
private Config $config;
/** @var string[] */
private array $ignoredCommands;

/**
* @param string[] $ignoredCommands
*/
public function __construct(Config $config, NewRelicInteractorInterface $interactor, array $ignoredCommands)
{
$this->config = $config;
Expand Down
4 changes: 2 additions & 2 deletions Listener/DeprecationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

class DeprecationListener
{
private $isRegistered = false;
private $interactor;
private bool $isRegistered = false;
private NewRelicInteractorInterface $interactor;

public function __construct(NewRelicInteractorInterface $interactor)
{
Expand Down
17 changes: 4 additions & 13 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 All @@ -25,7 +24,7 @@
*/
class ExceptionListener implements EventSubscriberInterface
{
private $interactor;
private NewRelicInteractorInterface $interactor;

public function __construct(NewRelicInteractorInterface $interactor)
{
Expand All @@ -40,21 +39,13 @@ public static function getSubscribedEvents(): array
}

/**
* @param GetResponseForExceptionEvent|ExceptionEvent $event
* @param ExceptionEvent $event
*/
public function onKernelException(KernelExceptionEvent $event): void
public function onKernelException(ExceptionEvent $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);
}
}
37 changes: 17 additions & 20 deletions Listener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@
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;

class RequestListener implements EventSubscriberInterface
{
private $ignoredRoutes;
private $ignoredPaths;
private $config;
private $interactor;
private $transactionNamingStrategy;
private $symfonyCache;
/** @var string[] */
private array $ignoredRoutes;
/** @var string[] */
private array $ignoredPaths;
private Config $config;
private NewRelicInteractorInterface $interactor;
private TransactionNamingStrategyInterface $transactionNamingStrategy;
private bool $symfonyCache;

/**
* @param string[] $ignoreRoutes
* @param string[] $ignoredPaths
*/
public function __construct(
Config $config,
NewRelicInteractorInterface $interactor,
Expand Down Expand Up @@ -58,7 +63,7 @@ public static function getSubscribedEvents(): array
];
}

public function setApplicationName(KernelRequestEvent $event): void
public function setApplicationName(RequestEvent $event): void
{
if (!$this->isEventValid($event)) {
return;
Expand All @@ -80,7 +85,7 @@ public function setApplicationName(KernelRequestEvent $event): void
}
}

public function setTransactionName(KernelRequestEvent $event): void
public function setTransactionName(RequestEvent $event): void
{
if (!$this->isEventValid($event)) {
return;
Expand All @@ -91,7 +96,7 @@ public function setTransactionName(KernelRequestEvent $event): void
$this->interactor->setTransactionName($transactionName);
}

public function setIgnoreTransaction(KernelRequestEvent $event): void
public function setIgnoreTransaction(RequestEvent $event): void
{
if (!$this->isEventValid($event)) {
return;
Expand All @@ -110,16 +115,8 @@ public function setIgnoreTransaction(KernelRequestEvent $event): void
/**
* Make sure we should consider this event. Example: make sure it is a master request.
*/
private function isEventValid(KernelRequestEvent $event): bool
private function isEventValid(RequestEvent $event): bool
{
return HttpKernelInterface::MASTER_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);
return HttpKernelInterface::MAIN_REQUEST === $event->getRequestType();
}
}
25 changes: 8 additions & 17 deletions Listener/ResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@
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;
private Config $newRelic;
private NewRelicInteractorInterface $interactor;
private bool $instrument;
private bool $symfonyCache;
private ?NewRelicExtension $newRelicTwigExtension;

public function __construct(
Config $newRelic,
Expand All @@ -53,9 +52,9 @@ public static function getSubscribedEvents(): array
];
}

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

if (!$isMainRequest) {
return;
Expand Down Expand Up @@ -88,7 +87,7 @@ public function onKernelResponse(KernelResponseEvent $event): void

// We can only instrument HTML responses
if (!$response instanceof StreamedResponse
&& 'text/html' === substr($response->headers->get('Content-Type', ''), 0, 9)
&& str_starts_with($response->headers->get('Content-Type', ''), 'text/html')
) {
$responseContent = $response->getContent();
$response->setContent(''); // free the memory
Expand All @@ -111,11 +110,3 @@ 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);
}
}
4 changes: 4 additions & 0 deletions Logging/AdaptiveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Ekino\NewRelicBundle\Logging;

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

Expand All @@ -28,6 +29,9 @@ public function __construct(
parent::__construct($level, $bubble, $appName, $explodeArrays, $transactionName);
}

/**
* @throws MissingExtensionException
*/
protected function write(array $record): void
{
if (!$this->isNewRelicEnabled()) {
Expand Down
2 changes: 1 addition & 1 deletion NewRelic/AdaptiveInteractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class AdaptiveInteractor implements NewRelicInteractorInterface
{
private $interactor;
private NewRelicInteractorInterface $interactor;

public function __construct(NewRelicInteractorInterface $real, NewRelicInteractorInterface $fake)
{
Expand Down
18 changes: 9 additions & 9 deletions NewRelic/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
class Config
{
private $name;
private $apiKey;
private $apiHost = null;
private $licenseKey;
private $xmit;
private $customEvents;
private $customMetrics;
private $customParameters;
private $deploymentNames;
private string|false $name;
private ?string $apiKey;
private ?string $apiHost;
private string|false $licenseKey;
private bool $xmit;
private array $customEvents;
private array $customMetrics;
private array $customParameters;
private array $deploymentNames;

public function __construct(?string $name, string $apiKey = null, string $licenseKey = null, bool $xmit = false, array $deploymentNames = [], ?string $apiHost = null)
{
Expand Down
4 changes: 2 additions & 2 deletions NewRelic/LoggingInteractorDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

class LoggingInteractorDecorator implements NewRelicInteractorInterface
{
private $interactor;
private $logger;
private NewRelicInteractorInterface $interactor;
private LoggerInterface|NullLogger $logger;

public function __construct(NewRelicInteractorInterface $interactor, LoggerInterface $logger = null)
{
Expand Down
6 changes: 3 additions & 3 deletions NewRelic/NewRelicInteractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function ignoreTransaction(): void

public function addCustomEvent(string $name, array $attributes): void
{
newrelic_record_custom_event((string) $name, $attributes);
newrelic_record_custom_event($name, $attributes);
}

public function addCustomMetric(string $name, float $value): bool
Expand All @@ -42,7 +42,7 @@ public function addCustomMetric(string $name, float $value): bool

public function addCustomParameter(string $name, $value): bool
{
return newrelic_add_custom_parameter((string) $name, $value);
return newrelic_add_custom_parameter($name, $value);
}

public function getBrowserTimingHeader(bool $includeTags = true): string
Expand Down Expand Up @@ -72,7 +72,7 @@ public function noticeThrowable(\Throwable $e, string $message = null): void

public function enableBackgroundJob(): void
{
newrelic_background_job(true);
newrelic_background_job();
}

public function disableBackgroundJob(): void
Expand Down
8 changes: 4 additions & 4 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testDefaults()
$this->assertIsArray($config['deployment_names']);
}

public static function ignoredRoutesProvider()
public static function ignoredRoutesProvider(): array
{
return [
['single_ignored_route', ['single_ignored_route']],
Expand All @@ -102,7 +102,7 @@ public static function ignoredRoutesProvider()
];
}

public static function ignoredPathsProvider()
public static function ignoredPathsProvider(): array
{
return [
['/single/ignored/path', ['/single/ignored/path']],
Expand All @@ -111,7 +111,7 @@ public static function ignoredPathsProvider()
];
}

public static function ignoredCommandsProvider()
public static function ignoredCommandsProvider(): array
{
return [
['single:ignored:command', ['single:ignored:command']],
Expand All @@ -120,7 +120,7 @@ public static function ignoredCommandsProvider()
];
}

public static function deploymentNamesProvider()
public static function deploymentNamesProvider(): array
{
return [
['App1', ['App1']],
Expand Down
2 changes: 1 addition & 1 deletion Tests/Listener/DeprecationListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testOtherErrorAreIgnored()
set_error_handler(function () { return false; });
try {
$listener->register();
@trigger_error('This is a notice', \E_USER_NOTICE);
@trigger_error('This is a notice');
} finally {
$listener->unregister();
restore_error_handler();
Expand Down
Loading