ImmutableConfig.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Drupal\Core\Config;
  3. /**
  4. * Defines the immutable configuration object.
  5. *
  6. * Encapsulates all capabilities needed for runtime configuration handling
  7. * except being able to change the configuration.
  8. *
  9. * If you need to be able to change configuration use
  10. * \Drupal\Core\Form\ConfigFormBaseTrait or
  11. * \Drupal\Core\Config\ConfigFactoryInterface::getEditable().
  12. *
  13. * @see \Drupal\Core\Form\ConfigFormBaseTrait
  14. * @see \Drupal\Core\Config\ConfigFactoryInterface::getEditable()
  15. * @see \Drupal\Core\Config\ConfigFactoryInterface::get()
  16. *
  17. * @ingroup config_api
  18. */
  19. class ImmutableConfig extends Config {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function set($key, $value) {
  24. throw new ImmutableConfigException("Can not set values on immutable configuration {$this->getName()}:$key. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function clear($key) {
  30. throw new ImmutableConfigException("Can not clear $key key in immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function save($has_trusted_data = FALSE) {
  36. throw new ImmutableConfigException("Can not save immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  37. }
  38. /**
  39. * Deletes the configuration object.
  40. *
  41. * @return \Drupal\Core\Config\Config
  42. * The configuration object.
  43. */
  44. public function delete() {
  45. throw new ImmutableConfigException("Can not delete immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object");
  46. }
  47. }