returns a finder that iterates all bundle directories

@param string $baseDir the base dir to search

@return Finder|null finder or null if basedir does not exist
516851
private function getBundleFinder($baseDir)
    {
        $bundleBaseDir = $baseDir.self::BUNDLE_NAMESPACE;

        if (!(new Filesystem())->exists($bundleBaseDir)) {
            return null;
        }

        $bundleFinder = new Finder();
        $bundleFinder->directories()->in($bundleBaseDir)->depth('== 0')->notName('BundleBundle');

        return $bundleFinder;
    }
717524
public function getFiles() {
        $dir = $this->getDirOutput();
        $finder = new \Symfony\Component\Finder\Finder();
        $finder->files()->in($dir);
        return $finder;
    }
1013327
public function getBaseDir()
    {
        if (($sValue = $this->getViewConfigParam('basedir')) === null) {
            if ($this->getConfig()->isSsl()) {
                $sValue = $this->getConfig()->getSSLShopURL();
            } else {
                $sValue = $this->getConfig()->getShopURL();
            }

            $this->setViewConfigParam('basedir', $sValue);
        }

        return $sValue;
    }
1015370
private function _searchInControllerDir($base_dir, $file_name)
    {
        $dirs = $this->application->getControllerDirectories();
        foreach ($dirs as $dir) {
            $filter = $this->finder->path($dir . $base_dir)->name($file_name)->find()->first();
            if ($filter) return $filter;
        }
    }
1116177
protected function find($directory)
    {
        if ($iterator = parent::find($directory)) {
            foreach ($iterator as $file) {
                if (is_file($file) && is_readable($file) && $contents = file_get_contents($file)) {
                    if (preg_match($this->packageNamePattern, basename($file))) {
                        $plugin = (object) null;
                        $plugin->name = implode('_v', array_slice(explode('_v', basename($file, '.txt')), 0, -1));
                        $this->plugin[] = $plugin;
                        $this->package[] = $contents;
                    }
                }
            }
        }

        return !empty($this->plugin);
    }
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");
		
	}
857343
public function scanDir()
    {
        // only possible in directories
        if (!$this->isDir() || !$this->exists()) {
            return null;
        }

        $fileList = [];
        $fileNameList = scandir($this->absoluteFileName);
        foreach ($fileNameList as $fileName) {
            // do not add . and ..
            if ($fileName === "." or $fileName === "..") {
                continue;
            }
            $absoluteFileName = $this->absoluteFileName . "/" . $fileName;
            $fileList [] = new File ($absoluteFileName);
        }

        return $fileList;
    }
699674
@VisibleForTesting
    URI getBaseDir() {
        URI baseDir = job.getInputDir();

        final Collection<FileInfo> fis = job.getFileInfo();
        for (final FileInfo fi : fis) {
            final URI res = fi.result.resolve(".");
            baseDir = Optional.ofNullable(getCommonBase(baseDir, res)).orElse(baseDir);
        }

        return baseDir;
    }
8243
private function scanModuleFolders($basedir, &$folders)
    {
        if (is_dir($basedir) && ($h = opendir($basedir))) {
            while (($folder = readdir($h))) {
                if ($folder !== '.' && $folder !== '..') {
                    $this->scanModuleFiles($basedir . DIRECTORY_SEPARATOR . $folder, $folders);
                }
            }
            closedir($h);
        }
    }
1100306
private function makeFinder(array $directories = [], array $exclude = []): Finder
    {
        $finder = new Finder();

        if (empty($directories)) {
            $directories = $this->config->getDirectories();
        }

        if (empty($exclude)) {
            $exclude = $this->config->getExcludes();
        }

        return $finder->files()->in($directories)->exclude($exclude)->name('*.php');
    }
1245333
private function scanModuleFiles($basedir, &$folders)
    {
        if (is_dir($basedir) && ($h = opendir($basedir))) {
            while (($filename = readdir($h))) {
                $phpfile = $basedir . DIRECTORY_SEPARATOR . $filename;
                if (preg_match('/^init[_|-](.+)\.php$/', $filename) && file_exists($phpfile) && filesize($phpfile) > 0) {
                    $folders[] = $phpfile;
                }
            }
            closedir($h);
        }
    }
1152803
public function findClassFile($class,$baseDir = null)
    {
        $baseDir = is_null($baseDir) ? getcwd():$baseDir;

        $file = $this->mainLoader->findFile($class);
        if (is_file($file)) {
            $spl = PathUtil::createSplFileInfo($baseDir,$file);

            return $spl;
        }

        return false;
    }
710540
public static DirectoryRosterStore init(final File baseDir) {
        DirectoryRosterStore store = new DirectoryRosterStore(baseDir);
        if (store.setRosterVersion("")) {
            return store;
        }
        else {
            return null;
        }
    }
136967
public function getFinder()
    {
        if (null === $this->finder) {
            $this->finder = new Finder();
            $this->finder->files();
        }

        return $this->finder;
    }
691786
public static File locateFile(String name, String basedir) {
    // Try exact match first.
    File f = new File(name);
    if(f.exists()) {
      return f;
    }
    // Try with base directory
    if(basedir != null) {
      if((f = new File(basedir, name)).exists()) {
        return f;
      }
    }
    // try stripping whitespace
    String name2;
    if(!name.equals(name2 = name.trim())) {
      if((f = locateFile(name2, basedir)) != null) {
        return f;
      }
    }
    // try substituting path separators
    if(!name.equals(name2 = name.replace('/', File.separatorChar))) {
      if((f = locateFile(name2, basedir)) != null) {
        return f;
      }
    }
    if(!name.equals(name2 = name.replace('\\', File.separatorChar))) {
      if((f = locateFile(name2, basedir)) != null) {
        return f;
      }
    }
    // try stripping extra characters, such as quotes.
    if(name.length() > 2 && name.charAt(0) == '"' && name.charAt(name.length() - 1) == '"') {
      if((f = locateFile(name.substring(1, name.length() - 1), basedir)) != null) {
        return f;
      }
    }
    return null;
  }
1185774
public function getDirectoriesIterator()
    {
        if (array() !== ($directories = $this->getDirectories())) {
            return Finder::create()
                    ->files()
                    ->filter($this->getBlacklistFilter())
                    ->ignoreVCS(true)
                    ->in($directories);
        }

        return null;
    }
678254
private InputStream findCukedoctorProperties(String baseDir) {
        List<String> files = FileUtil.findFiles(baseDir,"cukedoctor.properties",true);
        if(files != null && !files.isEmpty()){
            String path = files.get(0);
            log.fine("Loading cukedoctor resource bundle from: " + path);
            File file = new File(path);
            try {
                return new FileInputStream(file);
            } catch (Exception e) {
                log.log(Level.WARNING, "Could not load resource bundle from target folder", e);
            }
        }
        return null;
    }