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