You are here

trait CachedPaginatedEntityListingControllerTrait in Apigee Edge 8

For those controllers that supports paginated entity listing.

Hierarchy

See also

\Apigee\Edge\Controller\PaginatedEntityListingControllerInterface

1 file declares its use of CachedPaginatedEntityListingControllerTrait
TeamController.php in modules/apigee_edge_teams/src/Entity/Controller/TeamController.php

File

src/Entity/Controller/CachedPaginatedEntityListingControllerTrait.php, line 30

Namespace

Drupal\apigee_edge\Entity\Controller
View source
trait CachedPaginatedEntityListingControllerTrait {
  use EntityCacheAwareControllerTrait;

  /**
   * The decorated entity controller from the SDK.
   *
   * We did not added a return type because this way all entity controller's
   * decorated() method becomes compatible with this declaration.
   *
   * @return \Apigee\Edge\Controller\PaginatedEntityListingControllerInterface
   *   An entity controller that extends these interfaces.
   */
  protected abstract function decorated();

  /**
   * {@inheritdoc}
   */
  public function getEntities(PagerInterface $pager = NULL, string $key_provider = 'id') : array {
    if ($this
      ->entityCache()
      ->isAllEntitiesInCache()) {
      if ($pager === NULL) {
        return $this
          ->entityCache()
          ->getEntities();
      }
      else {
        return $this
          ->extractSubsetOfAssociativeArray($this
          ->entityCache()
          ->getEntities(), $pager
          ->getLimit(), $pager
          ->getStartKey());
      }
    }
    $entities = $this
      ->decorated()
      ->getEntities($pager, $key_provider);
    $this
      ->entityCache()
      ->saveEntities($entities);
    if ($pager === NULL) {
      $this
        ->entityCache()
        ->allEntitiesInCache(TRUE);
    }
    return $entities;
  }

  /**
   * {@inheritdoc}
   */
  protected abstract function extractSubsetOfAssociativeArray(array $assoc_array, int $limit, ?string $start_key = NULL) : array;

}

Members

Namesort descending Modifiers Type Description Overrides
CachedPaginatedEntityListingControllerTrait::decorated abstract protected function The decorated entity controller from the SDK.
CachedPaginatedEntityListingControllerTrait::extractSubsetOfAssociativeArray abstract protected function
CachedPaginatedEntityListingControllerTrait::getEntities public function
EntityCacheAwareControllerTrait::entityCache abstract public function Returns the entity cache used by the controller. 4