Config.inc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * Load configuration from defaults or a configuration file
  5. */
  6. namespace Memcache_UI\Core {
  7. class Config {
  8. /**
  9. * The single account allowed access to the UI.
  10. *
  11. * @var string
  12. */
  13. public $account = NULL;
  14. /**
  15. * The cleartext password for the authorized account.
  16. *
  17. * @var string
  18. */
  19. public $password = NULL;
  20. /**
  21. * The list of servers to monitor.
  22. *
  23. * @var array
  24. * Entries in "server:port" format
  25. */
  26. public $servers = array(
  27. 'localhost:11211',
  28. );
  29. public function __construct(Context $context) {
  30. $path = $context->getDirectory() . '/memcache_ui.local.php';
  31. if (file_exists($path)) {
  32. if (is_readable($path)) {
  33. $context->setMessage(Context::t('Loading config from @path', array('@path' => $path)), LOG_DEBUG);
  34. require_once($path);
  35. $context->setMessage($this, LOG_DEBUG);
  36. if (empty($this->account)) {
  37. $context->setMessage(Context::t('Empty account: anonymous access only.'), LOG_ERR);
  38. }
  39. elseif (empty($this->password)) {
  40. $context->setMessage(Context::t('Empty password: anonymous access only.'), LOG_ERR);
  41. }
  42. elseif (empty($this->servers)) {
  43. $context->setMessage(Context::t('Empty servers array: no server info.'), LOG_ERR);
  44. }
  45. }
  46. else {
  47. $context->setMessage(Context::t('Local config @path exists but is not readable', array(
  48. '@path' => $path,
  49. )), LOG_ERR);
  50. }
  51. }
  52. else {
  53. $context->setMessage(Context::t('Local config @path does not exist.', array(
  54. '@path' => $path,
  55. )), LOG_ERR);
  56. }
  57. }
  58. }
  59. }