You are here

final class OrganizationController in Apigee Edge 8

Definition of the Organization controller service.

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

We created this to speed up entity controllers that have to use pagination when list entities from Apigee Edge. There is no need to load the same organization profile multiple times in the same page request when all entities are being loaded from Apigee Edge.

All paginated entity controllers should use this service.

Hierarchy

Expanded class hierarchy of OrganizationController

See also

\Apigee\Edge\Controller\PaginationHelperTrait::listEntities()

\Drupal\apigee_edge\Entity\Controller\DeveloperController

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

File

src/Entity/Controller/OrganizationController.php, line 44

Namespace

Drupal\apigee_edge\Entity\Controller
View source
final class OrganizationController implements OrganizationControllerInterface {

  /**
   * The internal entity cache.
   *
   * @var \Apigee\Edge\Api\Management\Entity\OrganizationInterface[]
   */
  private $cache = [];

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

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

  /**
   * OrganizationController constructor.
   *
   * @param \Drupal\apigee_edge\SDKConnectorInterface $connector
   *   The SDK connector service.
   */
  public function __construct(SDKConnectorInterface $connector) {
    $this->connector = $connector;
  }

  /**
   * Returns the decorated organization controller from the SDK.
   *
   * @return \Apigee\Edge\Api\Management\Controller\OrganizationControllerInterface
   *   The initialized organization controller.
   */
  private function decorated() : EdgeOrganizationControllerInterface {
    if ($this->instance === NULL) {
      $this->instance = new EdgeOrganizationController($this->connector
        ->getClient());
    }
    return $this->instance;
  }

  /**
   * {@inheritdoc}
   */
  public function create(EntityInterface $entity) : void {
    $this
      ->decorated()
      ->create($entity);
    $this->cache[$entity
      ->id()] = $entity;
  }

  /**
   * {@inheritdoc}
   */
  public function delete(string $entity_id) : EntityInterface {
    $entity = $this
      ->decorated()
      ->delete($entity_id);
    unset($this->cache[$entity_id]);
    return $entity;
  }

  /**
   * {@inheritdoc}
   */
  public function load(string $entity_id) : EntityInterface {
    if (!isset($this->cache[$entity_id])) {
      $this->cache[$entity_id] = $this
        ->decorated()
        ->load($entity_id);
    }
    return $this->cache[$entity_id];
  }

  /**
   * {@inheritdoc}
   */
  public function update(EntityInterface $entity) : void {
    $this
      ->decorated()
      ->update($entity);
    $this->cache[$entity
      ->id()] = $entity;
  }

  /**
   * {@inheritdoc}
   */
  public function getEntities() : array {
    $entities = $this
      ->decorated()
      ->getEntities();
    foreach ($entities as $id => $entity) {
      $this->cache[$id] = $entities;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OrganizationController::$cache private property The internal entity cache.
OrganizationController::$connector private property The SDK connector service.
OrganizationController::$instance private property Local cache for the decorated organization controller from the SDK.
OrganizationController::create public function
OrganizationController::decorated private function Returns the decorated organization controller from the SDK.
OrganizationController::delete public function
OrganizationController::getEntities public function
OrganizationController::load public function
OrganizationController::update public function
OrganizationController::__construct public function OrganizationController constructor.