ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables Pages
Config.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Entity;
4 
5 class Config extends ModelBase
6 {
7  private static $config = array();
8 
9  protected function install()
10  {
11  $dbPrefix = $this->getDbPrefix();
12  $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}config` (
13  `lang` VARCHAR(8) NULL,
14  `key` VARCHAR(64) NOT NULL,
15  `value` TEXT NULL,
16  UNIQUE(`lang`, `key`)
17  )");
18  if ($result === false)
19  throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
20  return true;
21  }
22 
23  public static function getConfig($lang =null, $key =null, $defaultValue =null)
24  {
25  $fetcher = new self();
26  if (isset(self::$config[$lang]))
27  return;
28  $values = $fetcher->selects(array("lang" => $lang));
29  foreach ($values as $i)
30  self::$config[$lang][$i->key] = $i->value;
31  if ($key)
32  return (isset(self::$config[$lang][$key]) ? self::$config[$lang][$key] : $defaultValue);
33  return $defaultValue;
34  }
35 }
36 
static getConfig($lang=null, $key=null, $defaultValue=null)
Definition: Config.php:23