You are here

final class DeveloperAppEdgeEntityControllerProxy in Apigee Edge 8

Developer app specific entity controller implementation.

It ensures that the right SDK controllers (and with that the right API endpoints) gets used for CRUDL operations.

Hierarchy

Expanded class hierarchy of DeveloperAppEdgeEntityControllerProxy

1 file declares its use of DeveloperAppEdgeEntityControllerProxy
DeveloperAppStorage.php in src/Entity/Storage/DeveloperAppStorage.php

File

src/Entity/Controller/DeveloperAppEdgeEntityControllerProxy.php, line 34

Namespace

Drupal\apigee_edge\Entity\Controller
View source
final class DeveloperAppEdgeEntityControllerProxy implements EdgeEntityControllerInterface {

  /**
   * The developer app controller factory service.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\DeveloperAppControllerFactoryInterface
   */
  private $devAppControllerFactory;

  /**
   * The app controller service.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\AppControllerInterface
   */
  private $appController;

  /**
   * DeveloperAppEntityControllerProxy constructor.
   *
   * @param \Drupal\apigee_edge\Entity\Controller\DeveloperAppControllerFactoryInterface $developer_app_controller_factory
   *   The developer app controller factory service.
   * @param \Drupal\apigee_edge\Entity\Controller\AppControllerInterface $app_controller
   *   The app controller service.
   */
  public function __construct(DeveloperAppControllerFactoryInterface $developer_app_controller_factory, AppControllerInterface $app_controller) {
    $this->devAppControllerFactory = $developer_app_controller_factory;
    $this->appController = $app_controller;
  }

  /**
   * {@inheritdoc}
   */
  public function create(EntityInterface $entity) : void {

    /** @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $entity */
    if (empty($entity
      ->getDeveloperId())) {

      // Sanity check.
      throw new RuntimeException('Developer id has to set on the app.');
    }
    $controller = $this->devAppControllerFactory
      ->developerAppController($entity
      ->getDeveloperId());
    $controller
      ->create($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function load(string $id) : EntityInterface {
    return $this->appController
      ->loadApp($id);
  }

  /**
   * {@inheritdoc}
   */
  public function update(EntityInterface $entity) : void {

    /** @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $entity */
    $controller = $this->devAppControllerFactory
      ->developerAppController($entity
      ->getDeveloperId());
    $controller
      ->update($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function delete(string $id) : void {

    // Try to be smart here and load the app from the developer app
    // entity cache (app controller's cache is probably empty unless there were
    // a load() or getEntities() call before).
    $entity = \Drupal::entityTypeManager()
      ->getStorage('developer_app')
      ->load($id);
    if (!$entity) {

      // Entity has not found in the entity cache, we have it from Apigee Edge.
      $entity = $this
        ->load($id);
    }

    /** @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $entity */
    $controller = $this->devAppControllerFactory
      ->developerAppController($entity
      ->getDeveloperId());

    // The id that we got is a UUID, what we need is an app name.
    $controller
      ->delete($entity
      ->getName());
  }

  /**
   * {@inheritdoc}
   */
  public function loadAll() : array {
    return array_filter($this->appController
      ->listApps(TRUE), function (AppInterface $app) {
      return $app instanceof DeveloperAppInterface;
    });
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeveloperAppEdgeEntityControllerProxy::$appController private property The app controller service.
DeveloperAppEdgeEntityControllerProxy::$devAppControllerFactory private property The developer app controller factory service.
DeveloperAppEdgeEntityControllerProxy::create public function Creates an entity in Apigee Edge. Overrides EdgeEntityControllerInterface::create
DeveloperAppEdgeEntityControllerProxy::delete public function Removes an entity from Apigee Edge. Overrides EdgeEntityControllerInterface::delete
DeveloperAppEdgeEntityControllerProxy::load public function Loads an entity from Apigee Edge. Overrides EdgeEntityControllerInterface::load
DeveloperAppEdgeEntityControllerProxy::loadAll public function Loads _all_ entities from Apigee Edge. Overrides EdgeEntityControllerInterface::loadAll
DeveloperAppEdgeEntityControllerProxy::update public function Updates an entity in Apigee Edge. Overrides EdgeEntityControllerInterface::update
DeveloperAppEdgeEntityControllerProxy::__construct public function DeveloperAppEntityControllerProxy constructor.