Skip to content

Commit 15e2f90

Browse files
committed
allow to install the bundle without Symfony security
1 parent fd43dd9 commit 15e2f90

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"symfony/event-dispatcher": "^4.4.20||^5.0.11||^6.0||^7.0",
2424
"symfony/http-kernel": "^4.4.20||^5.0.11||^6.0||^7.0",
2525
"symfony/polyfill-php80": "^1.22",
26-
"symfony/psr-http-message-bridge": "^1.2||^2.0||^6.4||^7.0",
27-
"symfony/security-core": "^4.4.20||^5.0.11||^6.0||^7.0",
28-
"symfony/security-http": "^4.4.20||^5.0.11||^6.0||^7.0"
26+
"symfony/psr-http-message-bridge": "^1.2||^2.0||^6.4||^7.0"
2927
},
3028
"require-dev": {
3129
"doctrine/dbal": "^2.13||^3.3||^4.0",
@@ -46,6 +44,8 @@
4644
"symfony/monolog-bundle": "^3.4",
4745
"symfony/phpunit-bridge": "^5.2.6||^6.0||^7.0",
4846
"symfony/process": "^4.4.20||^5.0.11||^6.0||^7.0",
47+
"symfony/security-core": "^4.4.20||^5.0.11||^6.0||^7.0",
48+
"symfony/security-http": "^4.4.20||^5.0.11||^6.0||^7.0",
4949
"symfony/twig-bundle": "^4.4.20||^5.0.11||^6.0||^7.0",
5050
"symfony/yaml": "^4.4.20||^5.0.11||^6.0||^7.0",
5151
"vimeo/psalm": "^4.3||^5.16.0"

src/DependencyInjection/Compiler/AddLoginListenerTagPass.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ final class AddLoginListenerTagPass implements CompilerPassInterface
1717
*/
1818
public function process(ContainerBuilder $container): void
1919
{
20+
if (!$container->hasDefinition(LoginListener::class)) {
21+
return;
22+
}
2023
$listenerDefinition = $container->getDefinition(LoginListener::class);
2124

22-
if (!class_exists(LoginSuccessEvent::class)) {
25+
if (class_exists(LoginSuccessEvent::class)) {
26+
$listenerDefinition->addTag('kernel.event_listener', [
27+
'event' => LoginSuccessEvent::class,
28+
'method' => 'handleLoginSuccessEvent',
29+
]);
30+
} elseif (class_exists(AuthenticationSuccessEvent::class)) {
2331
$listenerDefinition->addTag('kernel.event_listener', [
2432
'event' => AuthenticationSuccessEvent::class,
2533
'method' => 'handleAuthenticationSuccessEvent',

src/DependencyInjection/SentryExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Sentry\Options;
1616
use Sentry\SentryBundle\EventListener\ConsoleListener;
1717
use Sentry\SentryBundle\EventListener\ErrorListener;
18+
use Sentry\SentryBundle\EventListener\LoginListener;
1819
use Sentry\SentryBundle\EventListener\MessengerListener;
1920
use Sentry\SentryBundle\EventListener\TracingConsoleListener;
2021
use Sentry\SentryBundle\EventListener\TracingRequestListener;
@@ -34,6 +35,7 @@
3435
use Symfony\Component\DependencyInjection\Reference;
3536
use Symfony\Component\HttpClient\HttpClient;
3637
use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension;
38+
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
3739

3840
final class SentryExtension extends ConfigurableExtension
3941
{
@@ -75,6 +77,10 @@ protected function loadInternal(array $mergedConfig, ContainerBuilder $container
7577
$this->registerTwigTracingConfiguration($container, $mergedConfig['tracing']);
7678
$this->registerCacheTracingConfiguration($container, $mergedConfig['tracing']);
7779
$this->registerHttpClientTracingConfiguration($container, $mergedConfig['tracing']);
80+
81+
if (!class_exists(TokenStorageInterface::class)) {
82+
$container->removeDefinition(LoginListener::class);
83+
}
7884
}
7985

8086
/**

src/Resources/config/services.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
<argument type="service" id="security.token_storage" on-invalid="ignore" />
8484

8585
<tag name="kernel.event_listener" event="kernel.request" method="handleKernelRequestEvent" />
86-
<tag name="kernel.event_listener" event="Symfony\Component\Security\Http\Event\LoginSuccessEvent" method="handleLoginSuccessEvent" />
8786
</service>
8887

8988
<service id="Sentry\SentryBundle\Command\SentryTestCommand" class="Sentry\SentryBundle\Command\SentryTestCommand">

0 commit comments

Comments
 (0)