You are here

final class DeveloperController in Apigee Edge 8

Definition of the Developer controller service.

This integrates the Management API's Developer controller from the SDK's with Drupal.

Hierarchy

Expanded class hierarchy of DeveloperController

1 string reference to 'DeveloperController'
apigee_edge.services.yml in ./apigee_edge.services.yml
apigee_edge.services.yml
1 service uses DeveloperController
apigee_edge.controller.developer in ./apigee_edge.services.yml
Drupal\apigee_edge\Entity\Controller\DeveloperController

File

src/Entity/Controller/DeveloperController.php, line 39

Namespace

Drupal\apigee_edge\Entity\Controller
View source
final class DeveloperController implements DeveloperControllerInterface, EntityCacheAwareControllerInterface {
  use CachedEntityCrudOperationsControllerTrait {
    delete as private traitDelete;
  }
  use CachedPaginatedEntityIdListingControllerTrait;
  use CachedPaginatedEntityListingControllerTrait;
  use CachedPaginatedControllerHelperTrait;
  use CachedAttributesAwareEntityControllerTrait;

  /**
   * Local cache for the decorated developer controller from the SDK.
   *
   * @var \Apigee\Edge\Api\Management\Controller\DeveloperController|null
   *
   * @see decorated()
   */
  private $instance;

  /**
   * The SDK connector service.
   *
   * @var \Drupal\apigee_edge\SDKConnectorInterface
   */
  private $connector;

  /**
   * The organization controller service.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface
   */
  private $orgController;

  /**
   * The entity cache.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\Cache\EntityCacheInterface
   */
  private $entityCache;

  /**
   * The entity id cache.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCacheInterface
   */
  private $entityIdCache;

  /**
   * The app cache by owner factory service.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerFactoryInterface
   */
  private $appCacheByOwnerFactory;

  /**
   * The app name cache by owner factory service.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\Cache\AppNameCacheByOwnerFactoryInterface
   */
  private $appNameCacheByOwnerFactory;

  /**
   * DeveloperController constructor.
   *
   * @param \Drupal\apigee_edge\SDKConnectorInterface $connector
   *   The SDK connector service.
   * @param \Drupal\apigee_edge\Entity\Controller\OrganizationControllerInterface $org_controller
   *   The organization controller service.
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\EntityCacheInterface $entity_cache
   *   The entity cache used by this controller.
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\EntityIdCacheInterface $entity_id_cache
   *   The entity id cache used by this controller.
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerFactoryInterface $app_cache_by_owner_factory
   *   The app cache by owner factory service.
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\AppNameCacheByOwnerFactoryInterface $app_name_cache_by_owner
   *   The app name cache by owner factory service.
   */
  public function __construct(SDKConnectorInterface $connector, OrganizationControllerInterface $org_controller, EntityCacheInterface $entity_cache, EntityIdCacheInterface $entity_id_cache, AppCacheByOwnerFactoryInterface $app_cache_by_owner_factory, AppNameCacheByOwnerFactoryInterface $app_name_cache_by_owner) {
    $this->connector = $connector;
    $this->orgController = $org_controller;
    $this->entityCache = $entity_cache;
    $this->entityIdCache = $entity_id_cache;
    $this->appCacheByOwnerFactory = $app_cache_by_owner_factory;
    $this->appNameCacheByOwnerFactory = $app_name_cache_by_owner;
  }

  /**
   * {@inheritdoc}
   */
  public function entityCache() : EntityCacheInterface {
    return $this->entityCache;
  }

  /**
   * {@inheritdoc}
   */
  protected function entityIdCache() : EntityIdCacheInterface {
    return $this->entityIdCache;
  }

  /**
   * Returns the decorated developer controller from the SDK.
   *
   * @return \Apigee\Edge\Api\Management\Controller\DeveloperControllerInterface
   *   The initialized developer controller.
   */
  protected function decorated() : EdgeDeveloperControllerInterface {
    if ($this->instance === NULL) {
      $this->instance = new EdgeDeveloperController($this->connector
        ->getOrganization(), $this->connector
        ->getClient(), NULL, $this->orgController);
    }
    return $this->instance;
  }

  /**
   * {@inheritdoc}
   */
  public function getDeveloperByApp(string $app_name) : DeveloperInterface {
    $developer = $this
      ->decorated()
      ->getDeveloperByApp($app_name);

    // We do not keep cache entries about developer and app relationships so
    // we could not serve this request from cache but at least we add the
    // loaded developer to the cache here.
    $this->entityCache
      ->saveEntities([
      $developer,
    ]);
    return $developer;
  }

  /**
   * {@inheritdoc}
   */
  public function getOrganisationName() : string {
    return $this
      ->decorated()
      ->getOrganisationName();
  }

  /**
   * {@inheritdoc}
   */
  public function setStatus(string $entity_id, string $status) : void {
    $this
      ->decorated()
      ->setStatus($entity_id, $status);

    // Enforce reload of entity from Apigee Edge.
    $this->entityCache
      ->removeEntities([
      $entity_id,
    ]);
    $this->entityCache
      ->allEntitiesInCache(FALSE);
  }

  /**
   * {@inheritdoc}
   */
  public function delete(string $entity_id) : EntityInterface {

    /** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface $entity */
    $entity = $this
      ->traitDelete($entity_id);

    // Invalidate app caches that belongs to this developer.
    // This is implementation probably overcomplicated,
    // we may optimize this later.
    foreach ([
      $entity
        ->getEmail(),
      $entity
        ->getDeveloperId(),
    ] as $owner) {
      $app_cache = $this->appCacheByOwnerFactory
        ->getAppCache($owner);
      $app_names = [];

      /** @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $app */
      foreach ($app_cache
        ->getEntities() as $app) {
        $app_names[] = $app
          ->getAppId();
      }
      $app_cache
        ->removeEntities($app_names);

      // App cache has cleared all app names that it knows about
      // but it could happen that there are some remaining app names in the
      // app name cache that has not be created by app cache.
      $app_name_cache = $this->appNameCacheByOwnerFactory
        ->getAppNameCache($owner);
      $app_name_cache
        ->removeIds($app_name_cache
        ->getIds());
    }
    return $entity;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CachedAttributesAwareEntityControllerTrait::deleteAttribute public function
CachedAttributesAwareEntityControllerTrait::getAttribute public function
CachedAttributesAwareEntityControllerTrait::getAttributes public function
CachedAttributesAwareEntityControllerTrait::updateAttribute public function
CachedAttributesAwareEntityControllerTrait::updateAttributes public function
CachedEntityCrudOperationsControllerTrait::create public function
CachedEntityCrudOperationsControllerTrait::delete public function Aliased as: traitDelete
CachedEntityCrudOperationsControllerTrait::load public function 1
CachedEntityCrudOperationsControllerTrait::update public function
CachedPaginatedControllerHelperTrait::createPager public function
CachedPaginatedEntityIdListingControllerTrait::extractSubsetOfAssociativeArray abstract protected function
CachedPaginatedEntityIdListingControllerTrait::getEntityIds public function
CachedPaginatedEntityListingControllerTrait::getEntities public function
DeveloperController::$appCacheByOwnerFactory private property The app cache by owner factory service.
DeveloperController::$appNameCacheByOwnerFactory private property The app name cache by owner factory service.
DeveloperController::$connector private property The SDK connector service.
DeveloperController::$entityCache private property The entity cache.
DeveloperController::$entityIdCache private property The entity id cache.
DeveloperController::$instance private property Local cache for the decorated developer controller from the SDK.
DeveloperController::$orgController private property The organization controller service.
DeveloperController::decorated protected function Returns the decorated developer controller from the SDK. Overrides CachedEntityCrudOperationsControllerTrait::decorated
DeveloperController::delete public function
DeveloperController::entityCache public function Returns the entity cache used by the controller. Overrides EntityCacheAwareControllerTrait::entityCache
DeveloperController::entityIdCache protected function Entity id cache used by the entity controller. Overrides CachedPaginatedEntityIdListingControllerTrait::entityIdCache
DeveloperController::getDeveloperByApp public function
DeveloperController::getOrganisationName public function
DeveloperController::setStatus public function
DeveloperController::__construct public function DeveloperController constructor.