You are here

class CreateDeleteAppKey in Apigee Edge 8

Developer app credential create/delete event subscriber.

Hierarchy

  • class \Drupal\apigee_edge_test_app_keys\EventSubscriber\CreateDeleteAppKey implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of CreateDeleteAppKey

1 file declares its use of CreateDeleteAppKey
DeveloperAppCredentialEventTest.php in tests/src/Functional/DeveloperAppCredentialEventTest.php
1 string reference to 'CreateDeleteAppKey'
apigee_edge_test_app_keys.services.yml in tests/modules/apigee_edge_test_app_keys/apigee_edge_test_app_keys.services.yml
tests/modules/apigee_edge_test_app_keys/apigee_edge_test_app_keys.services.yml
1 service uses CreateDeleteAppKey
apigee_edge.event_subscriber.create_delete_app_key in tests/modules/apigee_edge_test_app_keys/apigee_edge_test_app_keys.services.yml
Drupal\apigee_edge_test_app_keys\EventSubscriber\CreateDeleteAppKey

File

tests/modules/apigee_edge_test_app_keys/src/EventSubscriber/CreateDeleteAppKey.php, line 32

Namespace

Drupal\apigee_edge_test_app_keys\EventSubscriber
View source
class CreateDeleteAppKey implements EventSubscriberInterface {

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  private $state;

  /**
   * The time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  private $time;

  /**
   * DeleteAppKey constructor.
   *
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The time service.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(TimeInterface $time, StateInterface $state) {
    $this->state = $state;
    $this->time = $time;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      AppCredentialCreateEvent::EVENT_NAME => 'onAppKeyCreateDelete',
      AppCredentialDeleteEvent::EVENT_NAME => 'onAppKeyCreateDelete',
    ];
  }

  /**
   * Creates a states entry when a dev. app credential is created or deleted.
   *
   * @param \Drupal\apigee_edge\Event\AppCredentialDeleteEvent|\Drupal\apigee_edge\Event\AppCredentialCreateEvent $event
   *   The developer app credential create or delete event.
   */
  public function onAppKeyCreateDelete($event) {
    $this->state
      ->set(static::generateStateKey($event
      ->getAppType(), $event
      ->getOwnerId(), $event
      ->getAppName(), $event
      ->getCredential()
      ->id()), $this->time
      ->getCurrentTime());
  }

  /**
   * Generates a unique states key for an app credential.
   *
   * @param string $app_type
   *   Either "developer" or "company".
   * @param string $owner_id
   *   Developer id or company name.
   * @param string $app_name
   *   App name.
   * @param string $credential_key
   *   Credential key.
   *
   * @return string
   *   States key.
   */
  public static function generateStateKey(string $app_type, string $owner_id, string $app_name, string $credential_key) : string {
    return "{$app_type}-{$owner_id}-{$app_name}-{$credential_key}";
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CreateDeleteAppKey::$state private property The state service.
CreateDeleteAppKey::$time private property The time service.
CreateDeleteAppKey::generateStateKey public static function Generates a unique states key for an app credential.
CreateDeleteAppKey::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CreateDeleteAppKey::onAppKeyCreateDelete public function Creates a states entry when a dev. app credential is created or deleted.
CreateDeleteAppKey::__construct public function DeleteAppKey constructor.