View source
<?php
namespace Drupal\apigee_edge\Entity\Controller;
use Apigee\Edge\Api\Management\Controller\AppCredentialController as EdgeAppCredentialController;
use Apigee\Edge\Api\Management\Entity\AppCredentialInterface;
use Apigee\Edge\Structure\AttributesProperty;
use Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerFactoryInterface;
use Drupal\apigee_edge\Event\AppCredentialAddApiProductEvent;
use Drupal\apigee_edge\Event\AppCredentialCreateEvent;
use Drupal\apigee_edge\Event\AppCredentialDeleteEvent;
use Drupal\apigee_edge\Event\AppCredentialGenerateEvent;
use Drupal\apigee_edge\Event\AppCredentialDeleteApiProductEvent;
use Drupal\apigee_edge\SDKConnectorInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
abstract class AppCredentialControllerBase implements AppCredentialControllerInterface {
protected $instances = [];
protected $owner;
protected $appName;
protected $connector;
protected $appCacheByOwner;
private $eventDispatcher;
public function __construct(string $owner, string $app_name, SDKConnectorInterface $connector, AppCacheByOwnerFactoryInterface $app_cache_by_owner_factory, EventDispatcherInterface $event_dispatcher) {
$this->owner = $owner;
$this->appName = $app_name;
$this->connector = $connector;
$this->appCacheByOwner = $app_cache_by_owner_factory
->getAppCache($owner);
$this->eventDispatcher = $event_dispatcher;
}
public function addProducts(string $consumer_key, array $api_products) : AppCredentialInterface {
$credential = $this
->decorated()
->addProducts($consumer_key, $api_products);
$this->eventDispatcher
->dispatch(AppCredentialAddApiProductEvent::EVENT_NAME, new AppCredentialAddApiProductEvent($this
->getAppType(), $this->owner, $this->appName, $credential, $api_products));
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $credential;
}
public function create(string $consumer_key, string $consumer_secret) : AppCredentialInterface {
$credential = $this
->decorated()
->create($consumer_key, $consumer_secret);
$this->eventDispatcher
->dispatch(AppCredentialCreateEvent::EVENT_NAME, new AppCredentialCreateEvent($this
->getAppType(), $this->owner, $this->appName, $credential));
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $credential;
}
protected abstract function decorated() : EdgeAppCredentialController;
public function delete(string $consumer_key) : AppCredentialInterface {
$credential = $this
->decorated()
->delete($consumer_key);
$this->eventDispatcher
->dispatch(AppCredentialDeleteEvent::EVENT_NAME, new AppCredentialDeleteEvent($this
->getAppType(), $this->owner, $this->appName, $credential));
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $credential;
}
public function deleteApiProduct(string $consumer_key, string $api_product) : AppCredentialInterface {
$credential = $this
->decorated()
->deleteApiProduct($consumer_key, $api_product);
$this->eventDispatcher
->dispatch(AppCredentialDeleteApiProductEvent::EVENT_NAME, new AppCredentialDeleteApiProductEvent($this
->getAppType(), $this->owner, $this->appName, $credential, $api_product));
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $credential;
}
public function deleteAttribute(string $entity_id, string $name) : void {
$this
->decorated()
->deleteAttribute($entity_id, $name);
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
}
public function generate(array $api_products, AttributesProperty $app_attributes, string $callback_url, array $scopes = [], string $key_expires_in = '-1') : AppCredentialInterface {
$credential = $this
->decorated()
->generate($api_products, $app_attributes, $callback_url, $scopes, $key_expires_in);
$this->eventDispatcher
->dispatch(AppCredentialGenerateEvent::EVENT_NAME, new AppCredentialGenerateEvent($this
->getAppType(), $this->owner, $this->appName, $credential));
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $credential;
}
public function getAttribute(string $entity_id, string $name) : string {
return $this
->decorated()
->getAttribute($entity_id, $name);
}
public function getAttributes(string $entity_id) : AttributesProperty {
return $this
->decorated()
->getAttributes($entity_id);
}
public function getOrganisationName() : string {
return $this
->decorated()
->getOrganisationName();
}
public function load(string $consumer_key) : AppCredentialInterface {
return $this
->decorated()
->load($consumer_key);
}
public function overrideScopes(string $consumer_key, array $scopes) : AppCredentialInterface {
$credential = $this
->decorated()
->overrideScopes($consumer_key, $scopes);
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $credential;
}
public function setApiProductStatus(string $consumer_key, string $api_product, string $status) : void {
$this
->decorated()
->setApiProductStatus($consumer_key, $api_product, $status);
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
}
public function setStatus(string $consumer_key, string $status) : void {
$this
->decorated()
->setStatus($consumer_key, $status);
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
}
public function updateAttribute(string $entity_id, string $name, string $value) : string {
$value = $this
->decorated()
->updateAttribute($entity_id, $name, $value);
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $value;
}
public function updateAttributes(string $entity_id, AttributesProperty $attributes) : AttributesProperty {
$attributes = $this
->decorated()
->updateAttributes($entity_id, $attributes);
$this->appCacheByOwner
->removeEntities([
$this->appName,
]);
return $attributes;
}
protected abstract function getAppType() : string;
}