Creates a connection manager from a <code>.kkdb.php</code> config file.

@param string $file
@return ConnectionManager

@throws \RuntimeException When the config file could not be found.
2144
public static function fromConfigFile($file)
	{
		if(!is_file($file))
		{
			throw new \RuntimeException(sprintf('Config file "%s" does not exist', $file));
		}
		
		$config = new Configuration(static::processConfigFileData(require $file));
		
		return new ConnectionManager($config->getConfig('ConnectionManager'));
	}
775084
public static function parse($file)
    {
        $config_path = self::$config_path == '' ? APP_PATH . '/config/' : self::$config_path;
        if($file == null){
            $file = scandir($config_path);
            foreach ($file as $k => $v)
            {
                unset($file[0], $file[1]);
                if($v == 'routes.php' )
                {
                    unset($file[$k]);
                }
            }
            foreach ($file as $k => $v)
            {
                $name = str_replace('.php', '', $v);
                $file = $config_path . $v;
                $data[$name] = include $file;
            }
        }else{
            $type = $file;
            if(strpos($type, '.')){
                $type = explode('.', $type);
                $file = $config_path . $type[0] . '.php';
                if(!array_key_exists($type[1], self::load($file)))
                {
                    throw new Exception('This configuration [' . self::$config . '] is not supported!');
                }
                $data = self::load($file)[$type[1]];
            }else{
                $file = $config_path . $file . '.php';
                $data = self::load($file);
            }

        }
        return $data;
    }
367643
protected function getConnection(Configuration $config)
    {
        $connection = $this->getOption('connection');

        switch (true) {
            case is_array($connection):
                $connection = new Connection(
                    array_key_exists('server', $connection) ? $connection['server'] : null,
                    array_key_exists('options', $connection) ? $connection['options'] : [],
                    $config,
                    $this->getEventManager()
                );
                break;

            case $connection instanceof Connection:
                if ($connection->getEventManager() !== $this->getEventManager()) {
                    throw new \RuntimeException(
                        'Cannot use different EventManager instances for DocumentManager and Connection.'
                    );
                }
                break;

            default:
                throw new \InvalidArgumentException('Invalid argument: ' . $connection);
        }

        return $connection;
    }
1323535
public function read($file)
	{
		if (!file_exists($file) || (filesize($file) < 10))
		{
			throw new FileNotFoundException('No configuration file found and no installation code available.', 500);
		}

		require_once $file;

		if (!class_exists('\\JConfig'))
		{
			throw new UnsupportedFormatException('Invalid configuration file.', 500);
		}

		$config = new \JConfig;

		if (isset($config->tmp_path))
		{
			if (substr($config->tmp_path, strlen(PATH_ROOT)) == DS . 'tmp')
			{
				$config->tmp_path = PATH_APP . substr($config->tmp_path, strlen(PATH_ROOT));
			}
		}

		if (isset($config->log_path))
		{
			if (substr($config->log_path, strlen(PATH_ROOT)) == DS . 'logs')
			{
				$config->log_path = PATH_APP . substr($config->log_path, strlen(PATH_ROOT));
			}
		}

		return $config;
	}
102987
protected function connect(string $connection): Redis
	{
		if(!isset($this->configurations[$connection]))
		{
			throw new RuntimeException(vsprintf('[ %s ] has not been defined in the redis configuration.', [$connection]));
		}

		$config = $this->configurations[$connection];

		return new Redis(new Connection($config['host'], $config['port'], $config['persistent'] ?? false, $config['timeout'] ?? 60, $connection), $config);
	}
9256
protected function _expandPlugin($file)
    {
        preg_match(self::PLUGIN_PATTERN, $file, $matches);
        if (empty($matches[1]) || empty($matches[2])) {
            throw new RuntimeException('Missing required parameters');
        }
        if (!CorePlugin::isLoaded($matches[1])) {
            throw new RuntimeException($matches[1] . ' is not a loaded plugin.');
        }
        $path = CorePlugin::path($matches[1]);

        return $path . 'webroot' . DS . $matches[2];
    }
1070145
public  function loadConfig( $file ){
		if( file_exists( $file ) ){
			$config = include $file;
			$driver = $config['driver'];
			if( $driver == 'file'){
				$session = new \Wudimei\Session\File($config);
			}
			$this->session = $session;
		}
		else{
			throw new \Exception('sesstion config file "' . $file . '" does not exists');
		}
		

	}
617245
public function load($file, array $options = []): Config
    {
        expect_type($file, 'string');

        $options += $this->options;
        $path = $this->absolutePath($file, $options['base_path'] ?? getcwd());

        if (!$this->assertFile($path, $options)) {
            return new Config();
        }

        $data = $this->loadFile($path, $options);
        $this->assertData($data, $file);

        return new Config($data);
    }
453690
public function withYamlConfig($file)
    {
        if (!class_exists(Yaml::class)) {
            throw new RuntimeException("You need to install 'symfony/yaml' to use this feature");
        }

        if (!is_readable($file)) {
            throw new RuntimeException("The configuration file is not readable");
        }

        $config = Yaml::parse(file_get_contents($file));
        if (!is_array($config)) {
            throw new RuntimeException("The configuration is not valid");
        }

        $this->withConfig($config);

        return $this;
    }
1268495
public static function createFromFile($file)
    {
        // If the file is not readable
        if (!is_readable($file)) {
            throw new InvalidArgumentException(
                sprintf(InvalidArgumentException::INVALID_FILE_STR, $file),
                InvalidArgumentException::INVALID_FILE
            );
        }

        return self::createFromString(file_get_contents($file));
    }
1032004
public function loadOids($file)
    {
        if (!file_exists($file)) {
            throw $this->createException('OIDs cache file not found');
        }

        if ($this->oidTypeNames) {
            return $this;
        }

        if (!$this->host || !$this->dbName) {
            throw $this->createException('You must set host name and dbName first');
        }

        $oids = include $file;

        if (isset($oids[$this->host][$this->dbName])) {
            $this->oidTypeNames = $oids[$this->host][$this->dbName];
        }

        return $this;
    }
189106
public function getConfig($file = null)
    {
        $file = !empty($file) ? $file : $this->fileCache;
        if (file_exists($file)) {
            if (!is_readable($file)) {
                throw new Exception\RuntimeException(sprintf('"%s" cannot read', $file));
            }
            return require $file;
        }
        return false;
    }
317038
protected function createConnection($connection)
    {
        // Load config connection
        $config = Arr::get($this->config, 'connections.' . $connection);
        if (is_null($config)) {
            throw new \InvalidArgumentException("config connection [$connection] not found.");
        }

        $driver = Arr::get($config, 'driver');
        if (is_null($driver)) {
            throw new \InvalidArgumentException("driver connection [$connection] not information.");
        }

        // We'll check to see if a creator method exists for the given connection. If not we
        // will check for a custom connection creator, which allows developers to create
        // connections using their own customized connection creator Closure to create it.
        if (isset($this->customCreators[$driver])) {
            return $this->callCustomCreator($driver, $config);
        } else {
            $method = 'create' . Str::studly($driver) . 'Driver';

            if (method_exists($this, $method)) {
                return $this->$method($config);
            }
        }
        throw new \InvalidArgumentException("driver [$driver] connection [$connection] not supported.");
    }
181766
public static function rmfile($file)
    {
        if (is_file($file)) {
            return chmod($file, 0777) && unlink($file);
        } else {
            throw new RuntimeException(sprintf(
                'Invalid file path supplied "%s"', $file
            ));
        }
    }
929483
public function create(Connection $connection)
    {
        // Get config with containing all metadata drivers
        $configuration = $this->configFactory->getConfiguration();

        // Get orm event manager
        $eventManager = $connection->getEventManager();

        // Pass the database connection, the orm config and the event manager 
        // to the concrete5 event system so packages can hook in to the process
        // and alter the values
        $event = new \Symfony\Component\EventDispatcher\GenericEvent();
        $event->setArgument('connection', $connection);
        $event->setArgument('configuration', $configuration);
        $event->setArgument('eventManager', $eventManager);
        Events::dispatch('on_entity_manager_configure', $event);

        // Reasign the values from the dispatched event
        $conn   = $event->getArgument('connection');
        $config = $event->getArgument('configuration');
        $evm    = $event->getArgument('eventManager');

        // Inject the orm eventManager into the entityManager so orm events
        // can be triggered.
        return EntityManager::create($conn, $config, $evm);
    }
304017
protected function lint($file)
    {
        $command = $this->executable . ' -output-format ' . escapeshellarg(
            'file:__FILE__;line:__LINE__;message:__ERROR__'
        ) . ' ';

        if (isset($this->conf)) {
            $command .= '-conf ' . escapeshellarg($this->conf->getPath()) . ' ';
        }

        $command .= '-process ';

        if (file_exists($file)) {
            if (is_readable($file)) {
                if ($this->cache) {
                    $lastmtime = $this->cache->get($file);

                    if ($lastmtime >= filemtime($file)) {
                        $this->log("Not linting '" . $file . "' due to cache", Project::MSG_DEBUG);

                        return false;
                    }
                }

                $messages = [];
                exec($command . '"' . $file . '"', $messages, $return);

                if ($return > 100) {
                    throw new BuildException("Could not execute Javascript Lint executable '{$this->executable}'");
                }

                $summary = $messages[count($messages) - 1];

                preg_match('/(\d+)\serror/', $summary, $matches);
                $errorCount = (count($matches) > 1 ? $matches[1] : 0);

                preg_match('/(\d+)\swarning/', $summary, $matches);
                $warningCount = (count($matches) > 1 ? $matches[1] : 0);

                $errors = [];
                $warnings = [];
                if ($errorCount > 0 || $warningCount > 0) {
                    $last = false;
                    foreach ($messages as $message) {
                        $matches = [];
                        if (preg_match('/^(\.*)\^$/', $message)) {
                            $column = strlen($message);
                            if ($last == 'error') {
                                $errors[count($errors) - 1]['column'] = $column;
                            } else {
                                if ($last == 'warning') {
                                    $warnings[count($warnings) - 1]['column'] = $column;
                                }
                            }
                            $last = false;
                        }
                        if (!preg_match('/^file:(.+);line:(\d+);message:(.+)$/', $message, $matches)) {
                            continue;
                        }
                        $msg = $matches[3];
                        $data = ['filename' => $matches[1], 'line' => $matches[2], 'message' => $msg];
                        if (preg_match('/^.*error:.+$/i', $msg)) {
                            $errors[] = $data;
                            $last = 'error';
                        } else {
                            if (preg_match('/^.*warning:.+$/i', $msg)) {
                                $warnings[] = $data;
                                $last = 'warning';
                            }
                        }
                    }
                }

                if ($this->showWarnings && $warningCount > 0) {
                    $this->log($file . ': ' . $warningCount . ' warnings detected', Project::MSG_WARN);
                    foreach ($warnings as $warning) {
                        $this->log(
                            '- line ' . $warning['line'] . (isset($warning['column']) ? ' column ' . $warning['column'] : '') . ': ' . $warning['message'],
                            Project::MSG_WARN
                        );
                    }
                    $this->hasWarnings = true;
                }

                if ($errorCount > 0) {
                    $this->log($file . ': ' . $errorCount . ' errors detected', Project::MSG_ERR);
                    if (!isset($this->badFiles[$file])) {
                        $this->badFiles[$file] = [];
                    }

                    foreach ($errors as $error) {
                        $message = 'line ' . $error['line'] . (isset($error['column']) ? ' column ' . $error['column'] : '') . ': ' . $error['message'];
                        $this->log('- ' . $message, Project::MSG_ERR);
                        $this->badFiles[$file][] = $message;
                    }
                    $this->hasErrors = true;
                } else {
                    if (!$this->showWarnings || $warningCount == 0) {
                        $this->log($file . ': No syntax errors detected', Project::MSG_VERBOSE);

                        if ($this->cache) {
                            $this->cache->put($file, filemtime($file));
                        }
                    }
                }
            } else {
                throw new BuildException('Permission denied: ' . $file);
            }
        } else {
            throw new BuildException('File not found: ' . $file);
        }
    }
873456
protected function _loadConfig($file) {
        $suffix = pathinfo($file, PATHINFO_EXTENSION);
        $suffix = ($suffix === 'dist') ?
                    pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION) : $suffix;
        if ($suffix == 'ini') {
            $config = Garp_Config_Ini::getCached($file, $this->getEnvironment())->toArray();
        } else {
            $config = parent::_loadConfig($file);
        }
        return $config;
    }