PluginManagerCacheClearer.php

Same filename and directory in other branches
  1. 9 core/modules/system/tests/modules/module_test/src/PluginManagerCacheClearer.php
  2. 11.x core/modules/system/tests/modules/module_test/src/PluginManagerCacheClearer.php

Namespace

Drupal\module_test

File

core/modules/system/tests/modules/module_test/src/PluginManagerCacheClearer.php

View source
<?php

namespace Drupal\module_test;

use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\State\StateInterface;

/**
 * Helps test module uninstall.
 */
class PluginManagerCacheClearer extends DefaultPluginManager {
  
  /**
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;
  
  /**
   * An optional service dependency.
   *
   * @var object|null
   */
  protected $optionalService;
  
  /**
   * PluginManagerCacheClearer constructor.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service for recording what happens.
   * @param null $optional_service
   *   An optional service for testing.
   */
  public function __construct(StateInterface $state, $optional_service = NULL) {
    $this->state = $state;
    $this->optionalService = $optional_service;
  }
  
  /**
   * Tests call to CachedDiscoveryInterface::clearCachedDefinitions().
   *
   * @see \Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface::clearCachedDefinitions()
   */
  public function clearCachedDefinitions() {
    $this->state
      ->set(self::class, isset($this->optionalService));
  }

}

Classes

Title Deprecated Summary
PluginManagerCacheClearer Helps test module uninstall.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.