Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
CRAP
42.86% covered (danger)
42.86%
6 / 14
Config
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
16.14
42.86% covered (danger)
42.86%
6 / 14
 install
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 getConfig
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 8
<?php
namespace Entity;
class Config extends ModelBase
{
    private static $config = array();
    protected function install()
    {
        $dbPrefix = $this->getDbPrefix();
        $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}config` (
            `lang` VARCHAR(8) NULL,
            `key` VARCHAR(64) NOT NULL,
            `value` TEXT NULL,
            UNIQUE(`lang`, `key`)
        )");
        if ($result === false)
            throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
        return true;
    }
    public static function getConfig($lang =null, $key =null, $defaultValue =null)
    {
        $fetcher = new self();
        if (isset(self::$config[$lang]))
            return;
        $values = $fetcher->selects(array("lang" => $lang));
        foreach ($values as $i)
            self::$config[$lang][$i->key] = $i->value;
        if ($key)
            return (isset(self::$config[$lang][$key]) ? self::$config[$lang][$key] : $defaultValue);
        return $defaultValue;
    }
}