Rewrite the config file with a complete list of plugins.

@param string $configFile The path to the config file.
@param array $plugins Of plugins.
@param string|null $root The root directory. Defaults to a value generated from $configFile.

@return void
961358
public static function writeConfigFile($configFile, $plugins, $root = null)
    {
        $root = $root ?: dirname(dirname($configFile));

        $data = [];
        foreach ($plugins as $name => $pluginPath) {
            // Normalize to *nix paths.
            $pluginPath = str_replace('\\', '/', $pluginPath);
            $pluginPath .= '/';

            $pluginPath = str_replace(
                DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
                DIRECTORY_SEPARATOR,
                $pluginPath
            );

            // Namespaced plugins should use /
            $name = str_replace('\\', '/', $name);

            $data[] = sprintf("        '%s' => '%s'", $name, $pluginPath);
        }

        $data = implode(",\n", $data);

        $contents = <<<'PHP'
<?php
$baseDir = dirname(dirname(__file__));
return [
    'plugins' => [
%s
    ]
];
PHP;
        $contents = sprintf($contents, $data);

        // Gross hacks to work around composer smashing `__FILE__` in this
        // PHP file when it runs the code through eval()
        $uppercase = function ($matches) {
            return strtoupper($matches[0]);
        };
        $contents = preg_replace_callback('/__file__/', $uppercase, $contents);

        $root = str_replace(
            DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
            DIRECTORY_SEPARATOR,
            $root
        );

        // Normalize to *nix paths.
        $root = str_replace('\\', '/', $root);
        $contents = str_replace('\'' . $root, '$baseDir . \'', $contents);

        file_put_contents($configFile, $contents);
    }
1073639
protected function registerConfigFiles()
    {
        if (isset($this->dir) and isset($this->configFiles) and is_array($this->configFiles)) {
            foreach ($this->configFiles as $key) {
                $path = $this->getConfigFilePath($key);
                //$this->mergeConfigFrom($this->getConfigFilePath($filename), $filename);
                $config = $this->app->make('config')->get($key, [ ]);
                $this->app->make('config')->set($key, array_replace_recursive(require $path, $config));
            }
        }
    }
82520
public function ClearCache($ConfigFile) {
      $FileKey = sprintf(Gdn_Configuration::CONFIG_FILE_CACHE_KEY, $ConfigFile);
      if (Gdn::Cache()->Type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::Cache()->ActiveEnabled()) {
         Gdn::Cache()->Remove($FileKey,array(
             Gdn_Cache::FEATURE_NOPREFIX => TRUE
         ));
      }
   }
1175357
protected function registerConfigItems(ParentItem $root, $parentId, $configItems)
    {
        foreach ($configItems as $configId => $configItem) {
            $subItems = reset($configItem);
            $path = $parentId . '/' . $configId;
            $configPath = str_replace("admin/server/config/",'', $path);
            $translationKey = 'expansion_config.menu.' . implode('.', explode('/', $configPath)) . '.label';

            if (is_array($subItems)) {
                $root->addChild(
                    ParentItem::class,
                    $path,
                    $translationKey,
                    null
                );

                $this->registerConfigItems($root, $path, $configItem);
            } else {
                $root->addChild(
                    ChatCommandItem::class,
                    $path,
                    $translationKey,
                    'admin_config', // Default config on each element.
                    ['cmd' => '/admin config "' . $configPath . '"']
                );
            }
        }
    }
56942
public function createConfigFile($toFile)
    {
        if (file_exists($toFile)) {
            $this->getOutput()->debug('Config file already exists in plugin, skipping creation of config file.');

            return;
        }
        if (!$this->configDumper->hasConfig()) {
            $this->getOutput()->debug('No config to write out, skipping creation of config file.');

            return;
        }
        $this->configDumper->dump($toFile);
        $this->getOutput()->debug('Created config file at '.$toFile);
    }
790798
public function connect($nameDB = NULL, $configFile = NULL){
        if($configFile != NULL){
            $this->configFile= $configFile;
            self::$config_db= NULL;
        }
        $this->connection= $this->getConnection($nameDB);
    }
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;
        }
    }
193533
public function modify(SplFileInfo $generatedFile, SplFileInfo $templateFile, array $modifiers, Inflector $inflector)
    {
        foreach ($modifiers as $modifierAlias => $modifierData) {
            if ($modifier = $this->contentModifiers->get($modifierAlias)) {
                $this->filesystem->dumpFile(
                    $generatedFile->getRealPath(),
                    $modifier->modify(
                        $generatedFile,
                        is_array($modifierData) ? $modifierData : array(),
                        $inflector,
                        $templateFile
                    )
                );
            }
        }
    }
1094252
public static function toFile($configFile, array $configData, $mode = 0600)
    {
        $fileData = sprintf('<?php return %s;', var_export($configData, true));
        FileIO::writeFile($configFile, $fileData, $mode);
    }
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";
        }
    }
527919
public function readConfig($configFile) {
        $yamlParser   = new \Symfony\Component\Yaml\Parser();
        $userConfPath = ROOT . DS . 'app' . DS . 'config' . DS . 'modules' . DS . $configFile;
        $userCustomPath = ROOT. DS . 'app'. DS.'modules'.DS.$configFile;
        $composerConfPath = ROOT . DS . 'modules' . DS . $configFile;
        $libConfPath  = ROOT_LIB . DS . 'src' . DS . 'modules' . DS . $configFile;
        if (file_exists($userConfPath)) {
            $confPath = $userConfPath;
        } elseif (file_exists($userCustomPath)) {
            $confPath = $userCustomPath;
        } elseif (file_exists($composerConfPath)) {
            $confPath = $composerConfPath;
        } elseif (file_exists($libConfPath)) {
            $confPath = $libConfPath;
        } else {
            throw new ModuleException ("Module configuration file not found!");
        }

        try {
            $conf = $yamlParser->parse(file_get_contents($confPath));
        } catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
            throw new ModuleException("Unable to parse module configuration
                                            file for AutomaticHeaderFooter module: " . $e->getMessage());
        }
        return $conf;
    }
74345
protected function bootConfigFiles($configFiles = null, $path = null)
    {
        if ($configFiles === null) {
            $configFiles = $this->configFiles;
        }
        if (!is_array($configFiles)) {
            $configFiles = [$configFiles];
        }
        if (isset($this->rootDir, $configFiles)) {
            foreach ($configFiles as $fileName) {
                $filePath = $path === null ? $this->resolvePath('configPath') : path_join($path, $fileName);
                $this->publishes([$filePath => config_path($fileName.'.php')], 'config');
            }
        }
    }
529782
def plugins_path
      if site.config["plugins_dir"].eql? Bunto::Configuration::DEFAULTS["plugins_dir"]
        [site.in_source_dir(site.config["plugins_dir"])]
      else
        Array(site.config["plugins_dir"]).map { |d| File.expand_path(d) }
      end
    end
1115475
public function reload($defaultSettingsFiles = array(), $userSettingsFile = null)
    {
        if (!empty($defaultSettingsFiles)
            || !empty($userSettingsFile)
        ) {
            $this->resetSettingsChain($defaultSettingsFiles, $userSettingsFile);
        }

        $reader = new IniReader();
        foreach ($this->settingsChain as $file => $ignore) {
            if (is_readable($file)) {
                try {
                    $contents = $reader->readFile($file);
                    $this->settingsChain[$file] = $this->decodeValues($contents);
                } catch (IniReadingException $ex) {
                    throw new IniReadingException('Unable to read INI file {' . $file . '}: ' . $ex->getMessage() . "\n Your host may have disabled parse_ini_file().");
                }

                $this->decodeValues($this->settingsChain[$file]);
            }
        }

        $merged = $this->mergeFileSettings();
        // remove reference to $this->settingsChain... otherwise dump() or compareElements() will never notice a difference
        // on PHP 7+ as they would be always equal
        $this->mergedSettings = $this->copy($merged);
    }
1015242
public static void writeConfigFile(File configFile, File searchDir) throws SQLException, IOException {
		writeConfigFile(configFile, searchDir, false);
	}
185215
public function setupPlugin(array $config = []): void
	{
		if (!$this->defaults) return;
		$this->setupConfig($this->defaults, $config);
	}
1018368
public final void load(final File fDirectory) throws PluginConfigurationException {
        File[] vFiles = fDirectory.listFiles();
        if (vFiles != null) {
            for (File f : vFiles) {
                if (f.isDirectory()) {
                    configurePlugins(f);
                }
            }
        }
    }