标准化文件信息

@param  \SplFileInfo $file

@return array|null
492624
protected function normalizeFileInfo(SplFileInfo $file)
    {
        if (! $file->isLink()) {
            $normalized = [
                'type'      => $file->getType(),
                'path'      => $this->getFilePath($file),
                'timestamp' => $file->getMTime()
            ];

            if ($normalized['type'] === 'file') {
                $normalized['size'] = $file->getSize();
            }

            return $normalized;
        }
    }
831558
protected function process(SplFileInfo $file): array
    {
        /** @var FileLoaderAdapterInterface $adapter */
        foreach ($this->adapters as $adapter) {
            if ($adapter->doesHandle($file)) return $adapter->process($file->getRealPath());
        }

        return [];

    }
876680
protected static function getFilePath(\SplFileInfo $file)
    {
        $path = $file->getPathname();

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

        return $path;
    }
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;
            }
        }
    }
1350934
protected function getRelativeFilename(SplFileInfo $file)
    {
        $filename = $file->getPathname();
        $regex = sprintf('#^(%s)/(.+)#', $this->directory);
        $matches = array();

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

        return $matches[2];
    }
1044513
public function getPdfInfo($file)
    {
        if ($this->fileInfo->getIsFile()
            && $this->fileInfo->getExtension() == 'pdf'
            && $this->isAppArraySet
        ) {
            $fileEscaped = CommandUtility::escapeShellArgument($file);
            $cmd = "{$this->app['pdfinfo']} $fileEscaped";
            CommandUtility::exec($cmd, $pdfInfoArray);
            $pdfInfo = $this->splitPdfInfo($pdfInfoArray);

            return $pdfInfo;
        }

        return false;
    }
166749
public function filter(\SPLFileInfo $file)
    {
        foreach ($this->filterlist as $filter) {
            if (! $filter->filter($file)) {
                return false;
            }
        }
        return true;
    }
227515
public static function getMimeTypeByFile(string $file)
    {
        if (!\is_file($file) || !\class_exists('\finfo', false)) {
            return null;
        }

        try {
            $finfo = new \finfo(FILEINFO_MIME_TYPE);

            return $finfo->file($file) ?: null;
            // @codeCoverageIgnoreStart
        } catch (\ErrorException $e) {
            // This is caused by an array to string conversion error.
            return null;
        }
    }
284958
protected function parse(\SplFileInfo $file): array
    {
        $config = @parse_ini_file($file->getRealPath());
        if ($config === false) {
            throw new ConfigurationParseException('Unable to parse configuration: invalid format');
        }

        return $config;
    }
664181
protected function parse(\SplFileInfo $file): array
    {
        $config = require_once $file->getRealPath();

        if (!is_array($config)) {
            throw new ConfigurationParseException('Invalid configuration file');
        }

        return $config;
    }
1174627
public function filter(\SplFileInfo $file)
    {
        try {
            $class = $this->getClassName($file->getPathname());
        } catch (\Exception $e){
            return false;
        }

        if (! @include_once($file->getPathname())) {
            return false;
        }

        $ReflectionClass = new \ReflectionClass($class);

        foreach ($this->instances as $instance) {
            if ($ReflectionClass->isSubclassOf($instance)) {
                return true;
            }

            if ($class === $instance) {
                return true;
            }
        }

        return false;
    }
554407
public function getLocalFile($file = '') {
        #判断数据不为空
        if (empty($file)) {
            return [];
        }
        $data = [];
        foreach ($file as $key => $value) {
            $path = ROOT_DIR . $value['name'];
            if (is_file($path)) {
                #获取文件内容
                $value['content'] = encrypt(file_get_contents($path));
                $data[]           = $value;
            }
        }
        return $data;
    }
770203
public function resolve($file)
    {
        $info = null;

        $this->rewind();
        foreach (clone $this as $path) {
            $info = new SplFileInfo(rtrim($path, '/') . '/' . ltrim($file, '/'));

            if ($info->isDir() || $info->isFile() || $info->isLink()) {
                break;
            }
        }

        return ($info)? $info->getPathname() : null;
    }
197779
public function filter(SplFileInfo $file)
    {
        try {
            $class = $this->getClassName($file->getPathname());
        } catch (Exception $e){
            return false;
        }

        $usedtraits = class_uses($class, $this->useautoload);

        foreach ($this->instances as $instance) {
            if (in_array($instance, $usedtraits)) {
                return true;
            }
        }

        return false;
    }
59748
protected function _filterFile(SplFileInfo $fileInfo)
    {
        if (!$fileInfo->isFile()) {
            return false;
        }

        if (($expr = $this->_getFilenameRegex()) && !preg_match($expr, $fileInfo->getPathname())) {
            return false;
        }

        if (($callback = $this->_getCallbackFilter()) && !call_user_func_array($callback, array($fileInfo))) {
            return false;
        }

        return true;
    }
824436
public function init(\SplFileInfo $file, $extension = null)
    {
        $config = Grav::instance()['config'];

        // some extension logic
        if (empty($extension)) {
            $this->extension('.' . $file->getExtension());
        } else {
            $this->extension($extension);
        }

        // extract page language from page extension
        $language = trim(basename($this->extension(), 'md'), '.') ?: null;
        $this->language($language);

        $this->hide_home_route = $config->get('system.home.hide_in_urls', false);
        $this->home_route = $this->adjustRouteCase($config->get('system.home.alias'));
        $this->filePath($file->getPathname());
        $this->modified($file->getMTime());
        $this->id($this->modified() . md5($this->filePath()));
        $this->routable(true);
        $this->header();
        $this->date();
        $this->metadata();
        $this->url();
        $this->visible();
        $this->modularTwig(strpos($this->slug(), '_') === 0);
        $this->setPublishState();
        $this->published();
        $this->urlExtension();


        return $this;
    }
615444
protected function parseArchive(\SplFileInfo $file): \SplFileInfo
    {
        $archive = (new ZipFile())->openFile(
            $file instanceof \SplTempFileObject ? $this->generateTempFile($file) : $file->getRealPath()
        );
        $this->correctArchiveFilenamesEncoding($archive);
        $this->flattenArchive($archive);
        $this->filenames = $this->correctArchiveFilenames($archive);
        
        $tempDirectoryPath = (new GenericDictionaryParser())->generateTempDirectory();
        $archive->extractTo($tempDirectoryPath);
        $archive->close();

        $validator = new \esperecyan\dictionary_php\Validator();
        $validator->setLogger($this->logger);
        foreach (new \FilesystemIterator(
            $tempDirectoryPath,
            \FilesystemIterator::KEY_AS_FILENAME
        ) as $filename => $file) {
            if ($file->getExtension() === 'txt') {
                if (isset($quizFile)) {
                    throw new SyntaxException(_('拡張子が「.txt」のファイルが2つ以上含まれています。'));
                }
                if (!in_array(
                    (new Finfo(FILEINFO_MIME_TYPE))->file($file),
                    ['text/plain', 'text/csv']
                )) {
                    throw new SyntaxException(
                        sprintf(_('「%s」は通常のテキストファイルとして認識できません。'), $filename)
                    );
                }
                $quizFile = $file;
            }
        }

        if (empty($quizFile)) {
            throw new SyntaxException(_('拡張子が「.txt」のファイルが見つかりません。'));
        }
        
        return $quizFile;
    }