class DatabaseEventSubscriber

Same name in other branches
  1. 11.x core/modules/system/tests/modules/database_test/src/EventSubscriber/DatabaseEventSubscriber.php \Drupal\database_test\EventSubscriber\DatabaseEventSubscriber

Responds to database API events.

Hierarchy

  • class \Drupal\database_test\EventSubscriber\DatabaseEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of DatabaseEventSubscriber

1 file declares its use of DatabaseEventSubscriber
DatabaseEventTest.php in core/tests/Drupal/KernelTests/Core/Database/DatabaseEventTest.php

File

core/modules/system/tests/modules/database_test/src/EventSubscriber/DatabaseEventSubscriber.php, line 13

Namespace

Drupal\database_test\EventSubscriber
View source
class DatabaseEventSubscriber implements EventSubscriberInterface {
    
    /**
     * A counter of started statement executions.
     */
    public int $countStatementStarts = 0;
    
    /**
     * A counter of finished statement executions.
     */
    public int $countStatementEnds = 0;
    
    /**
     * A counter of failed statement executions.
     */
    public int $countStatementFailures = 0;
    
    /**
     * A map of statements being executed.
     */
    public array $statementIdsInExecution = [];
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        return [
            StatementExecutionStartEvent::class => 'onStatementExecutionStart',
            StatementExecutionEndEvent::class => 'onStatementExecutionEnd',
            StatementExecutionFailureEvent::class => 'onStatementExecutionFailure',
        ];
    }
    
    /**
     * Subscribes to a statement execution started event.
     *
     * @param \Drupal\Core\Database\Event\StatementExecutionStartEvent $event
     *   The database event.
     */
    public function onStatementExecutionStart(StatementExecutionStartEvent $event) : void {
        $this->statementIdsInExecution[$event->statementObjectId] = TRUE;
        $this->countStatementStarts++;
    }
    
    /**
     * Subscribes to a statement execution finished event.
     *
     * @param \Drupal\Core\Database\Event\StatementExecutionEndEvent $event
     *   The database event.
     */
    public function onStatementExecutionEnd(StatementExecutionEndEvent $event) : void {
        unset($this->statementIdsInExecution[$event->statementObjectId]);
        $this->countStatementEnds++;
    }
    
    /**
     * Subscribes to a statement execution failure event.
     *
     * @param \Drupal\Core\Database\Event\StatementExecutionFailureEvent $event
     *   The database event.
     */
    public function onStatementExecutionFailure(StatementExecutionFailureEvent $event) : void {
        unset($this->statementIdsInExecution[$event->statementObjectId]);
        $this->countStatementFailures++;
    }

}

Members

Title Sort descending Modifiers Object type Summary
DatabaseEventSubscriber::$countStatementEnds public property A counter of finished statement executions.
DatabaseEventSubscriber::$countStatementFailures public property A counter of failed statement executions.
DatabaseEventSubscriber::$countStatementStarts public property A counter of started statement executions.
DatabaseEventSubscriber::$statementIdsInExecution public property A map of statements being executed.
DatabaseEventSubscriber::getSubscribedEvents public static function
DatabaseEventSubscriber::onStatementExecutionEnd public function Subscribes to a statement execution finished event.
DatabaseEventSubscriber::onStatementExecutionFailure public function Subscribes to a statement execution failure event.
DatabaseEventSubscriber::onStatementExecutionStart public function Subscribes to a statement execution started event.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.