Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
Config.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg\Database;
3 
13 class Config {
14 
15  const READ = 'read';
16  const WRITE = 'write';
17  const READ_WRITE = 'readwrite';
18 
20  protected $config;
21 
27  public function __construct(\stdClass $config) {
28  $this->config = $config;
29  }
30 
36  public function getTablePrefix() {
37  return $this->config->dbprefix;
38  }
39 
45  public function isQueryCacheEnabled() {
46  if (isset($this->config->db_disable_query_cache)) {
47  return !$this->config->db_disable_query_cache;
48  }
49 
50  return true;
51  }
52 
58  public function isDatabaseSplit() {
59  if (isset($this->config->db) && isset($this->config->db['split'])) {
60  return $this->config->db['split'];
61  }
62 
63  // this was the recommend structure from Elgg 1.0 to 1.8
64  if (isset($this->config->db) && isset($this->config->db->split)) {
65  return $this->config->db->split;
66  }
67 
68  return false;
69  }
70 
85  public function getConnectionConfig($type = self::READ_WRITE) {
86  $config = array();
87  switch ($type) {
88  case self::READ:
89  case self::WRITE:
91  break;
92  default:
94  break;
95  }
96 
97  return $config;
98  }
99 
105  protected function getGeneralConnectionConfig() {
106  return array(
107  'host' => $this->config->dbhost,
108  'user' => $this->config->dbuser,
109  'password' => $this->config->dbpass,
110  'database' => $this->config->dbname,
111  );
112  }
113 
120  protected function getParticularConnectionConfig($type) {
121  if (is_object($this->config->db[$type])) {
122  // old style single connection (Elgg < 1.9)
123  $config = array(
124  'host' => $this->config->db[$type]->dbhost,
125  'user' => $this->config->db[$type]->dbuser,
126  'password' => $this->config->db[$type]->dbpass,
127  'database' => $this->config->db[$type]->dbname,
128  );
129  } else if (array_key_exists('dbhost', $this->config->db[$type])) {
130  // new style single connection
131  $config = array(
132  'host' => $this->config->db[$type]['dbhost'],
133  'user' => $this->config->db[$type]['dbuser'],
134  'password' => $this->config->db[$type]['dbpass'],
135  'database' => $this->config->db[$type]['dbname'],
136  );
137  } else if (is_object(current($this->config->db[$type]))) {
138  // old style multiple connections
139  $index = array_rand($this->config->db[$type]);
140  $config = array(
141  'host' => $this->config->db[$type][$index]->dbhost,
142  'user' => $this->config->db[$type][$index]->dbuser,
143  'password' => $this->config->db[$type][$index]->dbpass,
144  'database' => $this->config->db[$type][$index]->dbname,
145  );
146  } else {
147  // new style multiple connections
148  $index = array_rand($this->config->db[$type]);
149  $config = array(
150  'host' => $this->config->db[$type][$index]['dbhost'],
151  'user' => $this->config->db[$type][$index]['dbuser'],
152  'password' => $this->config->db[$type][$index]['dbpass'],
153  'database' => $this->config->db[$type][$index]['dbname'],
154  );
155  }
156 
157  return $config;
158  }
159 }
160 
getGeneralConnectionConfig()
Get the read/write database connection information.
Definition: Config.php:105
__construct(\stdClass $config)
Constructor.
Definition: Config.php:27
getConnectionConfig($type=self::READ_WRITE)
Get the connection configuration.
Definition: Config.php:85
isQueryCacheEnabled()
Is the query cache enabled?
Definition: Config.php:45
isDatabaseSplit()
Are the read and write connections separate?
Definition: Config.php:58
getParticularConnectionConfig($type)
Get connection information for reading or writing.
Definition: Config.php:120
getTablePrefix()
Get the database table prefix.
Definition: Config.php:36
if(!$display_name) $type
Definition: delete.php:27