@param SplFileInfo $file

@return string
197861
private function getFileContents(SplFileInfo $file)
    {
        $content = $file->getContents();
        if ($file->getExtension() === 'js' && substr($content, -1) !== ';') {
            $content .= ';';
        }

        return $content;
    }
669665
public function transform(SplFileInfo $file)
    {
        try {
            $contentFile = $this->fileToContentFile->transform($file);
            $contentItem = $this->buildContentItem($contentFile);

            return $contentItem;
        } catch (\Exception $e) {
            throw new TransformationFailure($e->getMessage(), 0, $e, $file->getRealPath());
        }
    }
1095461
public function filter(\SplFileInfo $file)
    {
        if ($this->minsize !== null && $this->minsize > $file->getSize()) {
            return false;
        }
        if ($this->maxsize !== null && $this->maxsize < $file->getSize()) {
            return false;
        }

        return true;
    }
860550
public function getMimeType(\SplFileInfo $file)
    {
        $fileInfo = finfo_open(FILEINFO_MIME_TYPE);
        $mimeType = finfo_file($fileInfo, $file->getPathname());
        finfo_close($fileInfo);

        return $mimeType;
    }
1250906
protected function parse(\SplFileInfo $file): array
    {
        libxml_use_internal_errors(true);

        $xml = simplexml_load_file($file->getRealPath());
        if (!$xml instanceof \SimpleXMLElement) {
            $errors = array_map(function (\LibXMLError $error) {
                return trim($error->message);
            }, libxml_get_errors());
            libxml_clear_errors();

            throw new ConfigurationParseException('Unable to parse config file: ' . implode(', ', $errors));
        }

        $config = json_decode(json_encode($xml), true);

        return $config;
    }
490172
public function resolveClassname($file)
    {

        $splFile = new SplFileInfo($file);
        $parts   = explode('_', $splFile->getFilename());
        $strings = [];
        foreach ($parts as $part) {
            if (is_numeric($part)) {
                continue;
            }
            array_push($strings, $part);
        }
        $class = Str::studly(implode('_', $strings));
        return new $class;
    }
836371
public static function createFromSplFileInfo(\SplFileInfo $file)
    {
        $asset = new Asset();
        $guesser = MimeTypeGuesser::getInstance();
        return $asset
            ->setFilename($file->getFilename())
            ->setExtension($file->getExtension())
            ->setPathname($file->getPathname())
            ->setMimeType($guesser->guess($file->getPathname()))
            ->setClientOriginalName($file->getFilename())
            ->setClientOriginalExtension($file->getExtension())
        ;
    }
737820
protected function getClassnamesFromComposerFile(SplFileInfo $file)
    {
        $composerData = $this->readComposerFile($file);

        if (isset($composerData['extra']['spress_class']) === false) {
            return [];
        }

        if (
            is_string($composerData['extra']['spress_class']) === false
            && is_array($composerData['extra']['spress_class']) === false
        ) {
            return [];
        }

        return (array) $composerData['extra']['spress_class'];
    }
42294
protected static function autoloadFile(SplFileInfo $file)
    {
        $yml = Yaml::parse(file_get_contents($file->getRealPath()), true);

        $service = Arr::get($yml, 'micro-service');
        if (is_null($service)) {
            return;
        }

        sbox()->add(new MicroService($service, $yml));
    }
1350934
protected function getRelativeFilename(SplFileInfo $file)
    {
        $filename = $file->getPathname();
        $regex = sprintf('#^(%s)/(.+)#', $this->directory);
        $matches = array();

        preg_match(
            $regex,
            $filename,
            $matches
        );

        return $matches[2];
    }
1348252
protected function match(SplFileInfo $file): bool
    {
        return $file->isFile() &&
                $this->hasExtension($file) &&
                $this->instanceOf($file)
        ;
    }
387726
protected function fileToClass(SplFileInfo $file)
    {
        preg_match('/.*namespace\s([^\;]+)?/i', $file->getContents(), $match);

        if (isset($match[1])) {
            $class = $match[1].'\\'.$file->getBasename('.php');
            if (class_exists($class)) {
                return $class;
            }
        }
    }
1139802
protected function readComposerFile(SplFileInfo $file)
    {
        $json = $file->getContents();
        $data = json_decode($json, true);

        return $data;
    }
581053
public function clean(SplFileInfo $file)
    {
        $name = $file->getFilename();
        if ($file->isFile()) {
            $name = pathinfo($name, PATHINFO_FILENAME);
        }

        $name = str_replace("\t\n\r\0\x0B", ' ', $name); // remove control characters
        $name = str_replace('_', ' ', $name);

        $name = preg_replace('/\[[^\[\]]*\]/', ' ', $name); // remove [...]
        $name = preg_replace('/\([^\(\)]*\)/', ' ', $name); // remove (...)

        // remove all file meta data
        $reg = sprintf('/[ .,](?:%s)[ .,]/i', implode('|', $this->meta));
        while (preg_match($reg, $name.' ')) {
            $name = preg_replace($reg, ' ', $name.' ');
        }

        $name = str_replace('  ', ' ', $name); // remove double spaces
        $name = trim($name, ' .,-');

        return $name;
    }
982262
private function getFilenameFromFile(SplFileInfo $file) : string
    {
        return substr($file->getRelativePathname(), 0, -(strlen($this->fileExtension) + 1));
    }
1037554
protected function load(SplFileInfo $file)
    {
        // File info
        $this->filename = $file->getBasename();
        $this->sourcePath = $file->getRelativePath();

        // Load the file
        $data = $file->getContents();

        list($content, $meta) = $this->splitContentMeta($data);

        // Parse meta
        $meta = Yaml::parse($meta) ?: [];

        // Parse content
        switch ($file->getExtension()) {
            case 'md':
            case 'markdown':
                $content = Markdown::parse($content);
                $this->type = self::TYPE_MARKDOWN;
                break;
            case 'tx':
            case 'textile':
                $content = Textile::parse($content);
                $this->type = self::TYPE_TEXTILE;
                break;
        }

        // Set content
        $this->content = $content;
        $this->meta = $meta;

        // Ensure local URLs are absolute
        foreach($this->meta as $key=>$value) {
            if (preg_match('/\burl\b|.*_url\b/', $key)) {
                $this->meta[$key] = $this->builder->getUrl($value);
            }
        }

        // Set target
        $this->setTarget($file);

        // Pagination enabled
        $this->paginate = isset($this->meta['paginate']);

        // Get parent page
        if ($root = dirname(dirname($this->target))) {
            if ($root !== DIRECTORY_SEPARATOR) {
                $this->parentId = ltrim($root, '/');
            }
        }

        // Set URL
        $this->url = '/' . trim(str_replace([DIRECTORY_SEPARATOR, '//'], ['/', '/'], $this->target), '/');

        // Remove "index.html" from the end, this provides a cleaner URL
        if (substr($this->url, -10) === 'index.html') {
            $this->url = substr($this->url, 0, -10);
        }

        // Set basic values
        $this->id = trim($this->url, '/') ?: 'root';
        $this->title = $this->get('title');
        $this->url = $this->builder->getUrl($this->url);

        // Set Description
        if ($this->has('description')) {
            $this->description = $this->get('description');
        }
        else {
            $this->description = $this->getDescription();
        }
    }
876680
protected static function getFilePath(\SplFileInfo $file)
    {
        $path = $file->getPathname();

        $path = trim(str_replace('\\', '/', $path));

        return $path;
    }