You are here

protected function ConfigSplitManager::getSplitStorage in Configuration Split 2.0.x

Get the split storage.

Parameters

\Drupal\Core\Config\ImmutableConfig $config: The split config.

\Drupal\Core\Config\StorageInterface|null $transforming: The transforming storage.

Return value

\Drupal\Core\Config\StorageInterface|null The split storage.

6 calls to ConfigSplitManager::getSplitStorage()
ConfigSplitManager::commitAll in src/ConfigSplitManager.php
Make the split permanent by copying the preview to the split storage.
ConfigSplitManager::importTransform in src/ConfigSplitManager.php
Process the import of a split.
ConfigSplitManager::singleActivate in src/ConfigSplitManager.php
Import the config of a single split.
ConfigSplitManager::singleDeactivate in src/ConfigSplitManager.php
Deactivate a split.
ConfigSplitManager::singleExportTarget in src/ConfigSplitManager.php
Get the single export target.

... See full list

File

src/ConfigSplitManager.php, line 465

Class

ConfigSplitManager
The manager to split and merge.

Namespace

Drupal\config_split

Code

protected function getSplitStorage(ImmutableConfig $config, StorageInterface $transforming = NULL) : ?StorageInterface {
  $storage = $config
    ->get('storage');
  if ('collection' === $storage) {
    if ($transforming instanceof StorageInterface) {
      return new SplitCollectionStorage($transforming, $config
        ->get('id'));
    }
    return NULL;
  }
  if ('folder' === $storage) {

    // Here we could determine to use relative paths etc.
    $directory = $config
      ->get('folder');
    if (!is_dir($directory)) {

      // If the directory doesn't exist, attempt to create it.
      // This might have some negative consequences, but we trust the user to
      // have properly configured their site.

      /* @noinspection MkdirRaceConditionInspection */
      @mkdir($directory, 0777, TRUE);
    }

    // The following is roughly: file_save_htaccess($directory, TRUE, TRUE);
    // But we can't use global drupal functions, and we want to write the
    // .htaccess file to ensure the configuration is protected and the
    // directory not empty.
    if (file_exists($directory) && is_writable($directory)) {
      $htaccess_path = rtrim($directory, '/\\') . '/.htaccess';
      if (!file_exists($htaccess_path)) {
        file_put_contents($htaccess_path, FileSecurity::htaccessLines(TRUE));
        @chmod($htaccess_path, 0444);
      }
    }
    if (file_exists($directory) || strpos($directory, 'vfs://') === 0) {

      // Allow virtual file systems even if file_exists is false.
      return new FileStorage($directory);
    }
    return NULL;
  }

  // When the folder is not set use a database.
  return new DatabaseStorage($this->connection, $this->connection
    ->escapeTable(strtr($config
    ->getName(), [
    '.' => '_',
  ])));
}