class PluginManager in Backup and Migrate 5.0.x
@package Drupal\backup_migrate\Core\Plugin
Hierarchy
- class \Drupal\backup_migrate\Core\Plugin\PluginManager implements ConfigurableInterface, PluginManagerInterface uses ConfigurableTrait
Expanded class hierarchy of PluginManager
2 files declare their use of PluginManager
- BackupMigrate.php in src/
Core/ Main/ BackupMigrate.php - DBExcludeFilter.php in src/
Core/ Filter/ DBExcludeFilter.php
1 string reference to 'PluginManager'
- BackupMigrate::__construct in src/
Core/ Main/ BackupMigrate.php - Backup and Migrate constructor.
File
- src/
Core/ Plugin/ PluginManager.php, line 17
Namespace
Drupal\backup_migrate\Core\PluginView source
class PluginManager implements PluginManagerInterface, ConfigurableInterface {
use ConfigurableTrait;
/**
* @var \Drupal\backup_migrate\Core\Plugin\PluginInterface[]
*/
protected $items;
/**
* @var \Drupal\backup_migrate\Core\Service\ServiceManagerInterface
*/
protected $services;
/**
* @var \Drupal\backup_migrate\Core\File\TempFileManagerInterface
*/
protected $tempFileManager;
/**
* @param \Drupal\backup_migrate\Core\Service\ServiceManagerInterface $services
* @param \Drupal\backup_migrate\Core\Config\ConfigInterface $config
*/
public function __construct(ServiceManagerInterface $services = NULL, ConfigInterface $config = NULL) {
// Add the injected service locator for dependency injection into plugins.
$this
->setServiceManager($services ? $services : new ServiceManager());
// Set the configuration or a null object if no config was specified.
$this
->setConfig($config ? $config : new Config());
// Create an array to store the plugins themselves.
$this->items = [];
}
/**
* Set the configuration. Reconfigure all of the installed plugins.
*
* @param \Drupal\backup_migrate\Core\Config\ConfigInterface $config
*/
public function setConfig(ConfigInterface $config) {
// Set the configuration object to the one passed in.
$this->config = $config;
// Pass the appropriate configuration to each of the installed plugins.
foreach ($this
->getAll() as $key => $plugin) {
$this
->configurePlugin($plugin, $key);
}
}
/**
* {@inheritdoc}
*/
public function add($id, PluginInterface $item) {
$this
->preparePlugin($item, $id);
$this->items[$id] = $item;
}
/**
* {@inheritdoc}
*/
public function get($id) {
return isset($this->items[$id]) ? $this->items[$id] : NULL;
}
/**
* {@inheritdoc}
*/
public function getAll() {
return empty($this->items) ? [] : $this->items;
}
/**
* Get all plugins that implement the given operation.
*
* @param string $op
* The name of the operation.
*
* @return \Drupal\backup_migrate\Core\Plugin\PluginInterface[]
*/
public function getAllByOp($op) {
$out = [];
$weights = [];
foreach ($this
->getAll() as $key => $plugin) {
if ($plugin
->supportsOp($op)) {
$out[$key] = $plugin;
$weights[$key] = $plugin
->opWeight($op);
}
}
array_multisort($weights, $out);
return $out;
}
/**
* {@inheritdoc}
*/
public function call($op, $operand = NULL, array $params = []) {
// Run each of the installed plugins which implements the given operation.
foreach ($this
->getAllByOp($op) as $plugin) {
$operand = $plugin
->{$op}($operand, $params);
}
return $operand;
}
/**
* {@inheritdoc}
*/
public function map($op, array $params = []) {
$out = [];
// Run each of the installed plugins which implements the given operation.
foreach ($this
->getAllByOp($op) as $key => $plugin) {
$out[$key] = $plugin
->{$op}($params);
}
return $out;
}
/**
* Prepare the plugin for use.
*
* This is called when a plugin is added to the manager and it configures the
* plugin according to the config object injected into the manager. It also
* injects other dependencies as needed.
*
* @param \Drupal\backup_migrate\Core\Plugin\PluginInterface $plugin
* The plugin to prepare for use.
* @param string $id
* The id of the plugin (to extract the correct settings).
*/
protected function preparePlugin(PluginInterface $plugin, $id) {
// If this plugin can be configured, then pass in the configuration.
$this
->configurePlugin($plugin, $id);
// Inject the available services.
$this
->services()
->addClient($plugin);
}
/**
* Set the configuration for the given plugin.
*
* @param $plugin
* @param $id
*/
protected function configurePlugin(PluginInterface $plugin, $id) {
// If this plugin can be configured, then pass in the configuration.
if ($plugin instanceof ConfigurableInterface) {
// Configure the plugin with the appropriate subset of the configuration.
$config = (array) $this
->confGet($id);
// Set the config for the plugin.
$plugin
->setConfig(new Config($config));
// Get the configuration back from the plugin to populate defaults within
// the manager.
$this
->config()
->set($id, $plugin
->config());
}
}
/**
* @return \Drupal\backup_migrate\Core\Service\ServiceManagerInterface
*/
public function services() {
return $this->services;
}
/**
* @param \Drupal\backup_migrate\Core\Service\ServiceManagerInterface $services
*/
public function setServiceManager(ServiceManagerInterface $services) {
$this->services = $services;
// Inject or re-inject the services.
foreach ($this
->getAll() as $key => $plugin) {
$this
->services()
->addClient($plugin);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableTrait:: |
protected | property | The object's configuration object. | |
ConfigurableTrait:: |
protected | property | The initial configuration. | |
ConfigurableTrait:: |
public | function | Get a specific value from the configuration. | |
ConfigurableTrait:: |
public | function | Get the configuration object for this item. | |
ConfigurableTrait:: |
public | function | Get the default values for the plugin. | 10 |
ConfigurableTrait:: |
public | function | Get any validation errors in the config. | |
ConfigurableTrait:: |
public | function | Get a default (blank) schema. | 10 |
PluginManager:: |
protected | property | ||
PluginManager:: |
protected | property | ||
PluginManager:: |
protected | property | ||
PluginManager:: |
public | function |
Add an item to the manager. Overrides PluginManagerInterface:: |
|
PluginManager:: |
public | function |
Call all plugins which support the given operation. Overrides PluginManagerInterface:: |
|
PluginManager:: |
protected | function | Set the configuration for the given plugin. | |
PluginManager:: |
public | function |
Get the item with the given id. Overrides PluginManagerInterface:: |
|
PluginManager:: |
public | function |
Get a list of all of the items. Overrides PluginManagerInterface:: |
|
PluginManager:: |
public | function |
Get all plugins that implement the given operation. Overrides PluginManagerInterface:: |
|
PluginManager:: |
public | function |
Call all plugins which support the given operation. Overrides PluginManagerInterface:: |
|
PluginManager:: |
protected | function | Prepare the plugin for use. | |
PluginManager:: |
public | function | ||
PluginManager:: |
public | function |
Set the configuration. Reconfigure all of the installed plugins. Overrides ConfigurableTrait:: |
|
PluginManager:: |
public | function | ||
PluginManager:: |
public | function |
Overrides ConfigurableTrait:: |
|
TranslatableTrait:: |
protected | property | ||
TranslatableTrait:: |
public | function | ||
TranslatableTrait:: |
public | function | Translate the given string if there is a translator service available. |