protected function getDatabaseConfig()
    {
        if ($this->app->config()['use_cache']) {
            $key = 'rails.ar.dbconfig';
            if ($dbConfig = $this->app->getService('rails.cache')->read($key)) {
                return $dbConfig;
            }
        }
        
        $connections = $this->getDatabaseConnections();
        if (!$connections) {
            return [[], null, null];
        }
        
        $config  = $this->app->config();
        
        if ($config['active_record']['allow_profiler'] === null) {
            $allowProfiler = ($config['environment'] == 'production' || $config['environment'] == 'test');
        } else {
            $allowProfiler = (bool)$config['active_record']['allow_profiler'];
        }
        
        $options = [
            'allowProfiler' => $allowProfiler
        ];
        
        if (isset($connections[$config['environment']])) {
            $defaultConnction = $config['environment'];
        } elseif (isset($connections['default'])) {
            $defaultConnction = 'default';
        } else {
            $defaultConnction = key($connections);
        }
        
        $dbConfig = [
            $connections,
            $defaultConnction,
            $options
        ];
        
        if ($this->app->config()['use_cache']) {
            $this->app->getService('rails.cache')->write($key, $dbConfig);
        }
        
        return $dbConfig;
    }