You are here

class ErrorHandlerSubscriber in Devel 8.2

Same name and namespace in other branches
  1. 8.3 src/EventSubscriber/ErrorHandlerSubscriber.php \Drupal\devel\EventSubscriber\ErrorHandlerSubscriber
  2. 8 src/EventSubscriber/ErrorHandlerSubscriber.php \Drupal\devel\EventSubscriber\ErrorHandlerSubscriber
  3. 4.x src/EventSubscriber/ErrorHandlerSubscriber.php \Drupal\devel\EventSubscriber\ErrorHandlerSubscriber

Listener for handling PHP errors.

Hierarchy

  • class \Drupal\devel\EventSubscriber\ErrorHandlerSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ErrorHandlerSubscriber

1 string reference to 'ErrorHandlerSubscriber'
devel.services.yml in ./devel.services.yml
devel.services.yml
1 service uses ErrorHandlerSubscriber
devel.error_subscriber in ./devel.services.yml
Drupal\devel\EventSubscriber\ErrorHandlerSubscriber

File

src/EventSubscriber/ErrorHandlerSubscriber.php, line 13

Namespace

Drupal\devel\EventSubscriber
View source
class ErrorHandlerSubscriber implements EventSubscriberInterface {

  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $account;

  /**
   * ErrorHandlerSubscriber constructor.
   *
   * @param \Drupal\Core\Session\AccountProxyInterface $account
   *   The current user.
   */
  public function __construct(AccountProxyInterface $account) {
    $this->account = $account;
  }

  /**
   * Register devel error handler.
   *
   * @param \Symfony\Component\EventDispatcher\Event $event
   *   The event to process.
   */
  public function registerErrorHandler(Event $event = NULL) {
    if ($this->account && $this->account
      ->hasPermission('access devel information')) {
      devel_set_handler(devel_get_handlers());
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Runs as soon as possible in the request but after
    // AuthenticationSubscriber (priority 300) because you need to access to
    // the current user for determine whether register the devel error handler
    // or not.
    $events[KernelEvents::REQUEST][] = [
      'registerErrorHandler',
      256,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ErrorHandlerSubscriber::$account protected property The current user.
ErrorHandlerSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ErrorHandlerSubscriber::registerErrorHandler public function Register devel error handler.
ErrorHandlerSubscriber::__construct public function ErrorHandlerSubscriber constructor.