config_preview_deploy-1.0.0-alpha3/src/ProductionConfigImporter.php
src/ProductionConfigImporter.php
<?php
declare(strict_types=1);
namespace Drupal\config_preview_deploy;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ModuleInstallerInterface;
use Drupal\Core\Extension\ThemeExtensionList;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Creates and manages ConfigImporter instances on production.
*/
class ProductionConfigImporter {
/**
* The event dispatcher.
*/
protected EventDispatcherInterface $eventDispatcher;
/**
* The configuration manager.
*/
protected ConfigManagerInterface $configManager;
/**
* The lock backend.
*/
protected LockBackendInterface $lock;
/**
* The typed configuration manager.
*/
protected TypedConfigManagerInterface $typedConfigManager;
/**
* The module handler.
*/
protected ModuleHandlerInterface $moduleHandler;
/**
* The module installer.
*/
protected ModuleInstallerInterface $moduleInstaller;
/**
* The theme handler.
*/
protected ThemeHandlerInterface $themeHandler;
/**
* The string translation service.
*/
protected TranslationInterface $stringTranslation;
/**
* The module extension list.
*/
protected ModuleExtensionList $moduleExtensionList;
/**
* The theme extension list.
*/
protected ThemeExtensionList $themeExtensionList;
/**
* Constructs a ProductionConfigImporterService object.
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
ConfigManagerInterface $configManager,
LockBackendInterface $lock,
TypedConfigManagerInterface $typedConfigManager,
ModuleHandlerInterface $moduleHandler,
ModuleInstallerInterface $moduleInstaller,
ThemeHandlerInterface $themeHandler,
TranslationInterface $stringTranslation,
ModuleExtensionList $moduleExtensionList,
ThemeExtensionList $themeExtensionList,
) {
$this->eventDispatcher = $eventDispatcher;
$this->configManager = $configManager;
$this->lock = $lock;
$this->typedConfigManager = $typedConfigManager;
$this->moduleHandler = $moduleHandler;
$this->moduleInstaller = $moduleInstaller;
$this->themeHandler = $themeHandler;
$this->stringTranslation = $stringTranslation;
$this->moduleExtensionList = $moduleExtensionList;
$this->themeExtensionList = $themeExtensionList;
}
/**
* Creates a ConfigImporter for the given storage.
*
* @param \Drupal\Core\Config\StorageInterface $sourceStorage
* The source storage (contains new configurations).
* @param \Drupal\Core\Config\StorageInterface $targetStorage
* The target storage (current active storage).
*
* @return \Drupal\Core\Config\ConfigImporter
* The ConfigImporter instance.
*/
public function createImporter(StorageInterface $sourceStorage, StorageInterface $targetStorage): ConfigImporter {
$storageComparer = new StorageComparer(
$sourceStorage,
$targetStorage
);
$storageComparer->createChangelist();
return new ConfigImporter(
$storageComparer,
$this->eventDispatcher,
$this->configManager,
$this->lock,
$this->typedConfigManager,
$this->moduleHandler,
$this->moduleInstaller,
$this->themeHandler,
$this->stringTranslation,
$this->moduleExtensionList,
$this->themeExtensionList
);
}
}
