You are here

class CheckedEntityCache in Permissions by Term 8

Same name and namespace in other branches
  1. 8.2 modules/permissions_by_entity/src/Service/CheckedEntityCache.php \Drupal\permissions_by_entity\Service\CheckedEntityCache

Class CheckedEntityCache.

@package Drupal\permissions_by_entity\Service

Hierarchy

Expanded class hierarchy of CheckedEntityCache

1 file declares its use of CheckedEntityCache
PermissionsByEntityKernelEventSubscriber.php in modules/permissions_by_entity/src/EventSubscriber/PermissionsByEntityKernelEventSubscriber.php
1 string reference to 'CheckedEntityCache'
permissions_by_entity.services.yml in modules/permissions_by_entity/permissions_by_entity.services.yml
modules/permissions_by_entity/permissions_by_entity.services.yml
1 service uses CheckedEntityCache
permissions_by_entity.checked_entity_cache in modules/permissions_by_entity/permissions_by_entity.services.yml
Drupal\permissions_by_entity\Service\CheckedEntityCache

File

modules/permissions_by_entity/src/Service/CheckedEntityCache.php, line 12

Namespace

Drupal\permissions_by_entity\Service
View source
class CheckedEntityCache {

  /**
   * The checked entities.
   *
   * @var \Drupal\Core\Entity\FieldableEntityInterface[]
   */
  private $entities = [];

  /**
   * Returns if an entity has already been checked.
   *
   * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
   *   A fieldable entity.
   *
   * @return bool
   *   Returns TRUE if the entity has already been checked, otherwise FALSE.
   */
  public function isChecked(FieldableEntityInterface $entity) {
    return in_array($entity, $this->entities, TRUE);
  }

  /**
   * Adds a fieldable entity to the cache.
   *
   * If the entity has already been added to the cache, nothing will be done.
   *
   * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
   *   A fieldable entity.
   */
  public function add(FieldableEntityInterface $entity) {

    // In order to avoid duplicate entries we check if the entity is already in
    // the list of entities.
    if (!$this
      ->isChecked($entity)) {
      $this->entities[] = $entity;
    }
  }

  /**
   * Clears the cache.
   *
   * All cached fieldable entities will be removed irretrievably from the cache.
   */
  public function clear() {
    $this->entities = [];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CheckedEntityCache::$entities private property The checked entities.
CheckedEntityCache::add public function Adds a fieldable entity to the cache.
CheckedEntityCache::clear public function Clears the cache.
CheckedEntityCache::isChecked public function Returns if an entity has already been checked.