You are here

class TagsHeadersService in Purge 8.3

Provides a service that provides access to available tags headers.

Hierarchy

Expanded class hierarchy of TagsHeadersService

1 string reference to 'TagsHeadersService'
purge.services.yml in ./purge.services.yml
purge.services.yml
1 service uses TagsHeadersService
purge.tagsheaders in ./purge.services.yml
Drupal\purge\Plugin\Purge\TagsHeader\TagsHeadersService

File

src/Plugin/Purge/TagsHeader/TagsHeadersService.php, line 13

Namespace

Drupal\purge\Plugin\Purge\TagsHeader
View source
class TagsHeadersService extends ServiceBase implements TagsHeadersServiceInterface {
  use ContainerAwareTrait;
  use IteratingServiceBaseTrait;

  /**
   * The purge executive service, which wipes content from external caches.
   *
   * Do not access this property directly, use ::getPurgers.
   *
   * @var \Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface
   */
  private $purgePurgers;

  /**
   * Construct the tags headers service.
   *
   * @param \Drupal\Component\Plugin\PluginManagerInterface $pluginManager
   *   The plugin manager for this service.
   */
  public function __construct(PluginManagerInterface $pluginManager) {
    $this->pluginManager = $pluginManager;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginsEnabled() {
    if (!is_null($this->pluginsEnabled)) {
      return $this->pluginsEnabled;
    }

    // We blindly load all tag header plugins that we discovered, but not
    // when plugins put dependencies on purger plugins. When plugins do depend,
    // we load 'purge.purgers' and verify if we should load them or not.
    $load = function ($needles, $haystack) {
      if (empty($needles)) {
        return TRUE;
      }
      foreach ($needles as $needle) {
        if (in_array($needle, $haystack)) {
          return TRUE;
        }
      }
      return FALSE;
    };
    $this->pluginsEnabled = [];
    foreach ($this
      ->getPlugins() as $plugin) {
      if (!empty($plugin['dependent_purger_plugins'])) {
        if (!$load($plugin['dependent_purger_plugins'], $this
          ->getPurgers()
          ->getPluginsEnabled())) {
          continue;
        }
      }
      $this->pluginsEnabled[] = $plugin['id'];
    }
    return $this->pluginsEnabled;
  }

  /**
   * Retrieve the 'purge.purgers' service - lazy loaded.
   *
   * @return \Drupal\purge\Plugin\Purge\Purger\PurgersServiceInterface
   *   The 'purge.purgers' service.
   */
  protected function getPurgers() {
    if (is_null($this->purgePurgers)) {
      $this->purgePurgers = $this->container
        ->get('purge.purgers');
    }
    return $this->purgePurgers;
  }

  /**
   * {@inheritdoc}
   *
   * @ingroup countable
   */
  public function count() {
    $this
      ->initializePluginInstances();
    return count($this->instances);
  }

  /**
   * {@inheritdoc}
   */
  public function reload() {
    parent::reload();
    $this
      ->reloadIterator();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IteratingServiceBaseTrait::$instances protected property Holds all instantiated plugins.
IteratingServiceBaseTrait::$position protected property Current iterator position.
IteratingServiceBaseTrait::current public function Return the current element.
IteratingServiceBaseTrait::initializePluginInstances protected function Instantiate all enabled plugins or check that they are present.
IteratingServiceBaseTrait::key public function Return the key of the current element.
IteratingServiceBaseTrait::next public function Move forward to next element. 1
IteratingServiceBaseTrait::reloadIterator protected function Rewind the iterator and destruct loaded plugin instances.
IteratingServiceBaseTrait::rewind public function Rewind the Iterator to the first element.
IteratingServiceBaseTrait::valid public function Checks if current position is valid.
ServiceBase::$pluginManager protected property The plugin manager for the given service.
ServiceBase::$plugins protected property The list of all available plugins and their definitions.
ServiceBase::$pluginsEnabled protected property The list of all enabled plugins and their definitions.
ServiceBase::getPlugins public function Retrieve a list of all available plugins providing the service. Overrides ServiceInterface::getPlugins 1
ServiceBase::isPluginEnabled public function Find out whether the given plugin_id is enabled. Overrides ServiceInterface::isPluginEnabled
ServiceProviderBase::alter public function Modifies existing service definitions. Overrides ServiceModifierInterface::alter 5
ServiceProviderBase::register public function Registers services to the container. Overrides ServiceProviderInterface::register 1
TagsHeadersService::$purgePurgers private property The purge executive service, which wipes content from external caches.
TagsHeadersService::count public function
TagsHeadersService::getPluginsEnabled public function Retrieve the configured plugin_ids that the service will use. Overrides ServiceBase::getPluginsEnabled
TagsHeadersService::getPurgers protected function Retrieve the 'purge.purgers' service - lazy loaded.
TagsHeadersService::reload public function Reload the service and reinstantiate all enabled plugins. Overrides ServiceBase::reload
TagsHeadersService::__construct public function Construct the tags headers service.