You are here

class AcsfEventDispatcher in Acquia Cloud Site Factory Connector 8

Same name and namespace in other branches
  1. 8.2 src/Event/AcsfEventDispatcher.php \Drupal\acsf\Event\AcsfEventDispatcher

AcsfEventDispatcher.

This class defines the base event dispatcher. This will take a specified list of handlers and execute them serially. Any handler has the option to interrupt the execution of the event.

Hierarchy

Expanded class hierarchy of AcsfEventDispatcher

1 file declares its use of AcsfEventDispatcher
AcsfEventsTest.php in tests/AcsfEventsTest.php
Provides PHPUnit tests for the Acsf Events system.

File

src/Event/AcsfEventDispatcher.php, line 12

Namespace

Drupal\acsf\Event
View source
class AcsfEventDispatcher {

  /**
   * Constructor.
   */
  public function __construct() {
    $this->running = FALSE;
  }

  /**
   * Allows the interruption of the dispatcher.
   */
  public function interrupt() {
    $this->running = FALSE;
  }

  /**
   * Dispatches a list of event handlers.
   *
   * @param AcsfEvent $event
   *   The AcsfEvent that is being executed.
   */
  public function dispatch(AcsfEvent $event) {
    $this->running = TRUE;
    while ($this->running && ($handler = $event
      ->popHandler('incomplete'))) {
      try {

        // Capture some information about the handler.
        $handler->started = microtime(TRUE);
        $handler
          ->handle();
        $handler->completed = microtime(TRUE);
        $event
          ->pushHandler($handler, 'complete');
      } catch (\Exception $e) {
        $handler->message = sprintf('Class %s handler failed for event %s: %s', get_class($handler), $event->type, $e
          ->getMessage());
        $event
          ->pushHandler($handler, 'failed');
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcsfEventDispatcher::dispatch public function Dispatches a list of event handlers.
AcsfEventDispatcher::interrupt public function Allows the interruption of the dispatcher.
AcsfEventDispatcher::__construct public function Constructor.