Interim commit.
[yaffs-website] / web / modules / contrib / devel / src / EventSubscriber / ErrorHandlerSubscriber.php
1 <?php
2
3 namespace Drupal\devel\EventSubscriber;
4
5 use Drupal\Core\Session\AccountProxyInterface;
6 use Symfony\Component\EventDispatcher\Event;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8 use Symfony\Component\HttpKernel\KernelEvents;
9
10 /**
11  * Listener for handling PHP errors.
12  */
13 class ErrorHandlerSubscriber implements EventSubscriberInterface {
14
15   /**
16    * The current user.
17    *
18    * @var \Drupal\Core\Session\AccountProxyInterface
19    */
20   protected $account;
21
22   /**
23    * ErrorHandlerSubscriber constructor.
24    *
25    * @param \Drupal\Core\Session\AccountProxyInterface $account
26    *   The current user.
27    */
28   public function __construct(AccountProxyInterface $account) {
29     $this->account = $account;
30   }
31
32   /**
33    * Register devel error handler.
34    *
35    * @param \Symfony\Component\EventDispatcher\Event $event
36    *   The event to process.
37    */
38   public function registerErrorHandler(Event $event = NULL) {
39     if ($this->account && $this->account->hasPermission('access devel information')) {
40       devel_set_handler(devel_get_handlers());
41     }
42   }
43
44   /**
45    * {@inheritdoc}
46    */
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
51     // or not.
52     $events[KernelEvents::REQUEST][] = ['registerErrorHandler', 256];
53
54     return $events;
55   }
56
57 }