Skip to content

Commit e746361

Browse files
committed
📦 Avoid deprecation by using checking method availability
> Since symfony/http-kernel 5.3 "isMasterRequest()" is deprecated, use "isMainRequest()" instead.
1 parent d6a3536 commit e746361

File tree

7 files changed

+129
-10
lines changed

7 files changed

+129
-10
lines changed

src/Bridge/AppStartSpanListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Jaeger\Tag\SpanKindServerTag;
99
use Jaeger\Tracer\TracerInterface;
1010
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1112
use Symfony\Component\HttpKernel\Event\RequestEvent;
1213

1314
class AppStartSpanListener implements EventSubscriberInterface
@@ -27,7 +28,7 @@ public static function getSubscribedEvents(): array
2728
public function onRequest(RequestEvent $event)
2829
{
2930
$request = $event->getRequest();
30-
if (false === $event->isMasterRequest()) {
31+
if (false === $this->isMainRequestEvent($event)) {
3132
return $this;
3233
}
3334
$this->tracer
@@ -40,4 +41,20 @@ public function onRequest(RequestEvent $event)
4041

4142
return $this;
4243
}
44+
45+
/**
46+
* Use non-deprecated check method if availble
47+
*
48+
* @param KernelEvent $event
49+
*
50+
* @return bool
51+
*/
52+
private function isMainRequestEvent(KernelEvent $event): bool
53+
{
54+
if (\method_exists($event, 'isMainRequest')) {
55+
return $event->isMainRequest();
56+
}
57+
58+
return $event->isMasterRequest();
59+
}
4360
}

src/Bridge/ContextListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Jaeger\Tracer\InjectableInterface;
88
use Symfony\Component\Console\Event\ConsoleCommandEvent;
99
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1011
use Symfony\Component\HttpKernel\Event\RequestEvent;
1112

1213
class ContextListener implements EventSubscriberInterface
@@ -46,9 +47,25 @@ public function inject(): void
4647

4748
public function onRequest(RequestEvent $event): void
4849
{
49-
if (false === $event->isMasterRequest()) {
50+
if (false === $this->isMainRequestEvent($event)) {
5051
return;
5152
}
5253
$this->inject();
5354
}
55+
56+
/**
57+
* Use non-deprecated check method if availble
58+
*
59+
* @param KernelEvent $event
60+
*
61+
* @return bool
62+
*/
63+
private function isMainRequestEvent(KernelEvent $event): bool
64+
{
65+
if (\method_exists($event, 'isMainRequest')) {
66+
return $event->isMainRequest();
67+
}
68+
69+
return $event->isMasterRequest();
70+
}
5471
}

src/Bridge/DebugListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Event\ConsoleCommandEvent;
99
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
1010
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1112
use Symfony\Component\HttpKernel\Event\RequestEvent;
1213
use Symfony\Component\HttpKernel\Event\TerminateEvent;
1314

@@ -48,12 +49,28 @@ public function onCommand(): void
4849

4950
public function onRequest(RequestEvent $event)
5051
{
51-
if (false === $event->isMasterRequest()) {
52+
if (false === $this->isMainRequestEvent($event)) {
5253
return;
5354
}
5455
if ('' === ($debugId = $this->extractor->getDebug())) {
5556
return;
5657
}
5758
$this->debuggable->enable($debugId);
5859
}
60+
61+
/**
62+
* Use non-deprecated check method if availble
63+
*
64+
* @param KernelEvent $event
65+
*
66+
* @return bool
67+
*/
68+
private function isMainRequestEvent(KernelEvent $event): bool
69+
{
70+
if (\method_exists($event, 'isMainRequest')) {
71+
return $event->isMainRequest();
72+
}
73+
74+
return $event->isMasterRequest();
75+
}
5976
}

src/Bridge/GlobalSpanListener.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Jaeger\Symfony\Bridge;
55

66
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7+
use Symfony\Component\HttpKernel\Event\KernelEvent;
78
use Symfony\Component\HttpKernel\Event\RequestEvent;
89
use Symfony\Component\HttpKernel\Event\TerminateEvent;
910

@@ -33,11 +34,27 @@ public function onTerminate()
3334

3435
public function onRequest(RequestEvent $event)
3536
{
36-
if (false === $event->isMasterRequest()) {
37+
if (false === $this->isMainRequestEvent($event)) {
3738
return $this;
3839
}
3940
$this->handler->start($event->getRequest());
4041

4142
return $this;
4243
}
44+
45+
/**
46+
* Use non-deprecated check method if availble
47+
*
48+
* @param KernelEvent $event
49+
*
50+
* @return bool
51+
*/
52+
private function isMainRequestEvent(KernelEvent $event): bool
53+
{
54+
if (\method_exists($event, 'isMainRequest')) {
55+
return $event->isMainRequest();
56+
}
57+
58+
return $event->isMasterRequest();
59+
}
4360
}

src/Bridge/RequestSpanListener.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Jaeger\Tracer\TracerInterface;
1616
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1717
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
18+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1819
use Symfony\Component\HttpKernel\Event\RequestEvent;
1920
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2021

@@ -44,7 +45,7 @@ public static function getSubscribedEvents(): array
4445

4546
public function onResponse(ResponseEvent $event): void
4647
{
47-
if ($event->isMasterRequest()) {
48+
if (false === $this->isMainRequestEvent($event)) {
4849
return;
4950
}
5051
if ($this->spans->isEmpty()) {
@@ -55,7 +56,7 @@ public function onResponse(ResponseEvent $event): void
5556

5657
public function onRequest(RequestEvent $event): void
5758
{
58-
if ($event->isMasterRequest()) {
59+
if (false === $this->isMainRequestEvent($event)) {
5960
return;
6061
}
6162
$request = $event->getRequest();
@@ -86,4 +87,20 @@ public function onKernelException(ExceptionEvent $event): void
8687
->addLog(new ErrorLog($exception->getMessage(), $exception->getTraceAsString()))
8788
;
8889
}
90+
91+
/**
92+
* Use non-deprecated check method if availble
93+
*
94+
* @param KernelEvent $event
95+
*
96+
* @return bool
97+
*/
98+
private function isMainRequestEvent(KernelEvent $event): bool
99+
{
100+
if (\method_exists($event, 'isMainRequest')) {
101+
return $event->isMainRequest();
102+
}
103+
104+
return $event->isMasterRequest();
105+
}
89106
}

src/Context/Extractor/HeaderContextExtractor.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Jaeger\Codec\CodecRegistry;
88
use Jaeger\Span\Context\SpanContext;
99
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10+
use Symfony\Component\HttpKernel\Event\KernelEvent;
1011
use Symfony\Component\HttpKernel\Event\RequestEvent;
1112
use Symfony\Component\HttpKernel\Event\TerminateEvent;
1213

@@ -45,15 +46,15 @@ public function extract(): ?SpanContext
4546

4647
public function onTerminate(TerminateEvent $event): void
4748
{
48-
if (false === $event->isMasterRequest()) {
49+
if (false === $this->isMainRequestEvent($event)) {
4950
return;
5051
}
5152
$this->context = null;
5253
}
5354

5455
public function onRequest(RequestEvent $event): void
5556
{
56-
if (false === $event->isMasterRequest()) {
57+
if (false === $this->isMainRequestEvent($event)) {
5758
return;
5859
}
5960
$request = $event->getRequest();
@@ -62,4 +63,20 @@ public function onRequest(RequestEvent $event): void
6263
$this->context = $context;
6364
}
6465
}
66+
67+
/**
68+
* Use non-deprecated check method if availble
69+
*
70+
* @param KernelEvent $event
71+
*
72+
* @return bool
73+
*/
74+
private function isMainRequestEvent(KernelEvent $event): bool
75+
{
76+
if (\method_exists($event, 'isMainRequest')) {
77+
return $event->isMainRequest();
78+
}
79+
80+
return $event->isMasterRequest();
81+
}
6582
}

src/Debug/Extractor/CookieDebugExtractor.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Jaeger\Symfony\Debug\Extractor;
55

66
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7+
use Symfony\Component\HttpKernel\Event\KernelEvent;
78
use Symfony\Component\HttpKernel\Event\RequestEvent;
89
use Symfony\Component\HttpKernel\Event\TerminateEvent;
910

@@ -20,7 +21,7 @@ public function __construct(string $cookieName)
2021

2122
public function onRequest(RequestEvent $event): void
2223
{
23-
if (false === $event->isMasterRequest()) {
24+
if (false === $this->isMainRequestEvent($event)) {
2425
return;
2526
}
2627
$request = $event->getRequest();
@@ -32,7 +33,7 @@ public function onRequest(RequestEvent $event): void
3233

3334
public function onTerminate(TerminateEvent $event): void
3435
{
35-
if (false === $event->isMasterRequest()) {
36+
if (false === $this->isMainRequestEvent($event)) {
3637
return;
3738
}
3839
$this->debugId = '';
@@ -50,4 +51,20 @@ public static function getSubscribedEvents(): array
5051
TerminateEvent::class => ['onTerminate'],
5152
];
5253
}
54+
55+
/**
56+
* Use non-deprecated check method if availble
57+
*
58+
* @param KernelEvent $event
59+
*
60+
* @return bool
61+
*/
62+
private function isMainRequestEvent(KernelEvent $event): bool
63+
{
64+
if (\method_exists($event, 'isMainRequest')) {
65+
return $event->isMainRequest();
66+
}
67+
68+
return $event->isMasterRequest();
69+
}
5370
}

0 commit comments

Comments
 (0)