diff --git a/Factories/RollbarHandlerFactory.php b/Factories/RollbarHandlerFactory.php index 34135fa..a9cdde2 100755 --- a/Factories/RollbarHandlerFactory.php +++ b/Factories/RollbarHandlerFactory.php @@ -6,12 +6,14 @@ use Monolog\Handler\RollbarHandler; use Rollbar\Rollbar; use Rollbar\Symfony\RollbarBundle\DependencyInjection\RollbarExtension; +use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Kernel; +use Symfony\Component\Serializer\SerializerInterface; class RollbarHandlerFactory { - public function __construct(ContainerInterface $container) + public function __construct(ContainerInterface $container, SerializerInterface $serializer, Security|null $security=null) { $config = $container->getParameter(RollbarExtension::ALIAS . '.config'); @@ -22,13 +24,13 @@ public function __construct(ContainerInterface $container) if (!empty($config['person_fn']) && is_callable($config['person_fn'])) { $config['person'] = null; } elseif (empty($config['person'])) { - $config['person_fn'] = static function () use ($container) { + $config['person_fn'] = static function () use ($security, $serializer) { try { - $token = $container->get('security.token_storage')->getToken(); + $token = $security->getToken(); if ($token) { $user = $token->getUser(); - $serializer = $container->get('serializer'); + return \json_decode($serializer->serialize($user, 'json'), true, 512, JSON_THROW_ON_ERROR); } } catch (\Throwable $exception) { diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 37f1c65..d9e9406 100755 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -3,6 +3,8 @@ services: Rollbar\Symfony\RollbarBundle\Factories\RollbarHandlerFactory: arguments: - '@service_container' + - '@serializer' + - '@?security.helper' Rollbar\Monolog\Handler\RollbarHandler: factory: ['@Rollbar\Symfony\RollbarBundle\Factories\RollbarHandlerFactory', createRollbarHandler] diff --git a/composer.json b/composer.json index 9055b44..a5cced5 100755 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "phpunit/phpunit": "^9.6|^10.1", "symfony/framework-bundle": "^5.4|^6.2", "squizlabs/php_codesniffer": "^3.7", - "matthiasnoback/symfony-dependency-injection-test": "^4.3" + "matthiasnoback/symfony-dependency-injection-test": "^4.3", + "symfony/security-bundle": "^5.4|^6.2" }, "scripts": { "test": [