Skip to content

Commit eeb107b

Browse files
committed
Fix deprecations triggered by Symfony 5.3
1 parent 187ccb4 commit eeb107b

File tree

6 files changed

+100
-70
lines changed

6 files changed

+100
-70
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8-
- ...
8+
- Fix deprecations triggered by Symfony 5.3 (#490)
99

1010
## 3.5.4
1111
- CLI commands registration policy changed to lazy load (#373, thanks to @kefzce)

phpstan-baseline.neon

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Sentry\SentryBundle\EventListener;
4+
5+
use Symfony\Component\HttpKernel\Event\KernelEvent;
6+
7+
/**
8+
* Provides forward compatibility with newer Symfony versions.
9+
*
10+
* @internal
11+
*/
12+
trait KernelEventForwardCompatibilityTrait
13+
{
14+
private function isMainRequest(KernelEvent $event): bool
15+
{
16+
return method_exists($event, 'isMainRequest')
17+
? $event->isMainRequest()
18+
: $event->isMasterRequest()
19+
;
20+
}
21+
}

src/EventListener/RequestListener.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class_alias(FilterControllerEvent::class, RequestListenerControllerEvent::class)
3535
*/
3636
final class RequestListener
3737
{
38+
use KernelEventForwardCompatibilityTrait;
39+
3840
/** @var HubInterface */
3941
private $hub;
4042

@@ -61,7 +63,7 @@ public function __construct(
6163
*/
6264
public function onKernelRequest(RequestListenerRequestEvent $event): void
6365
{
64-
if (! $event->isMasterRequest()) {
66+
if (! $this->isMainRequest($event)) {
6567
return;
6668
}
6769

@@ -96,7 +98,7 @@ public function onKernelRequest(RequestListenerRequestEvent $event): void
9698

9799
public function onKernelController(RequestListenerControllerEvent $event): void
98100
{
99-
if (! $event->isMasterRequest()) {
101+
if (! $this->isMainRequest($event)) {
100102
return;
101103
}
102104

@@ -120,7 +122,7 @@ private function getUserData($user): array
120122
{
121123
if ($user instanceof UserInterface) {
122124
return [
123-
'username' => $user->getUsername(),
125+
'username' => method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername(),
124126
];
125127
}
126128

src/EventListener/SubRequestListener.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ class_alias(GetResponseEvent::class, SubRequestListenerRequestEvent::class);
2020

2121
final class SubRequestListener
2222
{
23+
use KernelEventForwardCompatibilityTrait;
24+
2325
/**
2426
* Pushes a new {@see Scope} for each SubRequest
2527
*
2628
* @param SubRequestListenerRequestEvent $event
2729
*/
2830
public function onKernelRequest(SubRequestListenerRequestEvent $event): void
2931
{
30-
if ($event->isMasterRequest()) {
32+
if ($this->isMainRequest($event)) {
3133
return;
3234
}
3335

@@ -41,7 +43,7 @@ public function onKernelRequest(SubRequestListenerRequestEvent $event): void
4143
*/
4244
public function onKernelFinishRequest(FinishRequestEvent $event): void
4345
{
44-
if ($event->isMasterRequest()) {
46+
if ($this->isMainRequest($event)) {
4547
return;
4648
}
4749

test/EventListener/RequestListenerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,12 @@ public function getSalt()
353353
return null;
354354
}
355355

356-
public function getUsername()
356+
public function getUsername(): string
357+
{
358+
return $this->getUserIdentifier();
359+
}
360+
361+
public function getUserIdentifier(): string
357362
{
358363
return $this->username;
359364
}

0 commit comments

Comments
 (0)