Returns an array of YAML files in the directory.

@param string $basedir The base directory

@return array

@throws \BackBee\Config\Exception\InvalidBaseDirException Occurs if the base directory cannont be read
549228
private function getYmlFiles($basedir)
    {
        $ymlFiles = File::getFilesByExtension($basedir, self::EXTENSION);

        $defaultFile = $basedir.DIRECTORY_SEPARATOR.self::CONFIG_FILE.'.'.self::EXTENSION;

        if (is_file($defaultFile) && 1 < count($ymlFiles)) {
            // Ensure that config.yml is the first one
            $ymlFiles = array_diff($ymlFiles, array($defaultFile));
            array_unshift($ymlFiles, $defaultFile);
        }

        foreach ($ymlFiles as &$file) {
            $name = basename($file);
            if (in_array(substr($name, 0, strrpos($name, '.')), $this->yml_names_to_ignore)) {
                $file = null;
            }
        }

        return array_filter($ymlFiles);
    }
547675
public function getBaseDirectory($directoryToAppend = null)
    {
        $baseDirectory = $this->getNamingDirectory()->search('php:env/baseDirectory');
        if ($directoryToAppend != null) {
            $baseDirectory .= $directoryToAppend;
        }
        return $baseDirectory;
    }
888284
public static function loadConfig($base_dir)
	{
		$config_defaults = json_decode(file_get_contents(__DIR__.'/../config.json.php'), TRUE);
		if (!$config_defaults) {
			throw new \Exception('Default config file is broken.');
		}
		$config_app = json_decode(file_get_contents($base_dir.'/config.app.json.php'), TRUE);
		if (!$config_app) {
			throw new \Exception('App config file is broken.');
		}
		if (file_exists($base_dir.'/config.local.json.php')) {
			$config_local = json_decode(file_get_contents($base_dir.'/config.local.json.php'), TRUE);
			if (!$config_local) {
				throw new \Exception('Local config file is broken.');
			}
		} else {
			$config_local = [];
		}
		return array_replace_recursive($config_defaults, $config_app, $config_local);
	}
949954
protected function getFiles($basePath, $path = null, &$files = array())
    {
        if (! is_dir($path))
            return null;
        if (substr($path, strlen($path) - 1) != '/')
            $path .= '/';
        $handle = opendir($path);
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..') {
                $path2 = $path . $file;
                if (is_dir($path2)) {
                    $this->getFiles($basePath, $path2, $files);
                } else {
                    $extension = strtolower(substr(strrchr($file, '.'), 1));
                    if (in_array($extension, $this->accept)) {
                        $files[] = array(
                            'object' => $this->normalizeWebPath($path2)
                        );
                    }
                }
            }
        }
        return $files;
    }
486091
private function loadFromBaseDir($basedir, $overwrite = false)
    {
        foreach ($this->getYmlFiles($basedir) as $filename) {
            $this->loadFromFile($filename, $overwrite);
        }
    }
993448
public function getDirectoryParts(): array
    {
        return $this->myAboveBaseLevel === 0 ? $this->myDirectoryParts : array_merge(array_fill(0, $this->myAboveBaseLevel, '..'), $this->myDirectoryParts);
    }
267620
private function getConfigDirByBundleBaseDir($baseDir)
    {
        $directory = $baseDir.DIRECTORY_SEPARATOR.BundleInterface::CONFIG_DIRECTORY_NAME;
        if (!is_dir($directory)) {
            $directory = $baseDir.DIRECTORY_SEPARATOR.BundleInterface::OLD_CONFIG_DIRECTORY_NAME;
        }

        return $directory;
    }
877035
public static function init($baseDir = "", $verbose = true) {
		
		// make sure a base dir was supplied
		if (empty($baseDir)) {
			Console::writeError("need a base directory to initialize the config class...");
		}
		
		// normalize the baseDir
		$baseDir = FileUtil::normalizePath($baseDir);
		
		// double-check the default config file exists
		if (!is_dir($baseDir)) {
			Console::writeError("make sure ".$baseDir." exists...");
		}
		
		// set the baseDir option
		self::$options["baseDir"] = ($baseDir[strlen($baseDir)-1] == DIRECTORY_SEPARATOR) ? $baseDir : $baseDir.DIRECTORY_SEPARATOR;
		
		// set-up the paths
		self::$userConfigDirClean  = self::$options["baseDir"].self::$userConfigDirClean;
		self::$userConfigDirDash   = self::$options["baseDir"].self::$userConfigDirDash;
		self::$userConfigDir       = (is_dir(self::$userConfigDirDash)) ? self::$userConfigDirDash : self::$userConfigDirClean;
		self::$userConfigPath      = self::$userConfigDir.DIRECTORY_SEPARATOR.self::$userConfig;
		self::$plConfigPath        = self::$options["baseDir"]."vendor/pattern-lab/core/".self::$plConfigPath;
		
		// can't add __DIR__ above so adding here
		if (!is_dir(self::$userConfigDir)) {
			mkdir(self::$userConfigDir);
		}
		
		// check to see if the user config exists, if not create it
		if ($verbose) {
			Console::writeLine("configuring pattern lab...");
		}
		
		// make sure migrate doesn't happen by default
		$migrate        = false;
		$diffVersion    = false;
		$defaultOptions = array();
		$userOptions    = array();
		
		// double-check the default config file exists
		if (!file_exists(self::$plConfigPath)) {
			Console::writeError("the default options for Pattern Lab don't seem to exist at <path>".Console::getHumanReadablePath(self::$plConfigPath)."</path>. please check on the install location of pattern lab...");
		}
		
		// set the default config using the pattern lab config
		try {
			$defaultOptions = Yaml::parse(file_get_contents(self::$plConfigPath));
			self::$options  = array_merge(self::$options, $defaultOptions);
		} catch (ParseException $e) {
			Console::writeError("Config parse error in <path>".Console::getHumanReadablePath(self::$plConfigPath)."</path>: ".$e->getMessage());
		}
		
		// double-check the user's config exists. if not mark that we should migrate the default one
		if (file_exists(self::$userConfigPath)) {
			try {
				$userOptions   = Yaml::parse(file_get_contents(self::$userConfigPath));
				self::$options = array_merge(self::$options, $userOptions);
			} catch (ParseException $e) {
				Console::writeError("Config parse error in <path>".Console::getHumanReadablePath(self::$userConfigPath)."</path>: ".$e->getMessage());
			}
		} else {
			$migrate = true;
		}
		
		// compare version numbers
		$diffVersion = (isset($userOptions["v"]) && ($userOptions["v"] == $defaultOptions["v"])) ? false : true;
		
		// run an upgrade and migrations if necessary
		if ($migrate || $diffVersion) {
			if ($verbose) {
				Console::writeInfo("upgrading your version of pattern lab...");
			}
			if ($migrate) {
				if (!@copy(self::$plConfigPath, self::$userConfigPath)) {
					Console::writeError("make sure that Pattern Lab can write a new config to ".self::$userConfigPath."...");
					exit;
				}
			} else {
				self::$options = self::writeNewConfigFile(self::$options, $defaultOptions);
			}
		}
		
		// making sure the config isn't empty
		if (empty(self::$options) && $verbose) {
			Console::writeError("a set of configuration options is required to use Pattern Lab...");
			exit;
		}
		
		// set-up the various dirs
		self::$options["configDir"]        = self::$userConfigDir;
		self::$options["configPath"]       = self::$userConfigPath;
		self::$options["coreDir"]          = is_dir(self::$options["baseDir"]."_core") ? self::$options["baseDir"]."_core" : self::$options["baseDir"]."core";
		self::$options["exportDir"]        = isset(self::$options["exportDir"])        ? self::$options["baseDir"].self::cleanDir(self::$options["exportDir"])   : self::$options["baseDir"]."exports";
		self::$options["publicDir"]        = isset(self::$options["publicDir"])        ? self::$options["baseDir"].self::cleanDir(self::$options["publicDir"])   : self::$options["baseDir"]."public";
		self::$options["scriptsDir"]       = isset(self::$options["scriptsDir"])       ? self::$options["baseDir"].self::cleanDir(self::$options["scriptsDir"])  : self::$options["baseDir"]."scripts";
		self::$options["sourceDir"]        = isset(self::$options["sourceDir"])        ? self::$options["baseDir"].self::cleanDir(self::$options["sourceDir"])   : self::$options["baseDir"]."source";
		self::$options["componentDir"]     = isset(self::$options["componentDir"])     ? self::$options["publicDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["componentDir"]) : self::$options["publicDir"].DIRECTORY_SEPARATOR."patternlab-components";
		self::$options["dataDir"]          = isset(self::$options["dataDir"])          ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["dataDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_data";
		self::$options["patternExportDir"] = isset(self::$options["patternExportDir"]) ? self::$options["exportDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["patternExportDir"]) : self::$options["exportDir"].DIRECTORY_SEPARATOR."patterns";
		self::$options["patternPublicDir"] = isset(self::$options["patternPublicDir"]) ? self::$options["publicDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["patternPublicDir"]) : self::$options["publicDir"].DIRECTORY_SEPARATOR."patterns";
		self::$options["patternSourceDir"] = isset(self::$options["patternSourceDir"]) ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["patternSourceDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_patterns";
		self::$options["metaDir"]          = isset(self::$options["metaDir"])          ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["metaDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_meta/";
		self::$options["annotationsDir"]   = isset(self::$options["annotationsDir"])   ? self::$options["sourceDir"].DIRECTORY_SEPARATOR.self::cleanDir(self::$options["annotationsDir"]) : self::$options["sourceDir"].DIRECTORY_SEPARATOR."_annotations/";
		
		// set-up outputFileSuffixes
		self::$options["outputFileSuffixes"]["rendered"]    = isset(self::$options["outputFileSuffixes"]["rendered"])    ? self::$options["outputFileSuffixes"]["rendered"]    : '';
		self::$options["outputFileSuffixes"]["rawTemplate"] = isset(self::$options["outputFileSuffixes"]["rawTemplate"]) ? self::$options["outputFileSuffixes"]["rawTemplate"] : '';
		self::$options["outputFileSuffixes"]["markupOnly"]  = isset(self::$options["outputFileSuffixes"]["markupOnly"])  ? self::$options["outputFileSuffixes"]["markupOnly"]  : '.markup-only';
		
		// handle a pre-2.1.0 styleguideKitPath before saving it
		if (isset(self::$options["styleguideKitPath"])) {
			self::$options["styleguideKitPath"] = self::$options["baseDir"].self::cleanDir(self::getStyleguideKitPath(self::$options["styleguideKitPath"]));
		}
		
		// double-check a few directories are real and set-up
		FileUtil::checkPathFromConfig(self::$options["sourceDir"], self::$userConfigPath, "sourceDir");
		FileUtil::checkPathFromConfig(self::$options["publicDir"], self::$userConfigPath, "publicDir");
		
		// make sure styleguideExcludes is set to an array even if it's empty
		if (is_string(self::$options["styleGuideExcludes"])) {
			self::$options["styleGuideExcludes"] = array();
		}
		
		// set the cacheBuster
		self::$options["cacheBuster"] = (self::$options["cacheBusterOn"] == "false") ? 0 : time();
		
		// provide the default for enable CSS. performance hog so it should be run infrequently
		self::$options["enableCSS"] = false;
		
		// which of these should be exposed in the front-end?
		self::$options["exposedOptions"] = array();
		self::setExposedOption("cacheBuster");
		self::setExposedOption("defaultPattern");
		self::setExposedOption("defaultShowPatternInfo");
		self::setExposedOption("patternExtension");
		self::setExposedOption("ishFontSize");
		self::setExposedOption("ishMaximum");
		self::setExposedOption("ishMinimum");
		self::setExposedOption("ishViewportRange");
		self::setExposedOption("outputFileSuffixes");
		self::setExposedOption("patternStates");
		self::setExposedOption("theme");
		self::setExposedOption("plugins");
		
	}
946865
public static function create($configFile,$baseDir="",$userDir="",$extConfigs=[])
    {
        //配置文件
        $pathInfo=pathinfo($configFile);
        $_configFile=$pathInfo["dirname"]."/".$pathInfo["filename"];
        $phpConfigFile=$_configFile.".php";
        $xmlConfigFile=$_configFile.".xml";
        $_configFile=file_exists($phpConfigFile)?$phpConfigFile:$xmlConfigFile;
        if(!file_exists($_configFile)){
            throw new \Exception("Fail to load configuration file '".$configFile."'!");
        }

        //如果缓存存在,则直接返回实例
        $configKey=$_configFile;
        if(array_key_exists($configKey, self::$m_configs)){
            return self::returnConfig(self::$m_configs[$configKey],$baseDir,$userDir,$extConfigs);
        }

        //从php配置文件读取配置:如果php配置文件存在且修改时间大于所有的xml配置文件
        if(file_exists($phpConfigFile)){
            //从php读取配置
            $config=new PhpConfiguration($phpConfigFile);

            //如果xml配置文件不存在,则直接从php配置直接返回
            if(!file_exists($xmlConfigFile)){
                self::$m_configs[$configKey]=$config;
                return self::returnConfig($config,$baseDir,$userDir,$extConfigs);
            }

            //如果xml配置文件存在,则要检查文件最后修改时间
            $phpTime=filemtime($phpConfigFile);
            $overrided=false;
            foreach ($config->getConfigValues(self::$m_configFilesKey) as $f){
                if(file_exists($f) && filemtime($f) > $phpTime){
                    $overrided=true;
                }
            }

            //php文件较新且非调试模式下
            if(!$overrided && !self::$m_debug){
                self::$m_configs[$configKey]=$config;
                return self::returnConfig($config,$baseDir,$userDir,$extConfigs);
            }
        }

        //从xml配置读取配置,并持久化到php
        if(file_exists($xmlConfigFile)){
            $config=new XmlConfiguration($xmlConfigFile);
            self::$m_configs[$configKey]=$config;
            self::dump2PhpFile($config, $phpConfigFile);
        }

        //返回实例
        if(array_key_exists($configKey, self::$m_configs)){
            return self::returnConfig(self::$m_configs[$configKey],$baseDir,$userDir,$extConfigs);
        }
        return null;
    }
533423
protected function setUp($baseFileDir = null)
	{

		$locator = new FileLocator($baseFileDir);

		$resolver = new LoaderResolver(
			array(
				new PhpArrayFileLoader($locator),
				new JsonFileLoader($locator),
				new YamlFileLoader($locator)
			)
		);

		$this->fileLoader = new DelegatingLoader($resolver);

	}
85739
public function buildClasses($basedir, OutputInterface $output)
    {
        $target = $this->ensureBuildDir($basedir, $output);

        foreach ($this->getClasses() as $element) {
            $element->build($target, $output);
        }
    }
94949
protected static function secureEncode($basedir, $source)
    {
        $components = parse_url($source);
        if (!isset($components['scheme'])) {
            // relative path
            if (\tao_helpers_File::securityCheck($source, false)) {
                if (file_exists($basedir . $source)) {
                    return 'data:' . \tao_helpers_File::getMimeType($basedir . $source) . ';'
                        . 'base64,' . base64_encode(file_get_contents($basedir . $source));
                } else {
                    throw new \tao_models_classes_FileNotFoundException($source);
                }
            } else {
                throw new \common_exception_Error('Invalid source path "' . $source . '"');
            }
        } else {
            // url, just return it as is
            return $source;
        }
    }
966738
public function lintFileList($file_list) {
    $this->say("Linting YAML files...");

    $files = explode("\n", $file_list);

    /** @var \Acquia\Blt\Robo\Filesets\FilesetManager $fileset_manager */
    $fileset_manager = $this->getContainer()->get('filesetManager');
    $fileset_ids = $this->getConfigValue('validate.yaml.filesets');
    $filesets = $fileset_manager->getFilesets($fileset_ids);

    $bin = $this->getConfigValue('composer.bin');
    $command = "'$bin/yaml-cli' lint '%s'";
    foreach ($filesets as $fileset_id => $fileset) {
      $filesets[$fileset_id] = $fileset_manager->filterFilesByFileset($files, $fileset);
    }

    $this->executeCommandAgainstFilesets($filesets, $command);
  }
621487
public function scanParents(string $sourceDir): array
    {
        $locales = $this->scanLocales($sourceDir);
        $fallbacks = [];

        foreach ($locales as $locale) {
            $content = \file_get_contents($sourceDir.'/'.$locale.'.txt');

            // Aliases contain the text "%%PARENT" followed by the aliased locale
            if (\preg_match('/%%Parent{"([^"]+)"}/', $content, $matches)) {
                $fallbacks[$locale] = $matches[1];
            }
        }

        return $fallbacks;
    }
777648
protected function getDirectoryScanner(PhingFile $baseDir)
    {
        $this->fileset->setDir($baseDir);
        $this->fileset->setDefaultexcludes($this->useDefaultExcludes);

        return $this->fileset->getDirectoryScanner($this->project);
    }
615970
function getFiles(base, dir = '', results = []) {
            const files = fs.readdirSync(path.join(base, dir));
            for (const file of files) {
                const relativeToBase = path.join(dir, file);
                if (fs.statSync(path.join(base, relativeToBase)).isDirectory()) {
                    getFiles(base, relativeToBase, results);
                } else {
                    results.push(relativeToBase);
                }
            }
            return results;
        }
926250
private function _getRoots()
    {
        $directories = [];

        if (is_string($this->module->root)) {
            $root = Yii::getAlias($this->module->root);
            if ($this->module->scanRootParentDirectory) {
                $root = dirname($root);
            }

            $directories[] = $root;
        } elseif (is_array($this->module->root)) {
            foreach ($this->module->root as $root) {
                $directories[] = Yii::getAlias($root);
            }
        } else {
            throw new InvalidConfigException('Invalid `root` option value!');
        }

        return $directories;
    }