class QueuersService in Purge 8.3
Provides a service that provides access to loaded queuers.
Hierarchy
- class \Drupal\Core\DependencyInjection\ServiceProviderBase implements ServiceModifierInterface, ServiceProviderInterface
- class \Drupal\purge\ServiceBase implements ServiceInterface
- class \Drupal\purge\Plugin\Purge\Queuer\QueuersService implements QueuersServiceInterface uses IteratingServiceBaseTrait, ModifiableServiceBaseTrait
- class \Drupal\purge\ServiceBase implements ServiceInterface
Expanded class hierarchy of QueuersService
1 string reference to 'QueuersService'
1 service uses QueuersService
File
- src/
Plugin/ Purge/ Queuer/ QueuersService.php, line 14
Namespace
Drupal\purge\Plugin\Purge\QueuerView source
class QueuersService extends ServiceBase implements QueuersServiceInterface {
use IteratingServiceBaseTrait;
use ModifiableServiceBaseTrait;
/**
* The factory for configuration objects.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Construct the queuers service.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $pluginManager
* The plugin manager for this service.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
*/
public function __construct(PluginManagerInterface $pluginManager, ConfigFactoryInterface $config_factory) {
$this->pluginManager = $pluginManager;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*
* @ingroup countable
*/
public function count() {
$this
->initializePluginInstances();
return count($this->instances);
}
/**
* {@inheritdoc}
*/
public function get($plugin_id) {
$this
->initializePluginInstances();
foreach ($this as $queuer) {
if ($queuer
->getPluginId() === $plugin_id) {
return $queuer;
}
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getPluginsEnabled() {
if (is_null($this->pluginsEnabled)) {
// Build a mapping of all plugins and whether they are enabled by default.
$this->pluginsEnabled = [];
foreach ($this
->getPlugins() as $plugin_id => $definition) {
$enable_by_default = $definition['enable_by_default'] === TRUE;
$this->pluginsEnabled[$plugin_id] = $enable_by_default;
}
// Override the mapping with information stored in CMI, then filter out
// everything that isn't enabled and finally flip the array with just ids.
$queuers = $this->configFactory
->get('purge.plugins')
->get('queuers');
if (!is_null($queuers)) {
foreach ($queuers as $inst) {
if (isset($this->pluginsEnabled[$inst['plugin_id']])) {
$this->pluginsEnabled[$inst['plugin_id']] = $inst['status'];
}
}
}
foreach ($this->pluginsEnabled as $plugin_id => $status) {
if (!$status) {
unset($this->pluginsEnabled[$plugin_id]);
}
}
$this->pluginsEnabled = array_keys($this->pluginsEnabled);
}
return $this->pluginsEnabled;
}
/**
* {@inheritdoc}
*/
public function reload() {
parent::reload();
// Without this, the tests will throw "failed to instantiate user-supplied
// statement class: CREATE TABLE {cache_config}".
// phpcs:ignore DrupalPractice.Objects.GlobalDrupal.GlobalDrupal
$this->configFactory = \Drupal::configFactory();
// Drush commands appreciate it when the config cache gets cleared.
if (php_sapi_name() === 'cli') {
// phpcs:ignore DrupalPractice.Objects.GlobalDrupal.GlobalDrupal
\Drupal::cache('config')
->deleteAll();
}
$this
->reloadIterator();
}
/**
* {@inheritdoc}
*/
public function setPluginsEnabled(array $plugin_ids) {
$definitions = $this->pluginManager
->getDefinitions();
// Gather all plugins mentioned in CMI and those available right now, set
// them disabled first. Then flip the switch for given plugin_ids.
$setting_assoc = [];
$instances = $this->configFactory
->get('purge.plugins')
->get('queuers');
if (!is_null($instances)) {
foreach ($instances as $inst) {
$setting_assoc[$inst['plugin_id']] = FALSE;
}
}
foreach ($definitions as $definition) {
$setting_assoc[$definition['id']] = FALSE;
}
foreach ($plugin_ids as $plugin_id) {
if (!isset($definitions[$plugin_id])) {
throw new \LogicException('Invalid plugin_id.');
}
$setting_assoc[$plugin_id] = TRUE;
}
// Convert the array to the CMI storage format and commit.
$setting = [];
foreach ($setting_assoc as $plugin_id => $status) {
$setting[] = [
'plugin_id' => $plugin_id,
'status' => $status,
];
}
$this->configFactory
->getEditable('purge.plugins')
->set('queuers', $setting)
->save();
$this
->reload();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
IteratingServiceBaseTrait:: |
protected | property | Holds all instantiated plugins. | |
IteratingServiceBaseTrait:: |
protected | property | Current iterator position. | |
IteratingServiceBaseTrait:: |
public | function | Return the current element. | |
IteratingServiceBaseTrait:: |
protected | function | Instantiate all enabled plugins or check that they are present. | |
IteratingServiceBaseTrait:: |
public | function | Return the key of the current element. | |
IteratingServiceBaseTrait:: |
public | function | Move forward to next element. | 1 |
IteratingServiceBaseTrait:: |
protected | function | Rewind the iterator and destruct loaded plugin instances. | |
IteratingServiceBaseTrait:: |
public | function | Rewind the Iterator to the first element. | |
IteratingServiceBaseTrait:: |
public | function | Checks if current position is valid. | |
ModifiableServiceBaseTrait:: |
public | function | Retrieve the plugin IDs of plugins that can be enabled. | |
QueuersService:: |
protected | property | The factory for configuration objects. | |
QueuersService:: |
public | function | ||
QueuersService:: |
public | function |
Get the requested queuer instance. Overrides QueuersServiceInterface:: |
|
QueuersService:: |
public | function |
Retrieve the configured plugin_ids that the service will use. Overrides ServiceBase:: |
|
QueuersService:: |
public | function |
Reload the service and reinstantiate all enabled plugins. Overrides ServiceBase:: |
|
QueuersService:: |
public | function |
Set the plugins used by the service and reload it. Overrides ModifiableServiceInterface:: |
|
QueuersService:: |
public | function | Construct the queuers service. | |
ServiceBase:: |
protected | property | The plugin manager for the given service. | |
ServiceBase:: |
protected | property | The list of all available plugins and their definitions. | |
ServiceBase:: |
protected | property | The list of all enabled plugins and their definitions. | |
ServiceBase:: |
public | function |
Retrieve a list of all available plugins providing the service. Overrides ServiceInterface:: |
1 |
ServiceBase:: |
public | function |
Find out whether the given plugin_id is enabled. Overrides ServiceInterface:: |
|
ServiceProviderBase:: |
public | function |
Modifies existing service definitions. Overrides ServiceModifierInterface:: |
5 |
ServiceProviderBase:: |
public | function |
Registers services to the container. Overrides ServiceProviderInterface:: |
1 |