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

Fix class_alias issues #309

Merged
merged 3 commits into from Jan 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,7 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## Unreleased

- ...

## 3.4.1 (2020-01-24)
- Fix issue due to usage of `class_alias` to fix deprecations, which could break BC layers of third party packages (#309, thanks to @scheb)

## 3.4.0 (2020-01-20)
- Add support for `sentry/sentry` 2.3 (#298)
Expand Down
27 changes: 18 additions & 9 deletions src/EventListener/RequestListener.php
Expand Up @@ -9,15 +9,24 @@
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;

if (! class_exists(RequestEvent::class)) {
class_alias(GetResponseEvent::class, RequestEvent::class);
}

if (! class_exists(ControllerEvent::class)) {
class_alias(FilterControllerEvent::class, ControllerEvent::class);
if (Kernel::MAJOR_VERSION >= 5) {
if (! class_exists('Sentry\SentryBundle\EventListener\UserContextRequestEvent')) {
class_alias(RequestEvent::class, 'Sentry\SentryBundle\EventListener\UserContextRequestEvent');
}
if (! class_exists('Sentry\SentryBundle\EventListener\UserContextControllerEvent')) {
class_alias(ControllerEvent::class, 'Sentry\SentryBundle\EventListener\UserContextControllerEvent');
}
} else {
if (! class_exists('Sentry\SentryBundle\EventListener\UserContextRequestEvent')) {
class_alias(GetResponseEvent::class, 'Sentry\SentryBundle\EventListener\UserContextRequestEvent');
}
if (! class_exists('Sentry\SentryBundle\EventListener\UserContextControllerEvent')) {
class_alias(FilterControllerEvent::class, 'Sentry\SentryBundle\EventListener\UserContextControllerEvent');
}
}

/**
Expand Down Expand Up @@ -48,9 +57,9 @@ public function __construct(
/**
* Set the username from the security context by listening on core.request
*
* @param RequestEvent $event
* @param UserContextRequestEvent $event
*/
public function onKernelRequest(RequestEvent $event): void
public function onKernelRequest(UserContextRequestEvent $event): void
{
if (! $event->isMasterRequest()) {
return;
Expand Down Expand Up @@ -85,7 +94,7 @@ public function onKernelRequest(RequestEvent $event): void
});
}

public function onKernelController(ControllerEvent $event): void
public function onKernelController(UserContextControllerEvent $event): void
{
if (! $event->isMasterRequest()) {
return;
Expand Down
15 changes: 11 additions & 4 deletions src/EventListener/SubRequestListener.php
Expand Up @@ -6,19 +6,26 @@
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Kernel;

if (! class_exists(RequestEvent::class)) {
class_alias(GetResponseEvent::class, RequestEvent::class);
if (Kernel::MAJOR_VERSION >= 5) {
if (! class_exists('Sentry\SentryBundle\EventListener\UserContextRequestEvent')) {
class_alias(RequestEvent::class, 'Sentry\SentryBundle\EventListener\UserContextRequestEvent');
}
} else {
if (! class_exists('Sentry\SentryBundle\EventListener\UserContextRequestEvent')) {
class_alias(GetResponseEvent::class, 'Sentry\SentryBundle\EventListener\UserCon textRequestEvent');
}
}

final class SubRequestListener
{
/**
* Pushes a new {@see Scope} for each SubRequest
*
* @param RequestEvent $event
* @param UserContextRequestEvent $event
*/
public function onKernelRequest(RequestEvent $event): void
public function onKernelRequest(UserContextRequestEvent $event): void
{
if ($event->isMasterRequest()) {
return;
Expand Down