create config object from db
@param $name
@return mixed
172351
private function getConfigObjectFromDatabase($name)
    {
        // Load config from DB
        $config = $this->app->db->conn()->prepare(
            'SELECT * FROM ' . $this->app->db->getPrefix() . 'config
                          WHERE `config_name` = ? LIMIT 1');
        $config->execute(array($name));
        $config = $config->fetch(\PDO::FETCH_ASSOC);

        // Load corresponding class and get config array
        return $this->createConfigObject($config['config_name'], $config['config_data'], true);
    }
818040
public function getConfig($name)
    {
        $setting = $this->settings;
        return isset($setting[$name]) ? $setting[$name] : null;
    }
74504
public function getDatabase($name = null)
    {
        if (empty($name)) {
            $name = $this->getCurrentDatabaseName();
        }

        if (!isset($this->databasePool[$name])) {
            // init db
            $database = new Database($this, $name);
            if (isset($this->mapping[$name])) {
                $database->map($this->mapping[$name]);
            }

            // configure db
            $this->databasePool[$name] = $database;
        }
        
        return $this->databasePool[$name];
    }
730210
public function createDatabase($name)
    {
        if (preg_match('@[^a-z0-9\_\$\(\)+\-]@', $name)) {
            throw new InvalidDatabasenameException(sprintf(
                'The database name %s is invalid. The database name must match the following pattern (a-z0-9_$()+-)',
                $name
            ));
        }

        if ($this->eventManager->hasListeners(Events::PRE_CREATE_DATABASE)) {
            // @codeCoverageIgnoreStart
            $this->eventManager->dispatchEvent(Events::PRE_CREATE_DATABASE, new EventArgs($this, $name));
            // @codeCoverageIgnoreEnd
        }

        $response = $this->client->request('PUT', sprintf('/%s', $name));

        if (412 === $response->getStatusCode()) {
            throw new Exception(sprintf('The database "%s" already exist', $name));
        }

        $json = (string) $response->getBody();
        $value = JSONEncoder::decode($json);

        if (isset($value['error'])) {
            throw new Exception(sprintf('[%s] Failed to create database "%s". (%s)', $value['error'], $name, $value['reason']));
        }

        $database = $this->wrapDatabase($name);

        if ($this->eventManager->hasListeners(Events::POST_CREATE_DATABASE)) {
            // @codeCoverageIgnoreStart
            $this->eventManager->dispatchEvent(Events::POST_CREATE_DATABASE, new EventArgs($database));
            // @codeCoverageIgnoreEnd
        }

        return $database;
    }
997929
public function createDb($name)
    {
        $sql = $this->query->createDb($name);
        $this->db->exec($sql);

        return true;
    }
1242096
public static function initPdoDatabase($config, $name)
    {
        try {
            $pdo = static::createPdoConnectionByConfig($config);
        } catch (PDOException $e) {
            throw new Exception('Cannon instantiate database connection: ' . $e->getMessage());
        }

        $pdo->uniqueName = $config['host'] . "-" . $config['db'];

        static::checkDebugBar($pdo, $name);

        return new RepositoryPDO($pdo, $name);
    }
1183810
private static function getConnectionConfiguration($name)
    {
        $databaseConfig = Configuration::get('database.connections');
        if (isset($databaseConfig[$name])) {
            $databaseConfig = $databaseConfig[$name];
        } else {
            $databaseConfig = null;
        }

        if ($databaseConfig === null) {
            throw new ConfigurationException("Database configuration for connection '" . $name . "' doesn't exists!");
        }

        if (! isset($databaseConfig['driver'])) {
            throw new ConfigurationException("Database configuration for connection '" . $name . "' is invalid!");
        }

        return $databaseConfig;
    }
1090623
public function getPDO($name = null)
    {
        if (null === $name) {
            $name = $this->current ?: 'default';
        }
        if (!isset($this->connections[$name])) {
            $config = $this->configs[$name];
            $this->connections[$name] = new \PDO($config['dsn'], $config['username'], $config['password'], $config['options']);
        }

        return $this->connections[$name];
    }
1270383
protected function doSelectDatabase($name)
    {
        $mongoDB = $this->mongoClient->selectDB($name);
        $numRetries = $this->config->getRetryQuery();
        $loggerCallable = $this->config->getLoggerCallable();

        return $loggerCallable !== null
            ? new LoggableDatabase($this, $mongoDB, $this->eventManager, $numRetries, $loggerCallable)
            : new Database($this, $mongoDB, $this->eventManager, $numRetries);
    }
1071702
public static function create($name)
    {
        $db = Loader::db();
        $u = new User();
        $v = array($u->getUserID(), 0, $name, 'READY');
        $q = "insert into Piles (uID, isDefault, name, state) values (?, ?, ?, ?)";
        $r = $db->query($q, $v);
        if ($r) {
            $pID = $db->Insert_ID();

            return self::get($pID);
        }
    }
920215
public function getConfig($name) {
        $data = $this->get($name);
        if ($data === null) {
            return null;
        }
        if (isset($this->data['global'])) {
            $data['global'] = $this->data['global'];
        }
        $config = new self();
        $config->load($data);
        return $config;
    }
289979
public function loadConfigValue($name)
    {
        $feConfig = $this->iniConfig->getFeConfig($name);
        $section = $this->feConfigFallback[$name][static::SECTION];
        /** @var Model $model */
        $model = $this->pool->createClass('Brainworxx\\Krexx\\Service\\Config\\Model')
            ->setSection($section)
            ->setEditable($feConfig[0])
            ->setType($feConfig[1]);

        // Do we accept cookie settings here?
        if ($feConfig[0] === true) {
            $cookieSetting = $this->cookieConfig->getConfigFromCookies($section, $name);
            // Do we have a value in the cookies?
            if ($cookieSetting  !== null &&
                ($name === static::SETTING_DISABLED && $cookieSetting === static::VALUE_FALSE) === false
            ) {
                // We must not overwrite a disabled=true with local cookie settings!
                // Otherwise it could get enabled locally, which might be a security
                // issue.
                $model->setValue($cookieSetting)->setSource('Local cookie settings');
                $this->settings[$name] = $model;
                return $this;
            }
        }

        // Do we have a value in the ini?
        $iniSettings = $this->iniConfig->getConfigFromFile($section, $name);
        if (isset($iniSettings) === true) {
            $model->setValue($iniSettings)->setSource('Krexx.ini settings');
            $this->settings[$name] = $model;
            return $this;
        }

        // Nothing yet? Give back factory settings.
        $model->setValue($this->feConfigFallback[$name][static::VALUE])->setSource('Factory settings');
        $this->settings[$name] = $model;

        return $this;
    }
876024
public static function make($name='default') {
		$configs = static::listConfig();
		
		if( !isset($configs[$name]) ) {
			throw new SQLException('Database configuration with name "'.$name.'" not found.', 'Loading configuration');
		}
		
		$config = $configs[$name];
		
		if( empty($config['driver']) ) {
			throw new SQLException('Database configuration with name "'.$name.'" has no driver property.', 'Loading configuration');
		}
		
		if( empty(static::$adapters[$config['driver']]) ) {
			throw new SQLException('Database configuration with name "'.$name.'" requires an unknown driver "'.$config['driver'].'".', 'Loading configuration');
		}
		
		$adapterClass = static::$adapters[$config['driver']];
		return new $adapterClass($name, $config);
		
	}
1368933
protected function getPDO($name)
    {
        if (!isset($this->config[$name]) || !is_array($this->config[$name])) {
            throw new \Exception('Config not found ! (config: ' . $name . ')');
        }

        $config = $this->config[$name];

        if (!isset($config['dsn'])) {
            throw new \Exception('"dsn" parameter is not defined !');
        }

        if (!isset($config['user'])) {
            throw new \Exception('"user" parameter is not defined !');
        }

        if (!isset($config['pass'])) {
            throw new \Exception('"pass" parameter is not defined !');
        }

        $config['options'] = isset($config['options']) ? $config['options'] : array();

        $options = array();
        foreach ($config['options'] as $name => $value) {
            if (0 === strpos($name, 'PDO::')) {
                $options[constant($name)] = $value;
            }
        }

        $connection = new \PDO($config['dsn'], $config['user'], $config['pass'], $options);
        $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

        return $connection;
    }
774250
public function createRole($name) {
		$result = $this->repository->createRole($name);
		$this->domain->const->generateRoles();
		return $result;
	}
405605
public static function create( $name = null, $conf = null ) 
	{
		if ( is_null( $name ) ) 
		{
			$name = static::$_default;
		}

		if ( !is_null( $conf ) && is_array( $conf ) )
		{
			return static::$_instances[$name] = new static( $name, $conf );
		}

		if ( !isset( static::$_instances[$name] ) )
		{
			static::$_instances[$name] = new static( $name );
		}

		return static::$_instances[$name];
	}
301322
public function loadDatabaseConfig($name = 'default') {
        $config = new DatabaseConfiguration ($name);
        if ($name == 'default') {
            $_wula_config_file = APPROOT . CONF_DIR . '/dbconfig';
        } else {
            $_wula_config_file = APPROOT . CONF_DIR . '/' . $name . '_dbconfig';
        }
        $wula_cfg_fiels [] = $_wula_config_file . '.php';
        $wula_cfg_fiels [] = $_wula_config_file . '_' . APP_MODE . '.php';
        foreach ($wula_cfg_fiels as $_wula_config_file) {
            if (is_file($_wula_config_file)) {
                $cfg = include $_wula_config_file;
                if ($cfg instanceof Configuration) {
                    $config->setConfigs($cfg);
                } else if (is_array($cfg)) {
                    $config->setConfigs($cfg);
                }
            }
        }
        unset ($_wula_config_file, $wula_cfg_fiels);

        // 再给用户一次机会
        $cfg = function_exists('apply_filter') ? apply_filter('on_load_' . $name . '_dbconfig', $config) : $config;

        return $cfg instanceof DatabaseConfiguration ? $cfg : $config;
    }