You are here

class ConfigCollector in Configuration Provider 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/ConfigCollector.php \Drupal\config_provider\Plugin\ConfigCollector

Class for invoking configuration providers..

Hierarchy

Expanded class hierarchy of ConfigCollector

1 string reference to 'ConfigCollector'
config_provider.services.yml in ./config_provider.services.yml
config_provider.services.yml
1 service uses ConfigCollector
config_provider.collector in ./config_provider.services.yml
Drupal\config_provider\Plugin\ConfigCollector

File

src/Plugin/ConfigCollector.php, line 13

Namespace

Drupal\config_provider\Plugin
View source
class ConfigCollector implements ConfigCollectorInterface {

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The active configuration storage.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $activeStorage;

  /**
   * The configuration manager.
   *
   * @var \Drupal\Core\Config\ConfigManagerInterface
   */
  protected $configManager;

  /**
   * The provider configuration storage.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $providerStorage;

  /**
   * The configuration provider manager.
   *
   * @var \Drupal\config_provider\Plugin\ConfigProviderManager
   */
  protected $configProviderManager;

  /**
   * The configuration provider plugin instances.
   *
   * @var \Drupal\config_provider\Plugin\ConfigProvider
   */
  protected $configProviders;

  /**
   * Constructor for ConfigCollector objects.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   * @param \Drupal\Core\Config\StorageInterface $active_storage
   *   The active configuration storage.
   * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
   *   The configuration manager.
   * @param \Drupal\Core\Config\StorageInterface $provider_storage
   *   The provider configuration storage.
   * @param \Drupal\config_provider\Plugin\ConfigProviderManager $config_provider_manager
   *   The configuration provider manager.
   */
  public function __construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, ConfigManagerInterface $config_manager, StorageInterface $provider_storage, ConfigProviderManager $config_provider_manager) {
    $this->configFactory = $config_factory;
    $this->activeStorage = $active_storage;
    $this->configManager = $config_manager;
    $this->providerStorage = $provider_storage;
    $this->configProviderManager = $config_provider_manager;
    $this->configProviders = [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfigProviders() {
    if (empty($this->configProviders)) {
      $definitions = $this->configProviderManager
        ->getDefinitions();
      foreach (array_keys($definitions) as $id) {
        $this
          ->initConfigProviderInstance($id);
      }
    }
    return $this->configProviders;
  }

  /**
   * {@inheritdoc}
   */
  public function getInstallableConfig(array $extensions = []) {

    // Start with an empty storage.
    $this->providerStorage
      ->deleteAll();

    /* @var \Drupal\config_provider\Plugin\ConfigProviderInterface[] $providers */
    $providers = $this
      ->getConfigProviders();
    foreach ($providers as $provider) {
      $provider
        ->addInstallableConfig($this->providerStorage, $extensions);
    }
    return $this->providerStorage;
  }

  /**
   * Initializes an instance of the specified configuration provider.
   *
   * @param string $id
   *   The string identifier of the configuration provider.
   */
  protected function initConfigProviderInstance($id) {
    if (!isset($this->configProviders[$id])) {
      $instance = $this->configProviderManager
        ->createInstance($id, []);
      $instance
        ->setConfigFactory($this->configFactory);
      $instance
        ->setActiveStorages($this->activeStorage);
      $instance
        ->setConfigManager($this->configManager);
      $this->configProviders[$id] = $instance;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigCollector::$activeStorage protected property The active configuration storage.
ConfigCollector::$configFactory protected property The configuration factory.
ConfigCollector::$configManager protected property The configuration manager.
ConfigCollector::$configProviderManager protected property The configuration provider manager.
ConfigCollector::$configProviders protected property The configuration provider plugin instances.
ConfigCollector::$providerStorage protected property The provider configuration storage.
ConfigCollector::getConfigProviders public function Gets all configuration provider plugins. Overrides ConfigCollectorInterface::getConfigProviders
ConfigCollector::getInstallableConfig public function Gets installable configuration from all provider plugins. Overrides ConfigCollectorInterface::getInstallableConfig
ConfigCollector::initConfigProviderInstance protected function Initializes an instance of the specified configuration provider.
ConfigCollector::__construct public function Constructor for ConfigCollector objects.