@param DirectoryPath $root
@param SplFileInfo   $splDirectory

@return Directory
499063
protected function buildDirectory(DirectoryPath $root, SplFileInfo $splDirectory = null)
    {
        $relativeDirectoryPath = '';
        if (null !== $splDirectory) {
            $relativeDirectoryPath = $splDirectory->getRelativePathName();
        }

        $directory = new Directory(
            $this->getBasePath()->toAbsoluteFileSystemString(),
            $root->toRelativeFileSystemString(),
            $relativeDirectoryPath . DIRECTORY_SEPARATOR
        );

        return $directory;
    }
286610
public static Path pathForFileInRoot(
            final File rootDir,
            final File file
    )
    {
        String filePath = file.getAbsolutePath();
        String rootPath = rootDir.getAbsolutePath();
        if (!filePath.startsWith(rootPath)) {
            throw new IllegalArgumentException("not a file in the root directory: " + file);
        }
        return pathForRelativeFilepath(filePath.substring(rootPath.length()));
    }
1207039
public function getRealPath($path, $rootDir)
    {
        if (!is_string($path)) {
            return false;
        }

        if ($this->isRelativePath($path)) {
            return realpath($rootDir . DIRECTORY_SEPARATOR . $path);
        }

        return realpath($path);
    }
810797
public function toAbsolutePath($path, $rootDir)
    {
        if (!is_string($path)) {
            return false;
        }

        if ($this->isRelativePath($path)) {
            return $rootDir . DIRECTORY_SEPARATOR . $path;
        }

        return $path;
    }
157266
private void createRepositoryDirectoryStructure(File rootDir) {
		this.objs = new File(rootDir, OBJECT_DIR);
		if (!objs.exists()) {
			if (!objs.mkdirs()) {
				throw new RuntimeException("Could not create dir: " + objs.getAbsolutePath());
			}
		}

		this.refs = new File(rootDir, REFERENCE_DIR);
		if (!refs.exists()) {
			if (!refs.mkdirs()) {
				throw new RuntimeException("Could not create dir: " + refs.getAbsolutePath());
			}
		}
	}
1305763
public function filterDirs( SplFileInfo $current ) {
		if ( $current->isDir() ) {
			if ( in_array( $current->getFilename(), $this->defaultIgnoredDirs ) ) {
				// Default ignored directories can be anywhere in the directory structure
				return false;
			} elseif ( in_array( $current->getRealPath(), $this->ignoredDirs ) ) {
				// Ignored dirs are relative to root, and stored as absolute paths
				return false;
			}
		}

		return true;
	}
442366
public function createDirectory($directory)
    {
        // create parent directory if needed
        $parent = dirname($directory);
        if (!$this->directoryExists($parent)) {
            $this->createDirectory($parent);
        }

        if (ftp_mkdir($this->connection(), $directory) === false) {
            throw new \RuntimeException(sprintf(
                'Could not create directory \'%s\'.',
                $directory
            ));
        }

        return true;
    }
226547
private function getDirectoryIterator(string $realPath): \SplHeap
    {
        $directoryIterator = new \RecursiveDirectoryIterator(
            $realPath,
            \RecursiveDirectoryIterator::SKIP_DOTS
        );
        $iterator          = new \RecursiveIteratorIterator(
            $directoryIterator,
            \RecursiveIteratorIterator::SELF_FIRST
        );

        return new class($iterator) extends \SplHeap
        {
            public function __construct(\RecursiveIteratorIterator $iterator)
            {
                foreach ($iterator as $item) {
                    $this->insert($item);
                }
            }

            /**
             * @param mixed $item1
             * @param mixed $item2
             *
             * @return int
             */
            protected function compare($item1, $item2): int
            {
                return strcmp((string)$item2->getRealPath(), (string)$item1->getRealPath());
            }
        };
    }
225381
protected function parseDirectoryDo(\Gettext\Translations $translations, $rootDirectory, $relativePath, $subParsersFilter, $exclude3rdParty)
    {
        $phpFiles = array();
        foreach (array_merge(array(''), $this->getDirectoryStructure($rootDirectory, $exclude3rdParty)) as $child) {
            $fullDirectoryPath = ($child === '') ? $rootDirectory : "$rootDirectory/$child";
            $contents = @scandir($fullDirectoryPath);
            if ($contents === false) {
                throw new \Exception("Unable to parse directory $fullDirectoryPath");
            }
            foreach ($contents as $file) {
                if ($file[0] !== '.') {
                    $fullFilePath = "$fullDirectoryPath/$file";
                    if (preg_match('/^(.*)\.php$/i', $file) && is_file($fullFilePath)) {
                        $phpFiles[] = ($child === '') ? $file : "$child/$file";
                    }
                }
            }
        }
        if (count($phpFiles) > 0) {
            if (\C5TL\Gettext::commandIsAvailable('xgettext')) {
                $newTranslations = static::parseDirectoryDo_xgettext($rootDirectory, $phpFiles);
            } else {
                $newTranslations = static::parseDirectoryDo_php($rootDirectory, $phpFiles);
            }
            if ($newTranslations->count() > 0) {
                if ($relativePath !== '') {
                    foreach ($newTranslations as $newTranslation) {
                        static::fixExtractedComments($newTranslation);
                        $references = $newTranslation->getReferences();
                        $newTranslation->deleteReferences();
                        foreach ($references as $reference) {
                            $newTranslation->addReference($relativePath.'/'.$reference[0], $reference[1]);
                        }
                        $translations[] = $newTranslation;
                    }
                } else {
                    foreach ($newTranslations as $newTranslation) {
                        static::fixExtractedComments($newTranslation);
                        $translations[] = $newTranslation;
                    }
                }
            }
        }
    }
1249106
public function getRealWritingFilePath($path, $rootDir)
    {
        $realDir = $this->getRealDir($path, $rootDir);

        if (!is_string($realDir)) {
            return false;
        }

        return $realDir . DIRECTORY_SEPARATOR . basename($path);
    }
127212
private function getDirectory($kernelRootDir, $pattern)
    {
        $firstCharacter = substr($pattern, 0, 1);
        if ('/' === $firstCharacter || DIRECTORY_SEPARATOR === $firstCharacter) {
            return $pattern;
        }

        return $kernelRootDir.DIRECTORY_SEPARATOR.$pattern;
    }
626376
public function parseFromString($ramlString, $rootDir)
    {
        $ramlData = $this->parseRamlString($ramlString, $rootDir);

        return $this->parseRamlData($ramlData, $rootDir);
    }
420374
protected function getNestedDirectory(SplFileInfo $file, $path)
    {
        $directory = $file->getPath();

        if ($nested = trim(str_replace($path, '', $directory), DIRECTORY_SEPARATOR)) {
            $nested = str_replace(DIRECTORY_SEPARATOR, '.', $nested).'.';
        }

        return $nested;
    }
1135607
static public function searchFile($root, $pattern = '*', $flags = 0)
    {
        $dirs = self::listDirs($root);
        array_unshift($dirs, $root);
        
        $foundFiles = [];
        
        foreach ($dirs as $dir) {
            $filePatt = $dir . '/' . $pattern;
            $files = glob($filePatt, $flags);
        
            if ($files) {
                $foundFiles = array_merge($foundFiles, $files);
            }
        }
        
        return $foundFiles;
    }
342741
protected function parseDirectoryDo(\Gettext\Translations $translations, $rootDirectory, $relativePath, $subParsersFilter, $exclude3rdParty)
    {
        switch ($relativePath) {
            case '':
                $directoryAlternatives = array('application/config/generated_overrides', 'application/config', 'concrete/config');
                break;
            case 'application':
                $directoryAlternatives = array('config/generated_overrides', 'config');
                break;
            case 'concrete':
                $directoryAlternatives = array('config');
                break;
            default:
                return;
        }
        $prefix = ($relativePath === '') ? '' : "$relativePath/";
        $this->parseFileTypes($translations, $rootDirectory, $prefix, $directoryAlternatives);
        $this->parseTranslatableStrings($translations, $rootDirectory, $prefix, $directoryAlternatives);
    }
409494
public function setRootDirectory($rootDir)
    {
        if ($this->started) {
            throw new LogicException('Puli is already started');
        }

        Assert::nullOrDirectory($rootDir);

        $this->rootDir = $rootDir ? Path::canonicalize($rootDir) : null;
    }
169038
function onlyDirectories ()
  {
    return $this->where (function ($f) {
      if (!is_object ($f) || !$f instanceof SplFileInfo)
        throw new \RuntimeException ("You must use FilesystemIterator::CURRENT_AS_PATHNAME with onlyDirectories() ");
      return $f->isDir ();
    });
  }