You are here

trait CachedEntityCrudOperationsControllerTrait in Apigee Edge 8

Helper trait for those entity controllers that supports all CRUD operations.

This trait ensures that the right entity cache method(s) gets called when a CRUD method is called.

Hierarchy

See also

\Apigee\Edge\Controller\EntityCrudOperationsControllerInterface

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

File

src/Entity/Controller/CachedEntityCrudOperationsControllerTrait.php, line 33

Namespace

Drupal\apigee_edge\Entity\Controller
View source
trait CachedEntityCrudOperationsControllerTrait {
  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\EntityCrudOperationsControllerInterface
   *   An entity controller that extends this interface.
   */
  protected abstract function decorated();

  /**
   * {@inheritdoc}
   */
  public function create(EntityInterface $entity) : void {
    $this
      ->decorated()
      ->create($entity);
    $this
      ->entityCache()
      ->saveEntities([
      $entity,
    ]);
  }

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

  /**
   * {@inheritdoc}
   */
  public function load(string $entity_id) : EntityInterface {
    $entity = $this
      ->entityCache()
      ->getEntity($entity_id);
    if ($entity === NULL) {
      $entity = $this
        ->decorated()
        ->load($entity_id);
      $this
        ->entityCache()
        ->saveEntities([
        $entity,
      ]);
    }
    return $entity;
  }

  /**
   * {@inheritdoc}
   */
  public function update(EntityInterface $entity) : void {
    $this
      ->decorated()
      ->update($entity);
    $this
      ->entityCache()
      ->saveEntities([
      $entity,
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CachedEntityCrudOperationsControllerTrait::create public function
CachedEntityCrudOperationsControllerTrait::decorated abstract protected function The decorated entity controller from the SDK. 3
CachedEntityCrudOperationsControllerTrait::delete public function
CachedEntityCrudOperationsControllerTrait::load public function 1
CachedEntityCrudOperationsControllerTrait::update public function
EntityCacheAwareControllerTrait::entityCache abstract public function Returns the entity cache used by the controller. 4