You are here

class SmsTestGatewayEventSubscriber in SMS Framework 8

Same name and namespace in other branches
  1. 2.x tests/modules/sms_test_gateway/src/EventSubscriber/SmsTestGatewayEventSubscriber.php \Drupal\sms_test_gateway\EventSubscriber\SmsTestGatewayEventSubscriber
  2. 2.1.x tests/modules/sms_test_gateway/src/EventSubscriber/SmsTestGatewayEventSubscriber.php \Drupal\sms_test_gateway\EventSubscriber\SmsTestGatewayEventSubscriber

Test event subscriber.

Hierarchy

  • class \Drupal\sms_test_gateway\EventSubscriber\SmsTestGatewayEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of SmsTestGatewayEventSubscriber

1 string reference to 'SmsTestGatewayEventSubscriber'
sms_test_gateway.services.yml in tests/modules/sms_test_gateway/sms_test_gateway.services.yml
tests/modules/sms_test_gateway/sms_test_gateway.services.yml
1 service uses SmsTestGatewayEventSubscriber
sms_test_gateway.event_subscriber in tests/modules/sms_test_gateway/sms_test_gateway.services.yml
Drupal\sms_test_gateway\EventSubscriber\SmsTestGatewayEventSubscriber

File

tests/modules/sms_test_gateway/src/EventSubscriber/SmsTestGatewayEventSubscriber.php, line 12

Namespace

Drupal\sms_test_gateway\EventSubscriber
View source
class SmsTestGatewayEventSubscriber implements EventSubscriberInterface {

  /**
   * Store incoming messages in memory.
   *
   * @param \Drupal\sms\Event\SmsMessageEvent $event
   *   The event.
   *
   * @see sms_test_gateway_get_incoming()
   */
  public function memoryIncomingMessage(SmsMessageEvent $event) {
    $sms_message = $event
      ->getMessages()[0];

    // Save incoming result for later retrieval.
    $key = 'sms_test_gateway_sms_incoming_preprocess';
    $result =& drupal_static($key);
    if (!is_null($sms_message
      ->getRecipients()) && !is_null($sms_message
      ->getMessage())) {
      $recipients = $sms_message
        ->getRecipients();
      $result['number'] = count($recipients) ? reset($recipients) : NULL;
      $result['message'] = $sms_message
        ->getMessage();
      \Drupal::state()
        ->set($key, $result);
    }
    $key = 'sms_test_gateway.memory.incoming';
    $incoming_messages =& drupal_static($key, []);
    foreach ($event
      ->getMessages() as $message) {

      /** @var \Drupal\sms\Message\SmsMessageInterface $message */
      $incoming_messages[$message
        ->getGateway()
        ->id()][] = $message;
    }
    \Drupal::state()
      ->set($key, $incoming_messages);
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[SmsEvents::MESSAGE_INCOMING_POST_PROCESS][] = [
      'memoryIncomingMessage',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SmsTestGatewayEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
SmsTestGatewayEventSubscriber::memoryIncomingMessage public function Store incoming messages in memory.