Config.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace AlibabaCloud\Client\Config;
  3. use Exception;
  4. use clagiordano\weblibs\configmanager\ConfigManager;
  5. /**
  6. * Class Config
  7. *
  8. * @package AlibabaCloud\Client\Config
  9. */
  10. class Config
  11. {
  12. /**
  13. * @var ConfigManager|null
  14. */
  15. private static $configManager;
  16. /**
  17. * @param string $configPath
  18. *
  19. * @param string|null $defaultValue
  20. *
  21. * @return mixed
  22. */
  23. public static function get($configPath, $defaultValue = null)
  24. {
  25. return self::getConfigManager()
  26. ->getValue(
  27. \strtolower($configPath),
  28. $defaultValue
  29. );
  30. }
  31. /**
  32. * @return ConfigManager
  33. */
  34. private static function getConfigManager()
  35. {
  36. if (!self::$configManager instanceof ConfigManager) {
  37. self::$configManager = new ConfigManager(__DIR__ . DIRECTORY_SEPARATOR . 'Data.php');
  38. }
  39. return self::$configManager;
  40. }
  41. /**
  42. * @param string $configPath
  43. * @param mixed $newValue
  44. *
  45. * @return ConfigManager
  46. * @throws Exception
  47. */
  48. public static function set($configPath, $newValue)
  49. {
  50. self::getConfigManager()->setValue(\strtolower($configPath), $newValue);
  51. return self::getConfigManager()->saveConfigFile();
  52. }
  53. }