NullStorage.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Drupal\Core\Config;
  3. /**
  4. * Defines a stub storage.
  5. *
  6. * This storage is always empty; the controller reads and writes nothing.
  7. *
  8. * The stub implementation is needed for synchronizing configuration during
  9. * installation of a module, in which case all configuration being shipped with
  10. * the module is known to be new. Therefore, the module installation process is
  11. * able to short-circuit the full diff against the active configuration; the
  12. * diff would yield all currently available configuration as items to remove,
  13. * since they do not exist in the module's default configuration directory.
  14. *
  15. * This also can be used for testing purposes.
  16. */
  17. class NullStorage implements StorageInterface {
  18. /**
  19. * The storage collection.
  20. *
  21. * @var string
  22. */
  23. protected $collection;
  24. /**
  25. * Constructs a new NullStorage.
  26. *
  27. * @param string $collection
  28. * (optional) The collection to store configuration in. Defaults to the
  29. * default collection.
  30. */
  31. public function __construct($collection = StorageInterface::DEFAULT_COLLECTION) {
  32. $this->collection = $collection;
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function exists($name) {
  38. return FALSE;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function read($name) {
  44. return [];
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function readMultiple(array $names) {
  50. return [];
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function write($name, array $data) {
  56. return FALSE;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function delete($name) {
  62. return FALSE;
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function rename($name, $new_name) {
  68. return FALSE;
  69. }
  70. /**
  71. * {@inheritdoc}
  72. */
  73. public function encode($data) {
  74. return $data;
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function decode($raw) {
  80. return $raw;
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function listAll($prefix = '') {
  86. return [];
  87. }
  88. /**
  89. * {@inheritdoc}
  90. */
  91. public function deleteAll($prefix = '') {
  92. return FALSE;
  93. }
  94. /**
  95. * {@inheritdoc}
  96. */
  97. public function createCollection($collection) {
  98. return new static($collection);
  99. }
  100. /**
  101. * {@inheritdoc}
  102. */
  103. public function getAllCollectionNames() {
  104. // Returns only non empty collections.
  105. return [];
  106. }
  107. /**
  108. * {@inheritdoc}
  109. */
  110. public function getCollectionName() {
  111. return $this->collection;
  112. }
  113. }