forked from rollbar/rollbar-php-symfony-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRollbarHandlerFactory.php
executable file
·70 lines (58 loc) · 1.93 KB
/
RollbarHandlerFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Rollbar\Symfony\RollbarBundle\Factories;
use Psr\Log\LogLevel;
use Rollbar\Monolog\Handler\RollbarHandler;
use Rollbar\Rollbar;
use Rollbar\Symfony\RollbarBundle\DependencyInjection\RollbarExtension;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class RollbarHandlerFactory
*
* @package Rollbar\Symfony\RollbarBundle\Factories
*/
class RollbarHandlerFactory
{
/**
* @var string|null
*/
private $minimumLevel;
/**
* RollbarHandlerFactory constructor.
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$config = $container->getParameter(RollbarExtension::ALIAS . '.config');
if (isset($_ENV['ROLLBAR_TEST_TOKEN']) && $_ENV['ROLLBAR_TEST_TOKEN']) {
$config['access_token'] = $_ENV['ROLLBAR_TEST_TOKEN'];
}
if (!empty($config['person_fn']) && is_callable($config['person_fn'])) {
$config['person'] = null;
} elseif (empty($config['person'])) {
$config['person_fn'] = function () use ($container) {
try {
$token = $container->get('security.token_storage')->getToken();
if ($token) {
$user = $token->getUser();
$serializer = $container->get('serializer');
return \json_decode($serializer->serialize($user, 'json'), true);
}
} catch (\Exception $exception) {
// Ignore
}
};
}
$this->minimumLevel = $config['minimum_level'] ?: LogLevel::ERROR;
Rollbar::init($config, false, false, false);
}
/**
* Create RollbarHandler
*
* @return RollbarHandler
*/
public function createRollbarHandler()
{
return new RollbarHandler(Rollbar::logger(), $this->minimumLevel);
}
}