Skip to content

Fix deprecations triggered by Symfony 5.3 #490

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

Merged
merged 1 commit into from
Apr 26, 2021
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
- ...
- Fix deprecations triggered by Symfony 5.3 (#490)

## 3.5.4
- CLI commands registration policy changed to lazy load (#373, thanks to @kefzce)
Expand Down
126 changes: 63 additions & 63 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/EventListener/KernelEventForwardCompatibilityTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Sentry\SentryBundle\EventListener;

use Symfony\Component\HttpKernel\Event\KernelEvent;

/**
* Provides forward compatibility with newer Symfony versions.
*
* @internal
*/
trait KernelEventForwardCompatibilityTrait
{
private function isMainRequest(KernelEvent $event): bool
{
return method_exists($event, 'isMainRequest')
? $event->isMainRequest()
: $event->isMasterRequest()
;
}
}
8 changes: 5 additions & 3 deletions src/EventListener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class_alias(FilterControllerEvent::class, RequestListenerControllerEvent::class)
*/
final class RequestListener
{
use KernelEventForwardCompatibilityTrait;

/** @var HubInterface */
private $hub;

Expand All @@ -61,7 +63,7 @@ public function __construct(
*/
public function onKernelRequest(RequestListenerRequestEvent $event): void
{
if (! $event->isMasterRequest()) {
if (! $this->isMainRequest($event)) {
return;
}

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

public function onKernelController(RequestListenerControllerEvent $event): void
{
if (! $event->isMasterRequest()) {
if (! $this->isMainRequest($event)) {
return;
}

Expand All @@ -120,7 +122,7 @@ private function getUserData($user): array
{
if ($user instanceof UserInterface) {
return [
'username' => $user->getUsername(),
'username' => method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername(),
];
}

Expand Down
6 changes: 4 additions & 2 deletions src/EventListener/SubRequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ class_alias(GetResponseEvent::class, SubRequestListenerRequestEvent::class);

final class SubRequestListener
{
use KernelEventForwardCompatibilityTrait;

/**
* Pushes a new {@see Scope} for each SubRequest
*
* @param SubRequestListenerRequestEvent $event
*/
public function onKernelRequest(SubRequestListenerRequestEvent $event): void
{
if ($event->isMasterRequest()) {
if ($this->isMainRequest($event)) {
return;
}

Expand All @@ -41,7 +43,7 @@ public function onKernelRequest(SubRequestListenerRequestEvent $event): void
*/
public function onKernelFinishRequest(FinishRequestEvent $event): void
{
if ($event->isMasterRequest()) {
if ($this->isMainRequest($event)) {
return;
}

Expand Down
7 changes: 6 additions & 1 deletion test/EventListener/RequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,12 @@ public function getSalt()
return null;
}

public function getUsername()
public function getUsername(): string
{
return $this->getUserIdentifier();
}

public function getUserIdentifier(): string
{
return $this->username;
}
Expand Down