Skip to content

Commit

Permalink
Fix class_alias issues (#309)
Browse files Browse the repository at this point in the history
* Fix conflict with other bundles when creating alias for Symfony's RequestEvent

* Add changelog entry

* Slate release for today

Co-authored-by: Christian Scheb <[email protected]>
  • Loading branch information
Jean85 and scheb authored Jan 24, 2020
1 parent ff7de7b commit b35dfa8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit b35dfa8

Please sign in to comment.