3 namespace Drupal\devel\EventSubscriber;
5 use Drupal\Core\Session\AccountProxyInterface;
6 use Symfony\Component\EventDispatcher\Event;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8 use Symfony\Component\HttpKernel\KernelEvents;
11 * Listener for handling PHP errors.
13 class ErrorHandlerSubscriber implements EventSubscriberInterface {
18 * @var \Drupal\Core\Session\AccountProxyInterface
23 * ErrorHandlerSubscriber constructor.
25 * @param \Drupal\Core\Session\AccountProxyInterface $account
28 public function __construct(AccountProxyInterface $account) {
29 $this->account = $account;
33 * Register devel error handler.
35 * @param \Symfony\Component\EventDispatcher\Event $event
36 * The event to process.
38 public function registerErrorHandler(Event $event = NULL) {
39 if ($this->account && $this->account->hasPermission('access devel information')) {
40 devel_set_handler(devel_get_handlers());
47 public static function getSubscribedEvents() {
48 // Runs as soon as possible in the request but after
49 // AuthenticationSubscriber (priority 300) because you need to access to
50 // the current user for determine whether register the devel error handler
52 $events[KernelEvents::REQUEST][] = ['registerErrorHandler', 256];