Searches up a folder hierarchy for the most immediate config.

@throws ConfigException
@return ?string
180492
public static function locateConfigFile(string $path)
    {
        $dir_path = realpath($path);

        if ($dir_path === false) {
            throw new ConfigException('Config not found for path ' . $path);
        }

        if (!is_dir($dir_path)) {
            $dir_path = dirname($dir_path);
        }

        do {
            $maybe_path = $dir_path . DIRECTORY_SEPARATOR . Config::DEFAULT_FILE_NAME;

            if (file_exists($maybe_path) || file_exists($maybe_path .= '.dist')) {
                return $maybe_path;
            }

            $dir_path = dirname($dir_path);
        } while (dirname($dir_path) !== $dir_path);
        return null;
    }
194696
public function getConfigDirectory()
    {
        $directory = $this->baseDir.DIRECTORY_SEPARATOR.BundleInterface::CONFIG_DIRECTORY_NAME;
        if (false === is_dir($directory)) {
            $directory = $this->baseDir.DIRECTORY_SEPARATOR.BundleInterface::OLD_CONFIG_DIRECTORY_NAME;
        }

        return $directory;
    }
975242
protected function getConfigurationDirectory()
    {
        $reflector = new \ReflectionClass($this);
        $fileName = $reflector->getFileName();

        if (!is_dir($directory = dirname($fileName) . $this->configDirectory)) {
            throw new \RuntimeException(sprintf('The configuration directory "%s" does not exists.', $directory));
        }

        return $directory;
    }
642533
public function getRootFolderName()
    {
        if ($this->owner->NewsRootFolderID) {
            return str_replace(ASSETS_DIR . '/', '', $this->owner->NewsRootFolder()->getRelativePath());
        }

        return Config::inst()->get($this->class, 'uploads_folder');
    }
711764
public function getFilesystemFolder()
    {
        $config = Bootstrap::getSingleton()->getConfig();
        if (isset($config['app']['filesystem'])) {
            return Bootstrap::getSingleton()->getDirectory() . '/' . $config['app']['filesystem'];
        }
        return Bootstrap::getSingleton()->getDirectory() . '/filesystem';
    }
1297607
protected function _searchFiles()
    {
        $pattern = false;
        if (!empty($this->_exclude)) {
            $exclude = [];
            foreach ($this->_exclude as $e) {
                if (DIRECTORY_SEPARATOR !== '\\' && $e[0] !== DIRECTORY_SEPARATOR) {
                    $e = DIRECTORY_SEPARATOR . $e;
                }
                $exclude[] = preg_quote($e, '/');
            }
            $pattern = '/' . implode('|', $exclude) . '/';
        }
        foreach ($this->_paths as $path) {
            $path = realpath($path) . DIRECTORY_SEPARATOR;
            $Folder = new Folder($path);
            $files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
            if (!empty($pattern)) {
                $files = preg_grep($pattern, $files, PREG_GREP_INVERT);
                $files = array_values($files);
            }
            $this->_files = array_merge($this->_files, $files);
        }
        $this->_files = array_unique($this->_files);
    }
887407
protected static function getConfig()
    {
        if (static::$config) {
            return static::$config;
        }

        $config = Registry::get('config');
        if (!isset($config['log'])) {
            throw new ConfigException('log config not exists');
        }
        $config = $config['log'];

        if (!isset($config['level'])) {
            $config['level'] = 'info';
        }
        $config['level'] = isset(static::$logLevels[$config['level']])
            ? static::$logLevels[$config['level']]
            : Logger::INFO;

        if (!isset($config['channel'])) {
            $config['channel'] = static::$defaultChannel;
        }

        return static::$config = $config;
    }
426288
public function getConfigFile() : string
    {
        if (empty($this->configFile)) {
            $this->configFile = getcwd() . DIRECTORY_SEPARATOR . CH::CONFIG;
        }
        return $this->configFile;
    }
1304482
private function createIndex()
    {
        $basepath   = $this->config["basePath"];
        $pattern    = $this->config["pattern"];
        $path       = "$basepath/$pattern";

        $index = [];
        foreach (glob_recursive($path) as $file) {
            $filepath = substr($file, strlen($basepath) + 1);

            // Find content files
            $matches = [];
            preg_match($this->filenamePattern, basename($filepath), $matches);
            $dirpart = dirname($filepath) . "/";
            if ($dirpart === "./") {
                $dirpart = null;
            }
            $key = $dirpart . $matches[2];
            
            // Create level depending on the file id
            // TODO ciamge doc, can be replaced by __toc__ in meta?
            $id = (int) $matches[1];
            $level = 2;
            if ($id % 100 === 0) {
                $level = 0;
            } elseif ($id % 10 === 0) {
                $level = 1;
            }

            $index[$key] = [
                "file"     => $filepath,
                "section"  => $matches[1],
                "level"    => $level,  // TODO ?
                "internal" => $this->isInternalRoute($filepath),
                "tocable"  => $this->allowInToc($filepath),
            ];
        }

        return $index;
    }
1359569
public function get_project_config_path() {
		$config_files = array(
			'wp-cli.local.yml',
			'wp-cli.yml',
		);

		// Stop looking upward when we find we have emerged from a subdirectory
		// installation into a parent installation
		$project_config_path = Utils\find_file_upward(
			$config_files,
			getcwd(),
			function ( $dir ) {
				static $wp_load_count = 0;
				$wp_load_path         = $dir . DIRECTORY_SEPARATOR . 'wp-load.php';
				if ( file_exists( $wp_load_path ) ) {
					++ $wp_load_count;
				}
				return $wp_load_count > 1;
			}
		);

		$this->project_config_path_debug = 'No project config found';

		if ( ! empty( $project_config_path ) ) {
			$this->project_config_path_debug = 'Using project config: ' . $project_config_path;
		}

		return $project_config_path;
	}
67243
public function getConfigPath()
    {
        if (null == $this->configPath) {
            $this->configPath = getcwd().'/Configuration';
            Configuration::addPath($this->configPath);
        }
        return $this->configPath;
    }
879297
function getLocalConfig(thisConfig, directory) {
  var found,
    i,
    localConfig,
    localConfigFile,
    config = {},
    localConfigFiles = thisConfig.findLocalConfigFiles(directory),
    numFiles = localConfigFiles.length,
    rootPath,
    projectConfigPath = path.join(process.cwd(), LOCAL_CONFIG_FILENAME);

  for (i = 0; i < numFiles; i++) {

    localConfigFile = localConfigFiles[i];

        // Don't consider the personal config file in the home directory,
        // except if the home directory is the same as the current working directory
    if (localConfigFile === PERSONAL_CONFIG_PATH && localConfigFile !== projectConfigPath) {
      continue;
    }

        // If root flag is set, don't consider file if it is above root
    if (rootPath && !pathIsInside(path.dirname(localConfigFile), rootPath)) {
      continue;
    }

    localConfig = loadConfig(localConfigFile);

        // Don't consider a local config file found if the config is empty.
    if (!Object.keys(localConfig).length) {
      continue;
    }

        // Check for root flag
    if (localConfig.root === true) {
      rootPath = path.dirname(localConfigFile);
    }

    found = true;
    config = util.mergeConfigs(localConfig, config);
  }

    // Use the personal config file if there are no other local config files found.
  return found ? config : util.mergeConfigs(config, getPersonalConfig());
}
1234862
protected function scanLoadConfig(): void
    {
        /* @var SplFileInfo $directory */
        /* @var SplFileInfo $file */
        foreach (Finder::create()->directories()->depth(1)->name('Config')->in($this->modulePath()) as $directory) {
            foreach (Finder::create()->files()->name('*.php')->in($directory->getPathname()) as $file) {
                $this->mergeConfigFrom($file->getPathname(), Str::snake($directory->getRelativePath()));
            }
        }
    }
782140
public function getConfigFilesSorted()
    {
        $fileSystem = new Filesystem();

        $projectConfig = $fileSystem->glob(app_path('hc-config.json'));
        $packageConfigs = $fileSystem->glob(__DIR__ . '/../../../../*/*/*/hc-config.json');

        $packageConfigs = $this->sortByPriority($packageConfigs);

        $files = array_merge($packageConfigs, $projectConfig);

        return $files;
    }
741328
public function find(): self
    {
        $preparedPaths = \array_unique(
            \array_merge(
                $this->getPreparedPaths((array) $this->paths['psr0']),
                $this->getPreparedPaths((array) $this->paths['psr4']),
                $this->getPreparedPaths((array) $this->paths['classmap'])
            ),
            \SORT_STRING
        );

        $finder = Finder::create()
            ->files()
            ->in($preparedPaths)
            ->exclude($this->excludes)
            ->name('*.php')
            ->sortByName();

        if ($this->filter !== null) {
            $finder->filter($this->filter);
        }

        /** @var \SplFileInfo $file */
        foreach ($finder as $file) {
            $realPath  = (string) $file->getRealPath();

            $namespace = null;
            $tokens    = \token_get_all((string) \file_get_contents($realPath));

            foreach ($tokens as $key => $token) {
                if (\is_array($token)) {
                    if ($token[0] === \T_NAMESPACE) {
                        $namespace = self::getNamespace($key + 2, $tokens);
                    } elseif ($token[0] === \T_INTERFACE) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->interfaces[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_TRAIT) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->traits[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    } elseif ($token[0] === \T_ABSTRACT) {
                        $name = self::getName($key + 4, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->abstractClasses[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;

                        continue 2;
                    } elseif ($token[0] === \T_CLASS) {
                        $name = self::getName($key + 2, $tokens);

                        if ($name === null) {
                            continue 2;
                        }

                        $this->classes[\ltrim($namespace . '\\' . $name, '\\')] = $realPath;
                    }
                }
            }

            unset($tokens);
            // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
            \gc_mem_caches();
        }

        return $this;
    }
674454
public function locateRootDirectory()
    {
        $vendorDirectoryName = 'vendor';
        $fileDirectory    = __DIR__;
        $searchDirectories = [
            __DIR__.'/..',
            __DIR__.'/../..',
            __DIR__.'/../../..',
            __DIR__.'/../../../..',
            __DIR__.'/../../../../..'
        ];

        $fileSystem = $this->createNew(FileSystem::class);
        foreach ($searchDirectories as $searchDirectory) {
            if ($fileSystem->fileExists($searchDirectory . '/' . $vendorDirectoryName)) {
                return $fileSystem->getRealPath($searchDirectory);
            }
        }

        throw new FileSystemException('No application root directory found');
    }
26964
public function configHierarchical($key = null)
    {
        $config = [];
        $all = $this->config($key);
        if (! is_array($all)) $all = array($key => $all);
        foreach ($all as $_key => $_val) {
            $keys = explode('.', $_key);
            $value = &$config;
            while ($key = array_shift($keys)) {
                if ($keys) {
                    if (! isset($value[$key])) $value[$key] = [];
                    $value = &$value[$key];
                } else {
                    $value[$key] = $_val;
                }
            }
        }
        return $config;
    }