/
ConsoleListener.php
41 lines (35 loc) · 1.06 KB
/
ConsoleListener.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
<?php
namespace Sentry\SentryBundle\EventListener;
use Sentry\SentryBundle\SentryBundle;
use Sentry\State\HubInterface;
use Sentry\State\Scope;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
final class ConsoleListener
{
/** @var HubInterface */
private $hub;
/**
* ConsoleListener constructor.
* @param HubInterface $hub
*/
public function __construct(HubInterface $hub)
{
$this->hub = $hub; // not used, needed to trigger instantiation
}
/**
* This method ensures that the client and error handlers are registered at the start of the command
* execution cycle, and not only on exceptions
*
* @param ConsoleCommandEvent $event
*
* @return void
*/
public function onConsoleCommand(ConsoleCommandEvent $event): void
{
$command = $event->getCommand();
SentryBundle::getCurrentHub()
->configureScope(function (Scope $scope) use ($command): void {
$scope->setTag('command', $command ? $command->getName() : 'N/A');
});
}
}