FakeConfigManager.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Fake ConfigManager
  4. */
  5. class FakeConfigManager
  6. {
  7. protected $values = [];
  8. /**
  9. * Initialize with test values
  10. *
  11. * @param array $values Initial values
  12. */
  13. public function __construct($values = [])
  14. {
  15. $this->values = $values;
  16. }
  17. /**
  18. * Set a given value
  19. *
  20. * @param string $key Key of the value to set
  21. * @param mixed $value Value to set
  22. */
  23. public function set($key, $value)
  24. {
  25. $this->values[$key] = $value;
  26. }
  27. /**
  28. * Get a given configuration value
  29. *
  30. * @param string $key Index of the value to retrieve
  31. *
  32. * @return mixed The value if set, else the name of the key
  33. */
  34. public function get($key)
  35. {
  36. if (isset($this->values[$key])) {
  37. return $this->values[$key];
  38. }
  39. return $key;
  40. }
  41. /**
  42. * Check if a setting exists
  43. *
  44. * @param string $setting Asked setting, keys separated with dots
  45. *
  46. * @return bool true if the setting exists, false otherwise
  47. */
  48. public function exists($setting)
  49. {
  50. return array_key_exists($setting, $this->values);
  51. }
  52. }