Create a ConfigBag.

@param string $rootPath
@param string $configFilePath

@return ConfigBagInterface
321941
public function create(string $rootPath, string $configFilePath): ConfigBagInterface
    {
        $file = $this->resolvePath($rootPath, $configFilePath);

        $envs = $this->parseMainFile($file);
        $envs = $this->mergeExternalFiles($file, $envs);

        return ConfigBag::root(
            $envs,
            $this->getEnvironment(),
            $rootPath
        );
    }
441583
public function addGlobPath($globPath) {
    foreach(glob($globPath, GLOB_BRACE) as $definitionFile) {
      $this->addDefinitions($definitionFile);
    }
    return $this;
  }
710828
public static function connectWithWordPress($rootPath = '/')
  {
    include_once $rootPath.'wp-config.php';
    self::$cnxHandler = new MySql(DB_HOST, DB_USER, DB_PASSWORD, 5432, DB_NAME);
    return self::$cnxHandler->connect();
  }
51739
protected function createBackupFile($filePath)
    {
        $sourcePath = $filePath;
        $backupPath = $filePath.'.bak';

        if (file_exists($backupPath))
        {
            $date = new \DateTime();
            $backupPath = "{$filePath}{$date->getTimestamp()}.bak";
        }

        copy($sourcePath, $backupPath);
    }
397016
final private static function getDirectoryStructureDo($relativePath, $rootDirectory, $exclude3rdParty)
    {
        $thisRoot = $rootDirectory;
        if ($relativePath !== '') {
            $thisRoot .= '/'.$relativePath;
        }
        $subDirs = array();
        $hDir = @opendir($thisRoot);
        if ($hDir === false) {
            throw new \Exception("Unable to open directory $rootDirectory");
        }
        while (($entry = @readdir($hDir)) !== false) {
            if ($entry[0] === '.') {
                continue;
            }
            $fullPath = $thisRoot.'/'.$entry;
            if (!is_dir($fullPath)) {
                continue;
            }
            if ($exclude3rdParty) {
                if (($entry === 'vendor') || preg_match('%/libraries/3rdparty$%', $fullPath)) {
                    continue;
                }
            }
            $subDirs[] = $entry;
        }
        @closedir($hDir);
        $result = array();
        foreach ($subDirs as $subDir) {
            $rel = ($relativePath === '') ? $subDir : "$relativePath/$subDir";
            $result = array_merge($result, static::getDirectoryStructureDo($rel, $rootDirectory, $exclude3rdParty));
            $result[] = $rel;
        }

        return $result;
    }
818712
public function create($basePath)
	{
		$parts = explode('.', $this->loadVersion($basePath)->getShortVersion());
		while (!empty($parts))
		{
			$version = implode('Dot', $parts);
			$classname = __NAMESPACE__ . '\\Joomla' . $version . 'Driver';
			if (class_exists($classname))
			{
				return new $classname;
			}
			array_pop($parts);
		}
		throw new \RuntimeException('No driver found');
	}
1369925
protected function buildAppConfig($configPath)
    {
        $config = require($configPath);

        $callback = Arr::get($this->config, 'callback.vendor_config');
        if ($callback instanceof Closure) {
            $config = call_user_func($callback, $config);
        }

        return $config;
    }
1257720
public function setRootDir($rootPath = false)
    {
        if (!$rootPath) {
            $this->rootDir = getcwd().DS;
        }

        $this->rootDir = $rootPath.DS;

        return $this;
    }
233337
public function init(string $configPath): self
    {
        defined('INTERVAL') or define('INTERVAL', 10000);
        defined('SAW_DIR') or define('SAW_DIR', __DIR__);
        $config = array_merge(
            require __DIR__ . '/../config/saw.php',
            require $configPath
        );
        // todo include config
        foreach (['saw', 'factory', 'daemon', 'sockets', 'application', 'controller'] as $check) {
            if (!isset($config[$check]) || !is_array($config[$check])) {
                $config[$check] = [];
            }
        }
        if (isset($config['saw']['debug'])) {
            self::$debug = (bool)$config['saw']['debug'];
        }

        $initScript = __DIR__ . '/../bin/cli.php';
        if (!isset($config['controller_starter'])) {
            $config['controller_starter'] = <<<CMD
-r "require_once '{$initScript}';
\Maestroprog\Saw\Saw::instance()
    ->init('{$configPath}')
    ->instanceController()
    ->start();"
CMD;
        }
        if (!isset($config['worker_starter'])) {
            $config['worker_starter'] = <<<CMD
-r "require_once '{$initScript}';
\Maestroprog\Saw\Saw::instance()
    ->init('{$configPath}')
    ->instanceWorker()
    ->start();"
CMD;
        }

        $this->container = Container::instance();
        $this->container->register($this->sawContainer = new SawContainer(
            $this->config = $config,
            $this->daemonConfig = new DaemonConfig($config['daemon'], $configPath),
            $this->config = new Configurator($config['sockets']),
            $this->controllerConfig = new ControllerConfig($config['controller']),
            SawEnv::web()
        ));
        $this->container->register(new MemoryContainer());

        $this->applicationLoader = new ApplicationLoader(
            new ApplicationConfig($config['application']),
            new ApplicationFactory($this->container)
        );

        if (!self::$debug) {
            set_exception_handler(function (\Throwable $exception) {
                if ($exception instanceof \Exception) {
                    switch ($exception->getCode()) {
                        case self::ERROR_WRONG_CONFIG:
                            echo $exception->getMessage();
                            exit($exception->getCode());
                    }
                }
            });
        }

        /*$compiler = new ContainerCompiler($this->container);
        $compiler->compile('build/container.php');*/

        return $this;
    }
129878
public static function create($classPath) {

        if ( !isset(self::$INSTANES[$classPath]) ) {
            $reflect = new \ReflectionClass($classPath);
            $instance = $reflect->newInstance();
            $instance->initConfigs();
            self::$INSTANES[$classPath] = $instance;
        }
        return self::$INSTANES[$classPath];
    }
455153
private function parseAggregations(\DOMXPath $xpath, \DOMNode $rootNode)
    {
        $aggs = [];

        foreach ($xpath->query(self::AGGREGATIONS_PATH, $rootNode) as $aggNode) {
            $bucketName   = $aggNode->getAttribute('name');
            $bucketConfig = [];

            foreach ($aggNode->attributes as $attribute) {
                $bucketConfig[$attribute->name] = $attribute->value;
            }
            $aggFilters = $this->parseAggregationFilters($xpath, $aggNode);
            if (!empty($aggFilters)) {
                $bucketConfig['filters'] = $aggFilters;
            }
            $bucketConfig['childBuckets'] = $this->parseAggregations($xpath, $aggNode);
            $bucketConfig['metrics'] = $this->parseMetrics($xpath, $aggNode);
            $bucketConfig['pipelines'] = $this->parsePipelines($xpath, $aggNode);
            $aggs[$bucketName] = $bucketConfig;
        }

        return $aggs;
    }
899905
public function setBasePath($basePath)
    {
        $this['path.app'] = rtrim($basePath);

        foreach (['config', 'views', 'logs'] as $v) {
            $this['path.' . $v] = realpath(rtrim($basePath) . '/' . $v) . DIRECTORY_SEPARATOR;
        }

        $this['namespace.controller'] = '';

        return $this;
    }
883036
public static JNRPEConfiguration createConfiguration(final String configurationFilePath) throws ConfigurationException {
        JNRPEConfiguration conf = null;

        if (configurationFilePath.toLowerCase().endsWith(".conf") || configurationFilePath.toLowerCase().endsWith(".ini")) {
            conf = new IniJNRPEConfiguration();
        } else if (configurationFilePath.toLowerCase().endsWith(".xml")) {
            conf = new XmlJNRPEConfiguration();
        }

        if (conf == null) {
            throw new ConfigurationException("Config file name must end with either '.ini' " 
                                + "(ini file) or '.xml' (xml file). Received file name is : " + new File(configurationFilePath).getName());
        }

        conf.load(new File(configurationFilePath));

        return conf;
    }
360460
public static function fromPhp($configFilePath)
    {
        ob_start();
        /** @noinspection PhpIncludeInspection */
        $configArray = include($configFilePath);

        // Hide console output
        ob_end_clean();

        if (!is_array($configArray)) {
            throw new \RuntimeException(sprintf(
                'PHP file \'%s\' must return an array',
                $configFilePath
            ));
        }

        return new static($configArray, $configFilePath);
    }
1284625
protected function getConfigurationFilesInPath($configPath)
    {
        $files = [];

        if (! is_dir($configPath)) {
            return $files;
        }

        foreach (Finder::create()->files()->name('*.php')->depth(0)->in($configPath) as $file) {
            $files[$file->getBasename('.php')] = $file->getRealPath();
        }

        ksort($files, SORT_NATURAL);

        return $files;
    }
421878
protected function createThumbnail($imagePath, $thumbnailPath) {
        if ($this->config['images']['thumbnail']['enabled'] === true) {
            Log::info('generating thumbnail "' . $thumbnailPath . '"');

            // create folder if it does not exist
            if (!file_exists(dirname($thumbnailPath))) {
                mkdir(dirname($thumbnailPath), 0755, true);
            }

            $this->initUploader([
                'upload_dir' => dirname($imagePath) . '/',
            ])->create_thumbnail_image($imagePath);
        }
    }
741559
protected function registerConfigFiles($configFiles = null, $path = null)
    {
        if ($configFiles === null) {
            $configFiles = $this->configFiles;
        }
        if (!is_array($configFiles)) {
            $configFiles = [$configFiles];
        }
        if (null !== $this->getRootDir() && null !== $configFiles) {
            $path = $path ?: $this->resolvePath('configPath');
            foreach ($configFiles as $key) {
                call_user_func_array([$this, $this->configStrategy], [path_join($path, $key.'.php'), $key]);
            }
        }
    }