You are here

final class DeveloperAppNameCacheFactory in Apigee Edge 8

Developer specific app name 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 DeveloperAppNameCacheFactory

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

File

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

Namespace

Drupal\apigee_edge\Entity\Controller\Cache
View source
final class DeveloperAppNameCacheFactory implements AppNameCacheByOwnerFactoryInterface {

  /**
   * The (general) app name cache by owner factory service.
   *
   * @var \Drupal\apigee_edge\Entity\Controller\Cache\AppNameCacheByOwnerFactoryInterface
   */
  private $appNameCacheByOwnerFactory;

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

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

  /**
   * DeveloperAppNameCacheFactory constructor.
   *
   * @param \Drupal\apigee_edge\Entity\Controller\Cache\AppNameCacheByOwnerFactoryInterface $app_name_cache_by_owner_factory
   *   The (general) app name cache by app owner factory service.
   * @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(AppNameCacheByOwnerFactoryInterface $app_name_cache_by_owner_factory, EntityTypeManagerInterface $entity_type_manager, EmailValidatorInterface $email_validator) {
    $this->appNameCacheByOwnerFactory = $app_name_cache_by_owner_factory;
    $this->entityTypeManager = $entity_type_manager;
    $this->emailValidator = $email_validator;
  }

  /**
   * {@inheritdoc}
   */
  public function getAppNameCache(string $owner) : EntityIdCacheInterface {
    if ($this->emailValidator
      ->isValid($owner)) {

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

}

Members

Namesort descending Modifiers Type Description Overrides
DeveloperAppNameCacheFactory::$appNameCacheByOwnerFactory private property The (general) app name cache by owner factory service.
DeveloperAppNameCacheFactory::$emailValidator private property The email validator service.
DeveloperAppNameCacheFactory::$entityTypeManager private property The entity type manager.
DeveloperAppNameCacheFactory::getAppNameCache public function Returns the same app name cache instance for an owner. Overrides AppNameCacheByOwnerFactoryInterface::getAppNameCache
DeveloperAppNameCacheFactory::__construct public function DeveloperAppNameCacheFactory constructor.