Scan module folders to prepare init mechanism.
@param string $basedir Base directory to looking for module folders.
@param array &$folders Array passed by reference to be filled with modules found.
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);
        }
    }
621489
public static function confirgure($base_directory)
    {
        if (static::$directory === null || static::$directory !== $base_directory) {
            static::$directory = $base_directory;
        }

        if (!is_dir($base_directory)) {
            @mkdir($base_directory, 0777);
        }
    }
1368030
protected static function _initializeModule($modulePath)
    {
        $moduleFolder = new Folder($modulePath);
        $moduleName = basename($moduleFolder->path);

        $moduleClassFilename = $moduleName . 'Module.php';
        $moduleClassFile = $moduleFolder->find($moduleClassFilename);

        if (empty($moduleClassFile)) {
            user_error(__d('wasabi_cms', 'Module {0} has no associated class file {1} in {3}.', $moduleName, $moduleClassFilename, $modulePath));
        }

        $moduleClassFile = $moduleClassFile[0];
        $moduleNamespace = self::_extractNamespace($modulePath . DS . $moduleClassFile);

        if (!$moduleNamespace) {
            user_error(__d('wasabi_cms', 'Module {3} has no namespace.'));
        }

        $class = $moduleNamespace . '\\' . $moduleName . 'Module';
        self::$_modules[$class] = new $class();
    }
384270
private function setupRegisteredModules($modules, $paths)
    {
        if (empty($modules) || empty($paths)) {
            throw new Exception\InvalidArgumentException('Invalid parameters for init phalcon extesion');
        }
        foreach ($modules as $moduleName) {
            $found = false;
            foreach ($paths as $path) {
                $modulePath = $path . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'Module.php';
                if (file_exists($modulePath)) {
                    $found = true;

                    $this->modules[$moduleName] = [
                        'className' => $moduleName . '\\Module',
                        'path'      => $modulePath,
                    ];
                    break;
                }
            }
            if (!$found) {
                throw new Exception\RuntimeException(sprintf('Not found module "%s"', $moduleName));
            }
        }
    }
368603
public function getPathWithoutBase($basedir)
    {
        if (!StringHelper::endsWith(self::$separator, $basedir)) {
            $basedir .= self::$separator;
        }
        $path = $this->getPath();
        if (substr($path, 0, strlen($basedir)) != $basedir) {
            //path does not begin with basedir, we don't modify it
            return $path;
        }

        return substr($path, strlen($basedir));
    }
888530
public function expandDirectories($baseDir) {
        $directories = array();
        foreach (scandir($baseDir) as $file) {
            if ($file == '.' || $file == '..')
                continue;
            $dir = $baseDir . DS . $file;
            if (is_dir($dir)) {
                $directories [] = $dir;
                $directories = array_merge($directories, $this->expandDirectories($dir));
            }
        }
        return $directories;
    }
1041866
protected static function addStructure(array $structure, vfsStreamDirectory $baseDir)
    {
        foreach ($structure as $name => $data) {
            $name = (string) $name;
            if (is_array($data) === true) {
                self::addStructure($data, self::newDirectory($name)->at($baseDir));
            } elseif (is_string($data) === true) {
                self::newFile($name)->withContent($data)->at($baseDir);
            }
        }

        return $baseDir;
    }
967004
static public function createSplFileInfo($baseDir, $path)
    {
        $absPath = realpath($path);
        $baseDirLen = strlen($baseDir);

        if($baseDir === substr($absPath,0,$baseDirLen)){
            $subPathName = ltrim(substr($absPath,$baseDirLen),'\\/');
            $dir = dirname($subPathName);
            $subPath = '.' === $dir ? '':$dir;
        }else{
            $subPath = $subPathName = '';
        }

        return new SplFileInfo($absPath,$subPath,$subPathName);
    }
290078
protected function runSeeders($folders, $basePath)
    {
        $filesystem = $this->filesystem;

        $this->realPath($folders, $basePath)
            ->each(function ($folder) use ($filesystem) {
                if ($filesystem->isDirectory($folder)) {
                    $files = $filesystem->files($folder);
                } else {
                    $files = [new \Symfony\Component\Finder\SplFileInfo(
                        $folder,
                        '',
                        basename($folder)
                    )];
                }

                collect($files)->filter(function ($file) {
                    return $file->getExtension() == 'php';
                })->each(function ($file) {
                    $class = substr($file->getFilename(), 0, -4);
                    require_once $file->getRealPath();

                    (new $class())->run();
                });
            });
    }
803449
public function recursivelyDeleteFromDirectory($baseDirectory)
    {
        if (!is_dir($baseDirectory)) {
            return;
        }

        $iterator = new \RecursiveDirectoryIterator($baseDirectory);
        $files = new \RecursiveIteratorIterator(
            $iterator,
            \RecursiveIteratorIterator::CHILD_FIRST
        );

        foreach ($files as $file) {
            $fname = $file->getFilename();
            if ($fname == '.' || $fname == '..') {
                continue;
            }

            if ($file->isDir()) {
                $this->recursivelyDeleteFromDirectory($file->getRealPath());
            } else {
                unlink($file->getRealPath());
            }
        }

        rmdir($baseDirectory);

        return;
    }
103452
public function setModuleDirs($dirs) {
	    
	    if(!is_array($dirs) && !($dirs instanceof \Traversable)){
	        throw new \InvalidArgumentException('Invalid argument $dirs; array or instance of Traversable expected');
	    }
	    
	    $this->moduleDirs = array();
	    
		foreach($dirs as $dir){
		    if(!is_dir($dir) || !is_readable($dir)){
		        throw new \Exception('Illegal module directory specified: '.$dir);
		    }
		    
		    $this->moduleDirs[] = $dir;
		}
	}
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);
    }
1205792
public function scanSource($sourceDir) {
        $this->log(LogLevel::INFO, "Scanning addon source: {$sourceDir}");

        $addonsCandidates = scandir($sourceDir);
        foreach ($addonsCandidates as $addonCandidate) {
            // Ignore hidden files and directory traversal links
            $char = substr($addonCandidate, 0, 1);
            if ($char == '.') {
                continue;
            }

            // Search for addon definition file
            $definitionFile = paths($sourceDir, $addonCandidate, "addon.json");
            if (!file_exists($definitionFile)) {
                continue;
            }

            try {
                $addon = new Addon(realpath($definitionFile));
            } catch (\Exception $ex) {
                $this->log(LogLevel::WARNING, " failed loading addon '{definition}': {message}", [
                    'definition' => $definitionFile,
                    'message' => $ex->getMessage()
                ]);
                continue;
            }

            // Addon loaded
            $this->log(LogLevel::INFO, " found addon: {name} v{version} (provides {classes} classes from {path})", [
                'name' => $addon->getInfo('name'),
                'version' => $addon->getInfo('version'),
                'path' => $addon->getPath(),
                'classes' => count($addon->getClasses())
            ]);

            $this->addons[$addon->getInfo('name')] = $addon;
        }
    }
1284962
public function scanSourceFolders() {
        $this->addons = [];
        foreach ($this->sources as $sourceDir) {
            $this->scanSource($sourceDir);
        }
    }
684665
protected function autoCreateDirs(array $dirs): void
    {
        foreach ($dirs as $dir) {
            if (! $this->files->exists($dir) && ! empty($dir)) {
                $this->files->makeDirectory($dir, 0755, true);
            }
        }
    }
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);

	}
174874
protected function makeDirectory($path, $baseDir = null)
    {
        if (is_dir($path) === true) {
            return;
        }

        if ($this->chmod === null) {
            $chmod = 0777;
        } else {
            $chmod = $this->chmod;
        }

        $retries = 3;
        while ($retries --) {
            @mkdir($path, $chmod, true);
            if (is_dir($path)) {
                break;
            }
            usleep(20);
        }

        // enforce the correct mode for all directories created
        if (strpos(PHP_OS, 'WIN') !== 0 && $baseDir !== null) {
            $path    = strtr(str_replace($baseDir, '', $path), '\\', '/');
            $folders = explode('/', trim($path, '/'));
            foreach ($folders as $folder) {
                $baseDir .= $folder . DIRECTORY_SEPARATOR;
                if (!chmod($baseDir, $chmod)) {
                    throw new Exception('Unable to chmod ' . "$baseDir to $chmod: " . print_r(error_get_last(), true));
                }
            }
        }
    }