trait CachedAttributesAwareEntityControllerTrait in Apigee Edge 8
Helper trait for those entity controllers that supports attribute CRUDL.
This trait ensures that the right entity cache method(s) gets called when a CRUD method is called.
Hierarchy
- trait \Drupal\apigee_edge\Entity\Controller\CachedAttributesAwareEntityControllerTrait uses EntityCacheAwareControllerTrait
See also
\Apigee\Edge\Api\Management\Controller\AttributesAwareEntityControllerInterface
1 file declares its use of CachedAttributesAwareEntityControllerTrait
- TeamController.php in modules/
apigee_edge_teams/ src/ Entity/ Controller/ TeamController.php
File
- src/
Entity/ Controller/ CachedAttributesAwareEntityControllerTrait.php, line 33
Namespace
Drupal\apigee_edge\Entity\ControllerView source
trait CachedAttributesAwareEntityControllerTrait {
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\Api\Management\Controller\AttributesAwareEntityControllerInterface
* An entity controller that extends this interface.
*/
protected abstract function decorated();
/**
* {@inheritdoc}
*/
public function getAttributes(string $entity_id) : AttributesProperty {
$entity = $this
->entityCache()
->getEntity($entity_id);
/** @var \Apigee\Edge\Entity\Property\AttributesPropertyInterface $entity */
if ($entity) {
return $entity
->getAttributes();
}
return $this
->decorated()
->getAttributes($entity_id);
}
/**
* {@inheritdoc}
*/
public function getAttribute(string $entity_id, string $name) : string {
$entity = $this
->entityCache()
->getEntity($entity_id);
/** @var \Apigee\Edge\Entity\Property\AttributesPropertyInterface $entity */
if ($entity) {
return $entity
->getAttributeValue($name);
}
return $this
->decorated()
->getAttribute($entity_id, $name);
}
/**
* {@inheritdoc}
*/
public function updateAttributes(string $entity_id, AttributesProperty $attributes) : AttributesProperty {
$attributes = $this
->decorated()
->updateAttributes($entity_id, $attributes);
// Enforce reload of entity from Apigee Edge.
$this
->entityCache()
->removeEntities([
$entity_id,
]);
$this
->entityCache()
->allEntitiesInCache(FALSE);
return $attributes;
}
/**
* {@inheritdoc}
*/
public function updateAttribute(string $entity_id, string $name, string $value) : string {
$value = $this
->decorated()
->updateAttribute($entity_id, $name, $value);
// Enforce reload of entity from Apigee Edge.
$this
->entityCache()
->removeEntities([
$entity_id,
]);
$this
->entityCache()
->allEntitiesInCache(FALSE);
return $value;
}
/**
* {@inheritdoc}
*/
public function deleteAttribute(string $entity_id, string $name) : void {
$this
->decorated()
->deleteAttribute($entity_id, $name);
// Enforce reload of entity from Apigee Edge.
$this
->entityCache()
->removeEntities([
$entity_id,
]);
$this
->entityCache()
->allEntitiesInCache(FALSE);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CachedAttributesAwareEntityControllerTrait:: |
abstract protected | function | The decorated entity controller from the SDK. | 1 |
CachedAttributesAwareEntityControllerTrait:: |
public | function | ||
CachedAttributesAwareEntityControllerTrait:: |
public | function | ||
CachedAttributesAwareEntityControllerTrait:: |
public | function | ||
CachedAttributesAwareEntityControllerTrait:: |
public | function | ||
CachedAttributesAwareEntityControllerTrait:: |
public | function | ||
EntityCacheAwareControllerTrait:: |
abstract public | function | Returns the entity cache used by the controller. | 4 |