You are here

final class ExportStorageManager in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Config/ExportStorageManager.php \Drupal\Core\Config\ExportStorageManager
  2. 9 core/lib/Drupal/Core/Config/ExportStorageManager.php \Drupal\Core\Config\ExportStorageManager

The export storage manager dispatches an event for the export storage.

This class is not meant to be extended and is final to make sure the constructor and the getStorage method are both changed when this pattern is used in other circumstances.

Hierarchy

  • class \Drupal\Core\Config\ExportStorageManager implements \Drupal\Core\Config\StorageManagerInterface uses \Drupal\Core\Config\StorageCopyTrait

Expanded class hierarchy of ExportStorageManager

1 file declares its use of ExportStorageManager
ExportStorageManagerTest.php in core/tests/Drupal/KernelTests/Core/Config/ExportStorageManagerTest.php
1 string reference to 'ExportStorageManager'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ExportStorageManager
config.storage.export.manager in core/core.services.yml
Drupal\Core\Config\ExportStorageManager

File

core/lib/Drupal/Core/Config/ExportStorageManager.php, line 16

Namespace

Drupal\Core\Config
View source
final class ExportStorageManager implements StorageManagerInterface {
  use StorageCopyTrait;

  /**
   * The name used to identify the lock.
   */
  const LOCK_NAME = 'config_storage_export_manager';

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

  /**
   * The database storage.
   *
   * @var \Drupal\Core\Config\DatabaseStorage
   */
  protected $storage;

  /**
   * The event dispatcher.
   *
   * @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
   */
  protected $eventDispatcher;

  /**
   * The used lock backend instance.
   *
   * @var \Drupal\Core\Lock\LockBackendInterface
   */
  protected $lock;

  /**
   * ExportStorageManager constructor.
   *
   * @param \Drupal\Core\Config\StorageInterface $active
   *   The active config storage to prime the export storage.
   * @param \Drupal\Core\Database\Connection $connection
   *   The database connection.
   * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $event_dispatcher
   *   The event dispatcher.
   * @param \Drupal\Core\Lock\LockBackendInterface $lock
   *   The used lock backend instance.
   */
  public function __construct(StorageInterface $active, Connection $connection, EventDispatcherInterface $event_dispatcher, LockBackendInterface $lock) {
    $this->active = $active;
    $this->eventDispatcher = $event_dispatcher;
    $this->lock = $lock;

    // The point of this service is to provide the storage and dispatch the
    // event when needed, so the storage itself can not be a service.
    $this->storage = new DatabaseStorage($connection, 'config_export');
  }

  /**
   * {@inheritdoc}
   */
  public function getStorage() {

    // Acquire a lock for the request to assert that the storage does not change
    // when a concurrent request transforms the storage.
    if (!$this->lock
      ->acquire(self::LOCK_NAME)) {
      $this->lock
        ->wait(self::LOCK_NAME);
      if (!$this->lock
        ->acquire(self::LOCK_NAME)) {
        throw new StorageTransformerException("Cannot acquire config export transformer lock.");
      }
    }
    self::replaceStorageContents($this->active, $this->storage);
    $this->eventDispatcher
      ->dispatch(new StorageTransformEvent($this->storage), ConfigEvents::STORAGE_TRANSFORM_EXPORT);
    return new ReadOnlyStorage($this->storage);
  }

}

Members