You are here

class ApigeeEdgeActionsDebugEventSubscriber in Apigee Edge 8

Implements event subscriber for all apigee_edge_actions events.

Hierarchy

Expanded class hierarchy of ApigeeEdgeActionsDebugEventSubscriber

1 string reference to 'ApigeeEdgeActionsDebugEventSubscriber'
apigee_edge_actions_debug.services.yml in modules/apigee_edge_actions/modules/apigee_edge_actions_debug/apigee_edge_actions_debug.services.yml
modules/apigee_edge_actions/modules/apigee_edge_actions_debug/apigee_edge_actions_debug.services.yml
1 service uses ApigeeEdgeActionsDebugEventSubscriber
apigee_edge_actions_debug_subscriber in modules/apigee_edge_actions/modules/apigee_edge_actions_debug/apigee_edge_actions_debug.services.yml
Drupal\apigee_edge_actions_debug\EventSubscriber\ApigeeEdgeActionsDebugEventSubscriber

File

modules/apigee_edge_actions/modules/apigee_edge_actions_debug/src/EventSubscriber/ApigeeEdgeActionsDebugEventSubscriber.php, line 31

Namespace

Drupal\apigee_edge_actions_debug\EventSubscriber
View source
class ApigeeEdgeActionsDebugEventSubscriber implements EventSubscriberInterface {

  /**
   * The logger channel.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $logger;

  /**
   * ApigeeEdgeActionsDebugEventSubscriber constructor.
   *
   * @param \Drupal\Core\Logger\LoggerChannelInterface $logger
   *   The logger channel.
   */
  public function __construct(LoggerChannelInterface $logger) {
    $this->logger = $logger;
  }

  /**
   * Responds to rules events.
   *
   * @param \Symfony\Component\EventDispatcher\Event $event
   *   The event object.
   * @param string $event_name
   *   The event name.
   */
  public function onRulesEvent(Event $event, $event_name) {

    // Log the dispatched event.
    if ($event instanceof ApigeeEdgeActionsEventInterface) {
      $this->logger
        ->notice("Event {$event_name} was dispatched.");
    }
  }

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

    // Ensure this is called after the container is built.
    if (!\Drupal::hasService('state')) {
      return [];
    }
    $events = [];

    // Register a callback for all registered rules events.
    if ($rules_events = \Drupal::state()
      ->get('rules.registered_events')) {
      foreach ($rules_events as $rules_event) {
        $events[$rules_event][] = [
          'onRulesEvent',
          100,
        ];
      }
    }
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApigeeEdgeActionsDebugEventSubscriber::$logger protected property The logger channel.
ApigeeEdgeActionsDebugEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ApigeeEdgeActionsDebugEventSubscriber::onRulesEvent public function Responds to rules events.
ApigeeEdgeActionsDebugEventSubscriber::__construct public function ApigeeEdgeActionsDebugEventSubscriber constructor.