You are here

final class DeveloperAppCacheFactory in Apigee Edge 8

Developer specific app cache by app owner factory service.

This service ensures that the same cache instance is being used for the same developer's developer apps even if the developer is sometimes referenced by its UUID and sometimes by its email address.

Hierarchy

Expanded class hierarchy of DeveloperAppCacheFactory

1 string reference to 'DeveloperAppCacheFactory'
apigee_edge.services.yml in ./apigee_edge.services.yml
apigee_edge.services.yml
1 service uses DeveloperAppCacheFactory
apigee_edge.entity.controller.cache.developer_app_cache_factory in ./apigee_edge.services.yml
Drupal\apigee_edge\Entity\Controller\Cache\DeveloperAppCacheFactory

File

src/Entity/Controller/Cache/DeveloperAppCacheFactory.php, line 34

Namespace

Drupal\apigee_edge\Entity\Controller\Cache
View source
final class DeveloperAppCacheFactory implements AppCacheByOwnerFactoryInterface {

  /**
   * The (general) app cache by owner factory.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerFactoryInterface
   */
  private $appCacheByOwnerFactory;

  /**
   * The email validator service.
   *
   * @var \Drupal\Component\Utility\EmailValidatorInterface
   */
  private $emailValidator;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  private $entityTypeManager;

  /**
   * DeveloperAppCacheFactory constructor.
   *
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerFactoryInterface $app_cache_by_owner_factory
   *   The (general) app cache by owner factory.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Component\Utility\EmailValidatorInterface $email_validator
   *   The email validator service.
   */
  public function __construct(AppCacheByOwnerFactoryInterface $app_cache_by_owner_factory, EntityTypeManagerInterface $entity_type_manager, EmailValidatorInterface $email_validator) {
    $this->appCacheByOwnerFactory = $app_cache_by_owner_factory;
    $this->emailValidator = $email_validator;
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * Returns the same app cache instance for a developer.
   *
   * Even if the owner is sometime a UUID and sometime an email address.
   *
   * @param string $owner
   *   Developer id (UUID) or email.
   *
   * @return \Drupal\apigee_edge\Entity\Controller\Cache\AppCacheByOwnerInterface
   *   The developer app cache that belongs to this owner.
   */
  public function getAppCache(string $owner) : AppCacheByOwnerInterface {
    if ($this->emailValidator
      ->isValid($owner)) {

      /** @var \Drupal\apigee_edge\Entity\Developer|null $developer */
      $developer = $this->entityTypeManager
        ->getStorage('developer')
        ->load($owner);
      if ($developer === NULL) {
        throw new DeveloperDoesNotExistException($owner);
      }
      $owner = $developer
        ->getDeveloperId();
    }
    return $this->appCacheByOwnerFactory
      ->getAppCache($owner);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeveloperAppCacheFactory::$appCacheByOwnerFactory private property The (general) app cache by owner factory.
DeveloperAppCacheFactory::$emailValidator private property The email validator service.
DeveloperAppCacheFactory::$entityTypeManager private property The entity type manager.
DeveloperAppCacheFactory::getAppCache public function Returns the same app cache instance for a developer. Overrides AppCacheByOwnerFactoryInterface::getAppCache
DeveloperAppCacheFactory::__construct public function DeveloperAppCacheFactory constructor.