You are here

class EventDispatcherCollection in Payment 8.2

Dispatches events to a collection of event dispatchers.

Hierarchy

Expanded class hierarchy of EventDispatcherCollection

1 file declares its use of EventDispatcherCollection
EventDispatcherCollectionTest.php in tests/src/Unit/EventDispatcherCollectionTest.php
1 string reference to 'EventDispatcherCollection'
payment.services.yml in ./payment.services.yml
payment.services.yml
1 service uses EventDispatcherCollection
payment.event_dispatcher in ./payment.services.yml
Drupal\payment\EventDispatcherCollection

File

src/EventDispatcherCollection.php, line 14

Namespace

Drupal\payment
View source
class EventDispatcherCollection implements EventDispatcherInterface {

  /**
   * The event dispatchers.
   *
   * @var \Drupal\payment\EventDispatcherInterface[]
   */
  protected $eventDispatchers = [];

  /**
   * Adds an event dispatcher to the collection.
   *
   * @param \Drupal\payment\EventDispatcherInterface $event_dispatcher
   *
   * @return $this
   */
  public function addEventDispatcher(EventDispatcherInterface $event_dispatcher) {
    $this->eventDispatchers[] = $event_dispatcher;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function alterQueueLoadedPaymentIds($queue_id, $category_id, $owner_id, array $payment_ids) {
    foreach ($this->eventDispatchers as $event_dispatcher) {
      $payment_ids = $event_dispatcher
        ->alterQueueLoadedPaymentIds($queue_id, $category_id, $owner_id, $payment_ids);
    }
    return $payment_ids;
  }

  /**
   * {@inheritdoc}
   */
  public function setPaymentStatus(PaymentInterface $payment, PaymentStatusInterface $previous_payment_status = NULL) {
    foreach ($this->eventDispatchers as $event_dispatcher) {
      $event_dispatcher
        ->setPaymentStatus($payment, $previous_payment_status);
    }
  }

  /**
   * {@inheritdoc}
   *
   */
  public function preExecutePayment(PaymentInterface $payment) {
    foreach ($this->eventDispatchers as $event_dispatcher) {
      $event_dispatcher
        ->preExecutePayment($payment);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function executePaymentAccess(PaymentInterface $payment, PaymentMethodInterface $payment_method, AccountInterface $account) {
    $access = AccessResult::neutral();
    foreach ($this->eventDispatchers as $event_dispatcher) {
      $access = $access
        ->orIf($event_dispatcher
        ->executePaymentAccess($payment, $payment_method, $account));
    }
    return $access;
  }

  /**
   * {@inheritdoc}
   *
   */
  public function preCapturePayment(PaymentInterface $payment) {
    foreach ($this->eventDispatchers as $event_dispatcher) {
      $event_dispatcher
        ->preCapturePayment($payment);
    }
  }

  /**
   * {@inheritdoc}
   *
   */
  public function preRefundPayment(PaymentInterface $payment) {
    foreach ($this->eventDispatchers as $event_dispatcher) {
      $event_dispatcher
        ->preRefundPayment($payment);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function preResumeContext(PaymentInterface $payment) {
    foreach ($this->eventDispatchers as $event_dispatcher) {
      $event_dispatcher
        ->preResumeContext($payment);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventDispatcherCollection::$eventDispatchers protected property The event dispatchers.
EventDispatcherCollection::addEventDispatcher public function Adds an event dispatcher to the collection.
EventDispatcherCollection::alterQueueLoadedPaymentIds public function Alters the payment IDs loaded by a payment queue. Overrides EventDispatcherInterface::alterQueueLoadedPaymentIds
EventDispatcherCollection::executePaymentAccess public function Checks access for before executing a payment. Overrides EventDispatcherInterface::executePaymentAccess
EventDispatcherCollection::preCapturePayment public function Fires right before a payment will be captured. Overrides EventDispatcherInterface::preCapturePayment
EventDispatcherCollection::preExecutePayment public function Fires right before a payment will be executed. Overrides EventDispatcherInterface::preExecutePayment
EventDispatcherCollection::preRefundPayment public function Fires right before a payment will be refunded. Overrides EventDispatcherInterface::preRefundPayment
EventDispatcherCollection::preResumeContext public function Fires right before a payment type's context is resumed. Overrides EventDispatcherInterface::preResumeContext
EventDispatcherCollection::setPaymentStatus public function Responds to a new payment status being set. Overrides EventDispatcherInterface::setPaymentStatus