Get all configuration data of selected file
@param string $configFile
@return array|null
352418
public function getAll($configFile = 'default'): ?array
    {
        $this->load($configFile);
        if (!Any::isArray($this->data) || !array_key_exists($configFile, $this->data)) {
            return null;
        }

        return $this->data[$configFile];
    }
73170
public function load($configFileName = null)
    {
        $configs = [];

        // load all local configs (config files that are not user-facing)
        $localConfig = [];
        foreach ($this->localConfigStack as $file) {
            $config = include $file;
            $localConfig = array_merge_recursive($localConfig, $config);
        }
        if (!empty($localConfig)) {
            $configs[] = $localConfig;
        }

        // load the current project's config file (user-facing)
        if (null === $configFileName) {
            $configFileName = $this->defaultFileName;
        }
        if ($this->projectFileSystem->has($configFileName)) {
            $configs[] = Yaml::parse($this->projectFileSystem->read($configFileName));
        }

        // validate and merge all configs
        $config = $this->processor->processConfiguration(
            $this->definition,
            $configs
        );

        return new $this->configClass($config);
    }
334479
public function getConfig($configKey = null)
    {
        $default = clone $this->config->configs->default;

        if (null !== $configKey) {
            $default->merge(clone $this->config->configs->{$configKey});
        }

        return $default->toArray();
    }
1288136
public static function fromFile($configFile)
    {
        if (false === FileIO::exists($configFile)) {
            throw new ConfigException(sprintf('unable to read "%s"', $configFile));
        }

        return new self(require $configFile);
    }
632752
public function GetConfigFileContents()
	{
		if (!$this->configFileContents)
		{
			// get rid of windows-style carriage returns
			$this->configFileContents = str_replace("\r\n", "\n", file_get_contents($this->configFilePath) );
		}
		
		return $this->configFileContents;
	}
1140996
public function updateConfig(string $configFile, array $newData, ?bool $mergeDeep = false): bool
    {
        $this->load($configFile);
        if (!isset($this->data[$configFile])) {
            return false;
        }

        $oldData = $this->data[$configFile];
        $saveData = ($mergeDeep ? Arr::mergeRecursive($oldData, $newData) : Arr::merge($oldData, $newData));
        return $this->writeConfig($configFile, $saveData);
    }
206585
public function readProjectConfigFile($dir, $configFile)
    {
        $result = null;
        $filename = $dir . '/' . $this->config->get('service.project_config_dir') . '/' . $configFile;
        if (file_exists($filename)) {
            $parser = new Parser();
            $result = $parser->parse(file_get_contents($filename));
        }

        return $result;
    }
104247
protected function preloadConfiguration($configFile)
    {
        try {
            Configuration::config($configFile);
        } catch (ConfigurationException $e) {
            if ($e->getCode() == 404) {
                throw new ConfigurationException("Your configuration file `{$configFile}` could not be found.", 405);
            }
            throw $e;
        }
    }
1144098
public static function readConfigFile($file = self::DEFAULT_CONFIG_FILE)
    {
        if (!is_string($file)) {
            throw new InvalidArgumentException('The config file path must be a string, type passed "'.gettype($file).'".');
        }

        $baseDir = realpath(dirname($file));
        $searchDirs = array(
            $baseDir.'/',
            $baseDir.'/../',
            $baseDir.'/../../',
            $baseDir.'/config/',
            $baseDir.'/../config/',
            $baseDir.'/../../config/'
        );

        $filename = basename($file);

        $configFile = null;
        foreach ($searchDirs as $dir) {
            if (realpath($dir.$filename) and is_readable($dir.$filename)) {
                $configFile = realpath($dir.$filename);
                break;
            }
        }

        if (is_null($configFile) and $file !== self::DEFAULT_CONFIG_FILE) {
            throw new InvalidArgumentException('The config file "'.$file.'" cannot be found or read.');
        }

        if (!$configFile) {
            return static::$config;
        }

        // Try to parse the contents
        try {
            $yaml = Yaml\Yaml::parse(file_get_contents($configFile));
        } catch (Yaml\Exception\ParseException $e) {
            throw new Exception('Unable to parse the config file: '.$e->getMessage());
        }

        return static::$config = $yaml;
    }
84790
private function getSettings()
    {
        $rootPath = $this->complement['path']['root'];
        $configFile = $rootPath . 'config/';

        if (is_dir($configFile) && $handle = scandir($configFile)) {
            $files = array_slice($handle, 2);

            foreach ($files as $file) {
                $content = require $configFile . $file;
                $merge = array_merge($this->complement, $content);
                $this->complement = $merge;
            }
        }

        $this->complement['path']['root'] = $rootPath;
        $this->complement['path']['config'] = $configFile;
    }
232875
private function parseFile($configFilePath) {
		$configFileText = file_get_contents ( $configFilePath );
		
		// Now split each line on carriage return
		$lines = explode ( "\n", $configFileText );
		
		// Now loop through each line, attempting a split by equals sign to get key value pairs out.
		foreach ( $lines as $line ) {
			
			// Firstly split lines on # to ensure that comments are ignored
			$splitComment = explode ( "#", $line );
			
			$propertyLine = trim ( $splitComment [0] );
			
			//  if the first entry is zero length when trimmed we know the line is a comment so we ignore the whole line
			// Otherwise continue and use the bit before any potential comment
			if (strlen ( $propertyLine ) > 0) {
				
				// Now split into key, value on =
				$positionOfFirstEquals = strpos ( $propertyLine, "=" );
				
				// If there are not 2 or more array entries at this point we should complain unless we meet a blank line.
				if ($positionOfFirstEquals) {
					$this->parameters [trim ( substr ( $propertyLine, 0, $positionOfFirstEquals ) )] = trim ( substr ( $propertyLine, $positionOfFirstEquals + 1 ) );
				} else {
					throw new Exception ( "Error in config file: Parameter '" . $propertyLine . "' Does not have a value" );
				}
			
			}
		}
	}
969635
public static function loadSettings($iniFile)
    {
        if (!file_exists($iniFile)) {
            throw new \Genesis\Exceptions\InvalidArgument(
                'The provided configuration file is invalid or inaccessible!'
            );
        }

        $settings = parse_ini_file($iniFile, true);

        foreach ($settings['Genesis'] as $option => $value) {
            if (array_key_exists($option, self::$vault)) {
                self::$vault[$option] = $value;
            }
        }

        foreach ($settings['Interfaces'] as $option => $value) {
            if (array_key_exists($option, self::$interfaces)) {
                self::$interfaces[$option] = $value;
            }
        }
    }
1316766
public static function getInstance($configFile = null, $mode = self::APP_MODE_PROD) {
        $c = get_called_class();
        if (!isset(self::$_instances[$c])) {
            // Create an instance
            self::$_instances[$c] = new $c($configFile, $mode);
            // Setup application
            self::$_instances[$c]->setup();
        }

        return self::$_instances[$c];
    }
117896
private function readConfigFile()
    {
        // reading the config file to be stored in the 'configurations' variable below
        $configurations = $this->config_reader->get('api');
        $this->mappers_base_namespace = $configurations['mappers'];
        $this->limit = $configurations['limit'];
    }
592021
private function loadXmlFile(string $configFile): array
    {
        $xml = simplexml_load_file($configFile);
        $configArr = [];

        if (isset($xml->name)) {
            $configArr['name'] = (string) $xml->name;
        }

        if (isset($xml->database['name'])) {
            $configArr['database'] = (string) $xml->database['name'];
        }

        if (isset($xml->collection['name'])) {
            $configArr['collection_name'] = (string) $xml->collection['name'];
        }

        if (isset($xml->{'migrations-namespace'})) {
            $configArr['migrations_namespace'] = (string) $xml->{'migrations-namespace'};
        }

        if (isset($xml->{'migrations-directory'})) {
            $configArr['migrations_directory'] = (string) $xml->{'migrations-directory'};
        }

        if (isset($xml->{'migrations-script-directory'})) {
            $configArr['migrations_script_directory'] = (string) $xml->{'migrations-script-directory'};
        }

        if (isset($xml->migrations->migration)) {
            foreach ($xml->migrations->migration as $migration) {
                $configArr['migrations'][] = [
                    'version' => $migration['version'],
                    'class' => $migration['class'],
                ];
            }
        }

        return $configArr;
    }
372118
public static function init($configFile = null)
    {
        if (!version_compare(PHP_VERSION, '5.6.0', '>=')) {
            Daemon::log('PHP >= 5.6.0 required.');
            return;
        }

        //run without composer
        if (!function_exists('setTimeout')) {
            require 'PHPDaemon/Utils/func.php';
        }

        Daemon::initSettings();
        FileSystem::init();
        Daemon::$runName = basename($_SERVER['argv'][0]);

        $error = false;
        $argv = $_SERVER['argv'];
        $runmode = isset($argv[1]) ? str_replace('-', '', $argv[1]) : '';
        $args = Bootstrap::getArgs($argv);

        if (!isset(self::$params[$runmode]) && !in_array($runmode, self::$commands)) {
            if ('' !== $runmode) {
                echo('Unrecognized command: ' . $runmode . "\n");
            }

            self::printUsage();
            exit;
        } elseif ('help' === $runmode) {
            self::printHelp();
            exit;
        }

        $n = null;
        if ('log' === $runmode) {
            if (isset($args['n'])) {
                $n = $args['n'];
                unset($args['n']);
            } else {
                $n = 20;
            }
        }

        if (isset($configFile)) {
            Daemon::$config->configfile->setHumanValue($configFile);
        }
        if (isset($args['configfile'])) {
            Daemon::$config->configfile->setHumanValue($args['configfile']);
        }

        if (!Daemon::$config->loadCmdLineArgs($args)) {
            $error = true;
        }

        if (!Daemon::loadConfig(Daemon::$config->configfile->value)) {
            $error = true;
        }

        if ('log' === $runmode) {
            passthru('tail -n ' . $n . ' -f ' . escapeshellarg(Daemon::$config->logstorage->value));
            exit;
        }

        if (extension_loaded('apc') && ini_get('apc.enabled')) {
            Daemon::log('Detected pecl-apc extension enabled. Usage of bytecode caching (APC/eAccelerator/xcache/...)  makes no sense at all in case of using phpDaemon \'cause phpDaemon includes files just in time itself.');
        }

        if (isset(Daemon::$config->locale->value) && Daemon::$config->locale->value !== '') {
            setlocale(LC_ALL, array_map('trim', explode(',', Daemon::$config->locale->value)));
        }

        if (Daemon::$config->autoreimport->value && !is_callable('runkit_import')) {
            Daemon::log('[WARN] runkit extension not found. You should install it or disable --auto-reimport. Non-critical error.');
        }

        if (!is_callable('posix_kill')) {
            Daemon::log('[EMERG] Posix not found. You should compile PHP without \'--disable-posix\'.');
            $error = true;
        }

        if (!is_callable('pcntl_signal')) {
            Daemon::log('[EMERG] PCNTL not found. You should compile PHP with \'--enable-pcntl\'.');
            $error = true;
        }

        if (extension_loaded('libevent')) {
            Daemon::log('[EMERG] libevent extension found. You have to remove libevent.so extension.');
            $error = true;
        }

        $eventVer = '1.6.1';
        $eventVerType = 'stable';
        if (!Daemon::loadModuleIfAbsent('event', $eventVer . '-' . $eventVerType)) {
            Daemon::log('[EMERG] event extension >= ' . $eventVer . ' not found (or OUTDATED). You have to install it. `pecl install http://pecl.php.net/get/event`');
            $error = true;
        }

        if (!is_callable('socket_create')) {
            Daemon::log('[EMERG] Sockets extension not found. You should compile PHP with \'--enable-sockets\'.');
            $error = true;
        }

        if (!is_callable('shmop_open')) {
            Daemon::log('[EMERG] Shmop extension not found. You should compile PHP with \'--enable-shmop\'.');
            $error = true;
        }

        if (!isset(Daemon::$config->user)) {
            Daemon::log('[EMERG] You must set \'user\' parameter.');
            $error = true;
        }

        if (!isset(Daemon::$config->path)) {
            Daemon::log('[EMERG] You must set \'path\' parameter (path to your application resolver).');
            $error = true;
        }

        if (!file_exists(Daemon::$config->pidfile->value)) {
            if (!touch(Daemon::$config->pidfile->value)) {
                Daemon::log('[EMERG] Couldn\'t create pid-file \'' . Daemon::$config->pidfile->value . '\'.');
                $error = true;
            }

            Bootstrap::$pid = 0;
        } elseif (!is_file(Daemon::$config->pidfile->value)) {
            Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be a regular file.');
            Bootstrap::$pid = false;
            $error = true;
        } elseif (!is_writable(Daemon::$config->pidfile->value)) {
            Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be writable.');
            $error = true;
        } elseif (!is_readable(Daemon::$config->pidfile->value)) {
            Daemon::log('Pid-file \'' . Daemon::$config->pidfile->value . '\' must be readable.');
            Bootstrap::$pid = false;
            $error = true;
        } else {
            Bootstrap::$pid = (int)file_get_contents(Daemon::$config->pidfile->value);
        }

        if (Daemon::$config->chroot->value !== '/') {
            if (posix_getuid() != 0) {
                Daemon::log('You must have the root privileges to change root.');
                $error = true;
            }
        }

        $pathList = preg_split('~\s*;\s*~', Daemon::$config->path->value);
        $found = false;
        foreach ($pathList as $path) {
            if (@is_file($path)) {
                Daemon::$appResolverPath = $path;
                $found = true;
                break;
            }
        }
        if (!$found) {
            Daemon::log('Your application resolver \'' . Daemon::$config->path->value . '\' is not available (config directive \'path\').');
            $error = true;
        }

        Daemon::$appResolver = require Daemon::$appResolverPath;

        if (isset(Daemon::$config->group->value) && is_callable('posix_getgid')) {
            if (($sg = posix_getgrnam(Daemon::$config->group->value)) === false) {
                Daemon::log('Unexisting group \'' . Daemon::$config->group->value . '\'. You have to replace config-variable \'group\' with existing group-name.');
                $error = true;
            } elseif (($sg['gid'] != posix_getgid()) && (posix_getuid() != 0)) {
                Daemon::log('You must have the root privileges to change group.');
                $error = true;
            }
        }

        if (isset(Daemon::$config->user->value) && is_callable('posix_getuid')) {
            if (($su = posix_getpwnam(Daemon::$config->user->value)) === false) {
                Daemon::log('Unexisting user \'' . Daemon::$config->user->value . '\', user not found. You have to replace config-variable \'user\' with existing username.');
                $error = true;
            } elseif (($su['uid'] != posix_getuid()) && (posix_getuid() != 0)) {
                Daemon::log('You must have the root privileges to change user.');
                $error = true;
            }
        }

        if (isset(Daemon::$config->minspareworkers->value)
            && Daemon::$config->minspareworkers->value > 0
            && isset(Daemon::$config->maxspareworkers->value)
            && Daemon::$config->maxspareworkers->value > 0
        ) {
            if (Daemon::$config->minspareworkers->value > Daemon::$config->maxspareworkers->value) {
                Daemon::log('\'minspareworkers\' cannot be greater than \'maxspareworkers\'.');
                $error = true;
            }
        }

        if (isset(Daemon::$config->addincludepath->value)) {
            ini_set(
                'include_path',
                ini_get('include_path') . ':' . implode(':', Daemon::$config->addincludepath->value)
            );
        }

        if (isset(Daemon::$config->minworkers->value) && isset(Daemon::$config->maxworkers->value)) {
            if (Daemon::$config->minworkers->value > Daemon::$config->maxworkers->value) {
                Daemon::$config->minworkers->value = Daemon::$config->maxworkers->value;
            }
        }

        if ($runmode === 'start') {
            if ($error === false) {
                Bootstrap::start();
            } else {
                exit(6);
            }
        } elseif ($runmode === 'runworker') {
            if ($error === false) {
                Bootstrap::runworker();
            } else {
                exit(6);
            }
        } elseif ($runmode === 'status' || $runmode === 'fullstatus') {
            $status = Bootstrap::$pid && Thread\Generic::ifExistsByPid(Bootstrap::$pid);
            echo '[STATUS] phpDaemon ' . Daemon::$version . ' is ' . ($status ? 'running' : 'NOT running') . ' (' . Daemon::$config->pidfile->value . ").\n";

            if ($status && ($runmode === 'fullstatus')) {
                echo 'Uptime: ' . DateTime::diffAsText(filemtime(Daemon::$config->pidfile->value), time()) . "\n";

                Daemon::$shm_wstate = new ShmEntity(Daemon::$config->pidfile->value, Daemon::SHM_WSTATE_SIZE, 'wstate');

                $stat = Daemon::getStateOfWorkers();

                echo "State of workers:\n";
                echo "\tTotal: " . $stat['alive'] . "\n";
                echo "\tIdle: " . $stat['idle'] . "\n";
                echo "\tBusy: " . $stat['busy'] . "\n";
                echo "\tShutdown: " . $stat['shutdown'] . "\n";
                echo "\tPre-init: " . $stat['preinit'] . "\n";
                echo "\tInit: " . $stat['init'] . "\n";
            }

            echo "\n";
        } elseif ($runmode === 'update') {
            if ((!Bootstrap::$pid) || (!posix_kill(Bootstrap::$pid, SIGHUP))) {
                echo '[UPDATE] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
            }
        } elseif ($runmode === 'reopenlog') {
            if ((!Bootstrap::$pid) || (!posix_kill(Bootstrap::$pid, SIGUSR1))) {
                echo '[REOPEN-LOG] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
            }
        } elseif ($runmode === 'reload') {
            if ((!Bootstrap::$pid) || (!posix_kill(Bootstrap::$pid, SIGUSR2))) {
                echo '[RELOAD] ERROR. It seems that phpDaemon is not running' . (Bootstrap::$pid ? ' (PID ' . Bootstrap::$pid . ')' : '') . ".\n";
            }
        } elseif ($runmode === 'restart') {
            if ($error === false) {
                Bootstrap::stop(2);
                Bootstrap::start();
            }
        } elseif ($runmode === 'hardrestart') {
            Bootstrap::stop(3);
            Bootstrap::start();
        } elseif ($runmode === 'ipcpath') {
            $i = Daemon::$appResolver->getInstanceByAppName('\PHPDaemon\IPCManager\IPCManager');
            echo $i->getSocketUrl() . PHP_EOL;
        } elseif ($runmode === 'configtest') {
            $term = new Terminal;
            $term->enableColor();

            echo "\n";

            $rows = [];

            $rows[] = [
                'parameter' => 'PARAMETER',
                'value' => 'VALUE',
                '_color' => '37',
                '_bold' => true,
            ];

            foreach (Daemon::$config as $name => $entry) {
                if (!$entry instanceof Generic) {
                    continue;
                }

                $row = [
                    'parameter' => $name,
                    'value' => var_export($entry->humanValue, true),
                ];

                if ($entry->defaultValue != $entry->humanValue) {
                    $row['value'] .= ' (' . var_export($entry->defaultValue, true) . ')';
                }

                $rows[] = $row;
            }

            $term->drawtable($rows);

            echo "\n";
        } elseif ($runmode === 'stop') {
            Bootstrap::stop();
        } elseif ($runmode === 'gracefulstop') {
            Bootstrap::stop(4);
        } elseif ($runmode === 'hardstop') {
            echo '[HARDSTOP] Sending SIGINT to ' . Bootstrap::$pid . '... ';

            $ok = Bootstrap::$pid && posix_kill(Bootstrap::$pid, SIGINT);

            echo $ok ? 'OK.' : 'ERROR. It seems that phpDaemon is not running.';

            if ($ok) {
                $i = 0;

                while ($r = Thread\Generic::ifExistsByPid(Bootstrap::$pid)) {
                    usleep(500000);

                    if ($i === 9) {
                        echo "\nphpDaemon master-process hasn't finished. Sending SIGKILL... ";
                        posix_kill(Bootstrap::$pid, SIGKILL);
                        sleep(0.2);
                        if (!Thread\Generic::ifExistsByPid(Bootstrap::$pid)) {
                            echo " Oh, his blood is on my hands :'(";
                        } else {
                            echo "ERROR: Process alive. Permissions?";
                        }

                        break;
                    }

                    ++$i;
                }
            }

            echo "\n";
        }
    }
501830
public OptionsBuilder configurationFile(String configFile) {
		if (configFile != null) {
			options.put(Options.CONFIGURATION_FILE, new File(configFile));
		} else {
			options.remove(Options.CONFIGURATION_FILE);
		}
		return this;
	}