FileStorageFactory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Drupal\Core\Config;
  3. use Drupal\Core\Site\Settings;
  4. /**
  5. * Provides a factory for creating config file storage objects.
  6. */
  7. class FileStorageFactory {
  8. /**
  9. * Returns a FileStorage object working with the active config directory.
  10. *
  11. * @return \Drupal\Core\Config\FileStorage FileStorage
  12. *
  13. * @deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Drupal core
  14. * no longer creates an active directory.
  15. */
  16. public static function getActive() {
  17. return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY));
  18. }
  19. /**
  20. * Returns a FileStorage object working with the sync config directory.
  21. *
  22. * @return \Drupal\Core\Config\FileStorage FileStorage
  23. *
  24. * @throws \Exception
  25. * In case the sync directory does not exist or is not defined in
  26. * $settings['config_sync_directory'].
  27. */
  28. public static function getSync() {
  29. $directory = Settings::get('config_sync_directory', FALSE);
  30. if ($directory === FALSE) {
  31. // @todo: throw a more specific exception.
  32. // @see https://www.drupal.org/node/2696103
  33. throw new \Exception('The config sync directory is not defined in $settings["config_sync_directory"]');
  34. }
  35. return new FileStorage($directory);
  36. }
  37. }