Config.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /**
  30. * The PDO DSN for the history database. Typically a SQLite path.
  31. *
  32. * @var string
  33. */
  34. public $dsn = NULL;
  35. public function __construct(Context $context) {
  36. $path = $context->getDirectory() . '/memcache_ui.local.php';
  37. if (file_exists($path)) {
  38. if (is_readable($path)) {
  39. $context->setMessage(Context::t('Loading config from @path', array('@path' => $path)), LOG_DEBUG);
  40. require_once($path);
  41. $context->setMessage($this, LOG_DEBUG);
  42. if (empty($this->account)) {
  43. $context->setMessage(Context::t('Empty account: anonymous access only.'), LOG_ERR);
  44. }
  45. elseif (empty($this->password)) {
  46. $context->setMessage(Context::t('Empty password: anonymous access only.'), LOG_ERR);
  47. }
  48. elseif (empty($this->servers)) {
  49. $context->setMessage(Context::t('Empty servers array: no server info.'), LOG_ERR);
  50. }
  51. if (empty($this->dsn)) {
  52. $context->setMessage(Context::t('No DSN in config: history features not enabled.', LOG_NOTICE));
  53. }
  54. }
  55. else {
  56. $context->setMessage(Context::t('Local config @path exists but is not readable', array(
  57. '@path' => $path,
  58. )), LOG_ERR);
  59. }
  60. }
  61. else {
  62. $context->setMessage(Context::t('Local config @path does not exist.', array(
  63. '@path' => $path,
  64. )), LOG_ERR);
  65. }
  66. }
  67. }
  68. }