Skip to content
Open
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
10 changes: 6 additions & 4 deletions Factories/RollbarHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down