Generate SplFileInfo from base dir

@param   string $baseDir Base dir for path
@param   string  $path       A file/directory name
@return  SplFileInfo
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);
    }
273788
private function buildConfigDefinition($baseDir)
    {
        $definition = new Definition('BackBee\Config\Config', array(
            $this->getConfigDirByBundleBaseDir($baseDir),
            new Reference('cache.bootstrap'),
            null,
            '%debug%',
            '%config.yml_files_to_ignore%',
        ));

        if (true === $this->application->getContainer()->getParameter('container.autogenerate')) {
            $definition->addTag('dumpable', array('dispatch_event' => false));
        }

        $definition->addMethodCall('setContainer', array(new Reference('service_container')));
        $definition->addMethodCall('setEnvironment', array('%bbapp.environment%'));
        $definition->setConfigurator(array(new Reference('config.configurator'), 'configureBundleConfig'));
        $definition->addTag('bundle.config', array('dispatch_event' => false));

        return $definition;
    }
430097
public function getSplFileInfo(): \SplFileInfo
    {
        if (null !== $this->splFileInfo && $this->path === $this->splFileInfo->getRealPath()) {
            return $this->splFileInfo;
        }
        $this->assertExists();

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

        foreach ($this->getClasses() as $element) {
            $element->build($target, $output);
        }
    }
1239651
protected function getFiles(PhingFile $baseDir, DirectoryScanner $ds)
    {
        return $this->restrict($ds->getIncludedFiles(), $baseDir);
    }
230377
public function buildIndex($basedir, OutputInterface $output, array $options = array())
    {
        $target = $this->ensureBuildDir($basedir, $output);

        $built_iterator = new DirectoryIterator($target);
        $index = $target . DIRECTORY_SEPARATOR . 'index.rst';

        $title = str_replace('\\', '\\\\', $this->reflection->getName());
        if (isset($options['title'])) {
            $title = $options['title'];
        }

        $depth = substr_count($this->reflection->getName(), '\\');

        $template = str_repeat($this->titles[$depth], strlen($title)) . "\n";
        $template .= $title . "\n";
        $template .= str_repeat($this->titles[$depth], strlen($title)) . "\n\n";
        $template .= $this->getNamespaceElement();

        $template .= ".. toctree::\n\n";

        foreach ($built_iterator as $file) {
            if ($file->isDot()) continue;
            if ($file->isFile() && !$file->getExtension() == 'rst') continue;
            if ($file->isFile() && substr($file->getBaseName(), 0, 1) == '.') continue;
            if ($file->getBaseName() == 'index.rst') continue;

            $template .= '   ' . pathinfo($file->getPathName(), PATHINFO_FILENAME);

            if ($file->isDir()) {
                $template .= '/index';
            }

            $template .= "\n";
        }

        file_put_contents($index, $template);
    }
1050348
function host($path)
    {
        foreach ($this->files->scandir($this->sitesPath()) as $link) {
            if ($resolved = realpath($this->sitesPath().'/'.$link) === $path) {
                return $link;
            }
        }

        return basename($path);
    }
1171825
public function getImages($dir, $basedir)
    {
        $data = array();
        $dir = $basedir . $dir;
        $files = ftp_rawlist($this->link, $dir);
        foreach ($files as $v) {
            $file = ltrim(strrchr($v, ' '), ' ');
            $path = "{$dir}/{$file}";
            if (preg_match('/^-/', $v)) {
                if (preg_match('/^[a-zA-z0-9]+\.(gif|png|jpg|jpeg)$/', $file)) { //遍历目录设置
                    array_push($data, array(str_replace($basedir, '', $path), ftp_size($this->link, $path)));
                }
            }
        }
        return $data;
    }
1192760
public function getFiles()
    {
        if (empty($this->files)) {
            foreach ($this->path as $path) {
                if (is_dir($path)) {
                    $this->files = array_merge($this->files, $this->getFilesFromDir($path));
                } elseif (is_file($path)) {
                    $this->files[$path] = new SplFileInfo($path, $path, $path);
                }
            }
        }

        return $this->files;
    }
105840
protected function getBaseDir(DOMElement $root, $pathWorkflowFile)
    {
        if (!$root->hasAttribute('basedir')) {
            return null;
        }
        $basedirAtr = XmlUtil::getRequiredAttributeValue($root, 'basedir');


        $basedir = $basedirAtr;
        if (0 === strpos($basedir, '.')) {
            $basedir = dirname($pathWorkflowFile) .  substr($basedir, 1);
        }

        if (file_exists($basedir)) {
            $absolutePath = realpath($basedir);
        } else {
            $errMsg = sprintf('Отсутствует ресурс %s', $basedirAtr);
            throw new RuntimeException($errMsg);
        }

        return $absolutePath;
    }
924588
protected function realpath($path)
    {
        if ($path === '') {
            return $this->baseDir;
        }

        if ($path[0] === '/' || $path[1] === ':') {
            return $path;
        }

        return $this->baseDir . '/' . $path;
    }
219591
public function addNamespace($prefix, $baseDir)
    {
        $prefix = trim($prefix, '\\').'\\';
        $baseDir = rtrim($baseDir, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
        if (!isset($this->namespaceMap[$prefix])) {
            $this->namespaceMap[$prefix] = [];
        }
        array_push($this->namespaceMap[$prefix], str_replace('$path', $this->basePath, $baseDir));
    }
801972
public static function globAll(string $baseDir, array $patterns, int $flags = 0): array
    {
        $files = [];
        $inverse = [];

        foreach ($patterns as $pattern) {
            if (strpos($pattern, '!') === 0) {
                $pattern = substr($pattern, 1);

                $inverse[] = static::glob(
                    rtrim($baseDir, '\\/') . '/' . ltrim($pattern, '\\/'),
                    $flags
                );
            } else {
                $files[] = static::glob(
                    rtrim($baseDir, '\\/') . '/' . ltrim($pattern, '\\/'),
                    $flags
                );
            }
        }

        if ($files !== []) {
            $files = array_unique(array_merge(...$files));
        }

        if ($inverse !== []) {
            $inverse = array_unique(array_merge(...$inverse));
        }

        return array_diff($files, $inverse);
    }
493687
public function setBasePath($basePath = null) {
        if ($basePath === null) {
            $filename = (isset($this->SERVER['SCRIPT_FILENAME']))
                      ? basename($this->SERVER['SCRIPT_FILENAME'])
                      : '';

            $baseUrl = $this->getBaseUrl();
            if (empty($baseUrl)) {
                $this->_basePath = '';
                return $this;
            }

            if (basename($baseUrl) === $filename) {
                $basePath = dirname($baseUrl);
            } else {
                $basePath = $baseUrl;
            }
        }

        if (substr(PHP_OS, 0, 3) === 'WIN') {
            $basePath = str_replace('\\', '/', $basePath);
        }

        $this->_basePath = rtrim($basePath, '/');
        return $this;
    }
762532
public static function createFileInfo(string $base64String): \SplFileInfo
    {
        preg_match('/data:(.*);/', $base64String, $matchMime);
        preg_match('/data:image\/(.*);base64/', $base64String, $matchExt);

        $fileName = sprintf('/%s.%s', uniqid(), $matchExt[1]);
        $outputFile = sys_get_temp_dir() . $fileName;
        $fileResource = fopen($outputFile, 'wb');
        $base64Data = explode(',', $base64String);

        fwrite($fileResource, base64_decode($base64Data[1]));
        fclose($fileResource);

        return new \SplFileInfo($outputFile);
    }
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;
    }
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;
    }