Get database config.

@param array $return
327656
protected function getDatabaseConfigs(array &$return)
    {
        $return['localhost'] = 'localhost';

        $return['host']     = $this->connection->getConfig('host');
        $return['database'] = $this->connection->getConfig('database');
        $return['username'] = $this->connection->getConfig('username');
        $return['password'] = $this->connection->getConfig('password');
        $return['connection_username'] = $return['username'];
        $return['connection_password'] = $return['password'];

        if ( ! in_array($return['host'], ['localhost', '127.0.0.1']))
        {
            $return['localhost'] = $this->command->ask('Database is on the other server. Provide local IP/hostname.');
        }
    }
538127
public function fetch($return = self::RETURN_COLLECTION) {
        /** We replace Post.xx by post.xx */
        foreach ($this->_entities as $entity) {
            $class = $this->_getTableEntity($entity);

            if ($entity != $class->name()) {
                $this->_query = preg_replace('#(.*)' . $entity . '\.(.*)#isU', '$1' . $class->name() . '.$2', $this->_query);
            }
        }

        /** Query execution */
        $sql = new Sql();
        $sql->vars($this->_vars);
        $sql->query('orm-' . $this->_token, $this->_query);

        if ($this->_type == self::QUERY_COUNT) {
            return $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCHCOLUMN);
        }
        else {
            $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCH);
        }

        $collection = $sql->data($this->_getEntityName($this->_entity->name()));

        /** We can do SELECT OR SELECT DISTINCT OR SELECT RAW */
        if (in_array($this->_type, [self::QUERY_DISTINCT, self::QUERY_RAW])) {
            $nLines = $collection->count();
            $in = '';

            /** @var $value \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($collection as $key => $value) {
                $in .= $value->fields()[$value->primary()]->value;

                if ($key < $nLines - 1) {
                    $in .= ', ';
                }
            }

            $builder = new Builder($this->_entity);
            $collection = $builder->find()->where($this->_entity->name() . '.' . $this->_entity->primary() . ' IN (' . $in . ')')->fetch();
        }

        /** If we have fields with a relation ONE TO MANY OR MANY TO MANY */
        foreach ($this->_entity->fields() as $field) {
            if ($field->foreign != null && in_array($field->foreign->type(), [ForeignKey::ONE_TO_MANY, ForeignKey::MANY_TO_MANY])) {
                /** we loop through the results to add each time */
                switch ($field->foreign->type()) {
                    case ForeignKey::ONE_TO_MANY :
                        $collection = $this->_dataOneToMany($field, $collection);
                        break;

                    case ForeignKey::MANY_TO_MANY :
                        $collection = $this->_dataManyToMany($field, $collection);
                        break;
                }
            }
        }

        if ($return == self::RETURN_ENTITY && $collection->count() <= 1) {
            return $collection->first();
        }
        else {
            return $collection;
        }
    }
409175
private function getDblibDsn(array $config)
    {
        $arguments = [
            'host'   => $config['host'] . ':' . $config['port'],
            'dbname' => $config['database'],
        ];

        if (isset($config['appname'])) {
            $arguments['appname'] = $config['appname'];
        }

        if (isset($config['charset'])) {
            $arguments['charset'] = $config['charset'];
        }

        return $this->buildConnectString('dblib', $arguments);
    }
464859
public function normalizeFacebook($return)
    {
        $genders = [
            'male'   => 'M',
            'female' => 'F'
        ];

        $data = [
            'id'                  => $return['id'],
            'name'                => $return['name'],
            'firstName'           => $return['first_name'],
            'lastName'            => $return['last_name'],
            'facebookProfileLink' => $return['link'],
            'username'            => $return['username'],
            'email'               => $return['email'],
            'timezone'            => $return['timezone'],
            'locale'              => $return['locale'],
            'verified'            => $return['verified'],
            'gender'              => false,
            'avatar'              => false,
            'gravatar'            => false,
            'emailVerified'       => true,
            'isSilhouette'        => true
        ];

        if (isset($return['gender'])) {
            $data['gender'] = $genders[$return['gender']];
        }

        $response = $this->httpRequest(
            'https://graph.facebook.com',
            '/'.$return['id'].'/?fields=picture.type(large)'
        );

        if ($response->isOk()) {
            $graph = json_decode($response->getContent());
            $data['avatar'] = $graph->picture->data->url;
            $data['issilhouette'] = $graph->picture->data->is_silhouette;
        }

        return $data;
    }
777050
public function save($data = null, $return = Db::RETURN_ISOK)
	{
		if(null === $data)
		{
			$data = $this->data;
		}
		$table = $this->getOptionTable();
		if(empty($this->fields) || $table !== $this->tableName())
		{
			$this->loadFields($fields, $fieldNames, $pk, $bitFields, $table);
		}
		else
		{
			$pk = $this->pk;
		}
		$pk = explode(',', $pk);
		$isEdit = true;
		foreach($pk as $tpk)
		{
			if(!array_key_exists($tpk, $data))
			{
				$isEdit = false;
				break;
			}
		}
		// 判断记录是否存在，来决定$isEdit的值
		if($isEdit)
		{
			$option = $this->operationOption;
			$isEdit = $this->wherePk($data,$table)->count() > 0;
			$this->operationOption = $option;
		}
		// 2个if不要合并！
		if($isEdit)
		{
			$result = $this->wherePk($data,$table)->edit($data,$return);
			if(Db::RETURN_INSERT_ID === $result)
			{
				return $pk[0];
			}
			else
			{
				return $result;
			}
		}
		else
		{
			return $this->add($data);
		}
	}
223335
public function cacheThemeConfig($return=false)
	{
		$themes = $this->getThemesFromDb();
		$arrayTheme = array();

		foreach($themes as $theme) {
			if(!in_array($theme->folder, $arrayTheme))
				$arrayTheme[] = $theme->folder;
		}

		if($return == false) {
			$filePath   = Yii::getPathOfAlias('application.config');
			$fileHandle = fopen($filePath.'/cache_theme.php', 'w');
			fwrite($fileHandle, implode("\n", $arrayTheme));
			fclose($fileHandle);

		} else 
			return $arrayTheme;
	}
930776
public static function flatten($array, $return = array())
    {
        foreach ($array as $value) {
            if (is_array($value) || is_object($value)) {
                $return = self::flatten($value, $return);
            } else {
                $return[] = $value;
            }
        }
        return $return;
    }
77953
public function getConfig($key = null, $default = null)
	{
		if (is_array($key))
		{
			return \Arr::subset($this->config, $key, $default);
		}

		return \Arr::get($this->config, $key, $default);
	}
454058
public function printScripts($return = false)
    {
        $scripts = '';
        foreach ($this->getScripts() as $script) {
            $scripts .= '<script type="text/javascript" src="' . $script . '"></script>';
        }

        if ($return) {
            return $scripts;
        }
        else {
            echo $scripts;
        }
    }
27721
static function get($key, $default = null) {
    if (isset(Config::$values[$key])) {
      return Config::$values[$key];
    } else {
      if (Config::isEmpty()) {
        throw new ConfigException("Site configuration has not been initialised for '$key'");
      } else if ($default !== null) {
        return $default;
      } else {
        throw new ConfigException("No site configuration value found for '$key'");
      }
    }
  }
1025725
def get_database_configuration():
    """"""
    db_config = get_database_config_file()
    if db_config is None:
        return None
    with open(db_config, 'r') as ymlfile:
        cfg = yaml.load(ymlfile)
    return cfg
101535
private function validateDatabaseDetails($environment)
    {
        $db_config = [];
        $configFile = DIR_CONFIG_SITE . '/database.php';
        $environmentConfig = DIR_CONFIG_SITE . "/{$environment}.database.php";

        // If the database.php file exists, load it first
        if (file_exists($configFile)) {
            $db_config = include DIR_CONFIG_SITE . '/database.php';
        }

        // If there's an environment specific database file, load that too
        if (file_exists($environmentConfig)) {
            $db_config = array_merge($db_config, include $environmentConfig);
        }

        // Make sure the default connection is set
        $defaultConnection = array_get($db_config, 'default-connection');

        // Make sure we have all the stuff we expect
        $connection = array_get($db_config, "connections.{$defaultConnection}");

        // Make sure we have all the keys we are expecting
        return $defaultConnection && $connection &&
            array_get($connection, 'database') &&
            array_get($connection, 'username') &&
            array_get($connection, 'server');
    }
792390
def config(name='DATABASE_URL', default='sqlite://:memory:'):
    """"""
    config = {}
    s = env(name, default)
    if s:
        config = parse_database_url(s)
    return config
196001
private function getConfig($key = null, $args = null)
    {
        if($key!=null) {

            $value = null;
            if(isset($this->_config[$key])) {
                $value = $this->_config[$key];

            } elseif(isset($this->_updateConfig[$key])) {
                    $value = $this->_updateConfig[$key];

            }

            if (isset($args["returnAsArray"]) && $args["returnAsArray"]){

                /** Return the response as an array */
                if(is_array($value)){
                    return $value;
                }
                
            }elseif(is_array($value)) {
                /** @var CheckoutApi_Lib_RespondObj $to_return */
                $to_return = CheckoutApi_Lib_Factory::getInstance('CheckoutApi_Lib_RespondObj');
                $to_return->setConfig( $value);
                return $to_return;
            }

            return $value;
        }

        if($key == null) {
            return $this->_config;
        }
        return null;
    }
1363886
protected function getDatabaseConfig()
    {
        /** @skipUpgrade */
        $databaseConfig = [
            "type" => Environment::getEnv('SS_DATABASE_CLASS') ?: 'MySQLDatabase',
            "server" => Environment::getEnv('SS_DATABASE_SERVER') ?: 'localhost',
            "username" => Environment::getEnv('SS_DATABASE_USERNAME') ?: null,
            "password" => Environment::getEnv('SS_DATABASE_PASSWORD') ?: null,
        ];

        // Set the port if called for
        $dbPort = Environment::getEnv('SS_DATABASE_PORT');
        if ($dbPort) {
            $databaseConfig['port'] = $dbPort;
        }

        // Set the timezone if called for
        $dbTZ = Environment::getEnv('SS_DATABASE_TIMEZONE');
        if ($dbTZ) {
            $databaseConfig['timezone'] = $dbTZ;
        }

        // For schema enabled drivers:
        $dbSchema = Environment::getEnv('SS_DATABASE_SCHEMA');
        if ($dbSchema) {
            $databaseConfig["schema"] = $dbSchema;
        }

        // For SQlite3 memory databases (mainly for testing purposes)
        $dbMemory = Environment::getEnv('SS_DATABASE_MEMORY');
        if ($dbMemory) {
            $databaseConfig["memory"] = $dbMemory;
        }

        // Allow database adapters to handle their own configuration
        DatabaseAdapterRegistry::autoconfigure($databaseConfig);
        return $databaseConfig;
    }
1150331
public static function find($config = array(), $key = null)
	{
		$query = \DB::select()
			->from(static::$_table_name)
			->as_object(get_called_class());

		if ($config instanceof \Closure)
		{
			$config($query);
		}
		else
		{
			$config = $config + array(
				'select' => array(static::$_table_name.'.*'),
				'where' => array(),
				'order_by' => array(),
				'limit' => null,
				'offset' => 0,
			);

			extract($config);

			is_string($select) and $select = array($select);
			$query->select_array($select);

			if ( ! empty($where))
			{
				$query->where($where);
			}

			if (is_array($order_by))
			{
				foreach ($order_by as $_field => $_direction)
				{
					$query->order_by($_field, $_direction);
				}
			}
			else
			{
				$query->order_by($order_by);
			}

			if ($limit !== null)
			{
				$query = $query->limit($limit)->offset($offset);
			}
		}

		static::pre_find($query);

		$result =  $query->execute(static::get_connection());
		$result = ($result->count() === 0) ? null : $result->as_array($key);

		return static::post_find($result);
	}
647282
public static function config($option = null)
    {
        if (is_array($option)) {
            self::$config = new DataArray($option);
        }
        if (self::$config instanceof DataArray) {
            return self::$config->get();
        }
        return [];
    }