获取模板文件缓存

@param  string $file 模板文件名称
@param int $type 缓存类型0当前操作的模板的缓存 1包含的模板的缓存

@return string
779328
private function getFile($file, $type = 0)
    {
        $type == 1 && $file = $this->initBaseDir($file);//初始化路径
        //$file = str_replace([('/', '\\'], DIRECTORY_SEPARATOR, $file);
        $cacheFile = $this->getCacheFile($file);
        if ($this->options['autoUpdate']) {
            $tplFile = $this->getTplFile($file);
            if (!is_readable($tplFile)) {
                throw new FileCanNotReadableException(Lang::get('_TEMPLATE_FILE_NOT_FOUND_', $tplFile));
            }
            if (!is_file($cacheFile)) {
                if ($type !== 1 && !is_null($this->layout)) {
                    if (!is_readable($this->layout)) {
                        throw new FileCanNotReadableException(Lang::get('_TEMPLATE_FILE_NOT_FOUND_', $this->layout));
                    }
                }
                $this->compile($tplFile, $cacheFile, $type);
                return $cacheFile;
            }

            $compile = false;
            $tplMtime = filemtime($tplFile);
            $cacheMtime = filemtime($cacheFile);
            if ($cacheMtime && $tplMtime) {
                ($cacheMtime < $tplMtime) && $compile = true;
            } else {//获取mtime失败
                $compile = true;
            }

            if ($compile && $type !== 1 && !is_null($this->layout)) {
                if (!is_readable($this->layout)) {
                    throw new FileCanNotReadableException(Lang::get('_TEMPLATE_FILE_NOT_FOUND_', $this->layout));
                }
            }

            //当子模板未修改时判断布局模板是否修改
            if (!$compile && $type !== 1 && !is_null($this->layout)) {
                if (!is_readable($this->layout)) {
                    throw new FileCanNotReadableException(Lang::get('_TEMPLATE_FILE_NOT_FOUND_', $this->layout));
                }
                $layoutMTime = filemtime($this->layout);
                if ($layoutMTime) {
                    $cacheMtime < $layoutMTime && $compile = true;
                } else {
                    $compile = true;
                }
            }

            $compile && $this->compile($tplFile, $cacheFile, $type);
        }
        return $cacheFile;
    }
1164741
public function getNewFile($type = null)
    {
        $class = $this->getFileModelName($type);
        /** @var ModelFile $file */
        $file = new $class();
        $file->setModel($this);
        $file->setFilesystem($this->getFilesystemDisk());
        return $file;
    }
1204442
final protected function createImageFromFile($file, $type)
    {
        switch ($type) {
            case \IMAGETYPE_GIF:
                return imagecreatefromgif($file);

            case \IMAGETYPE_JPEG:
                return imagecreatefromjpeg($file);

            case \IMAGETYPE_PNG:
                return imagecreatefrompng($file);
    
            default:
                throw new LogicException(sprintf('Can not create image from "%s"', $file));
        }
    }
1359388
public function generate(FileGenerator $file, $type): string
    {
        $class = $file->getClass() ?: new ClassGenerator();
        $class->setNamespaceName($type->getNamespace());
        $class->setName($type->getName());

        $this->ruleSet->applyRules(new TypeContext($class, $type));

        foreach ($type->getProperties() as $property) {
            $this->ruleSet->applyRules(new PropertyContext($class, $type, $property));
        }

        $file->setClass($class);

        return $file->generate();
    }
933462
public static function pathInfo($file)
    {
        $result = self::_pathInfo($file);
        return self::i()->dump($result, '! pathInfo (' . $file . ') !');
    }
283833
protected function generateHtmlCode($type, $file)
    {
        // Generate the url
        $url = $this->getUrlToTheAssetLoader($file);
        
        // Return the correct html tag
        if ($type === AssetManager::CSS) {
            return '<link rel="stylesheet" type="text/css" href="' . $url . '">' . PHP_EOL;
        } else if ($type === AssetManager::JS) {
            return '<script type="text/javascript" src="' . $url . '"></script>' . PHP_EOL;
        }
    }
1177187
public function find_file($file, $type, $folder = '')
	{
		foreach ($this->_asset_paths[$type] as $path)
		{
			empty($folder) or $folder = $this->_unify_path($folder);

			if (is_file($newfile = $path.$folder.$this->_unify_path($file, null, false)))
			{
				// return the file found, make sure it uses forward slashes on Windows
				return str_replace(DS, '/', $newfile);
			}
		}

		return false;
	}
782073
protected function getParameters($type, $file = null)
    {
        $headers = [];

        if(!empty($file) && preg_match('/^http/', $file))
        {
            $headers[] = "fileUrl:$file";
        }

        switch($type)
        {
            case 'html':
                $resource = 'tika';
                $headers[] = 'Accept: text/html';
                break;

            case 'lang':
                $resource = 'language/stream';
                break;

            case 'mime':
                $name = basename($file);
                $resource = 'detect/stream';
                $headers[] = "Content-Disposition: attachment, filename=$name";
                break;

            case 'meta':
                $resource = 'meta';
                $headers[] = 'Accept: application/json';
                break;

            case 'text':
                $resource = 'tika';
                $headers[] = 'Accept: text/plain';
                break;

            case 'text-main':
                $resource = 'tika/main';
                $headers[] = 'Accept: text/plain';
                break;

            case 'detectors':
            case 'parsers':
            case 'mime-types':
            case 'version':
                $resource = $type;
                break;

            default:
                throw new Exception("Unknown type $type");
        }

        return [$resource, $headers];
    }
267716
public function add(string $file, string $type)
    {
        $url = self::ADD.$this->access_token.'&'.http_build_query([
                'type' => $type,
            ]);
        $this->curl->setOpt(CURLOPT_SAFE_UPLOAD, true);
        $data = $this->curl->post($url, [
            'media' => new \CURLFile($file),
        ]);

        return Response::json($data);
    }
282716
private static function checkType(string $file): string
    {
        $parts = explode('.', $file);
        $type = array_pop($parts);

        if (!in_array($type, array_keys(self::$types))) {
            throw new LoaderException("Loader::checkType(): Could not find parser for {$file}!");
        }

        return $type;
    }
823734
public function getFiles($type)
	{
		$f = $type . 'Files';

		if (property_exists($this, $f))
		{
			return self::${$f};
		}

		$this->say('Missing Files: ' . $type);

		return "";
	}
900702
protected function getArguments($type, $file = null)
    {
        // parameters for command
        $arguments = [];
        switch($type)
        {
            case 'html':
                $arguments[] = '--html';
                break;

            case 'lang':
                $arguments[] = '--language';
                break;

            case 'mime':
                $arguments[] = '--detect';
                break;

            case 'meta':
                $arguments[] = '--metadata --json';
                break;

            case 'text':
                $arguments[] = '--text';
                break;

            case 'text-main':
                $arguments[] = '--text-main';
                break;

            case 'mime-types':
                $arguments[] = '--list-supported-types';
                break;

            case 'detectors':
                $arguments[] = '--list-detectors';
                break;

            case 'parsers':
                $arguments[] = '--list-parsers';
                break;

            case 'version':
                $arguments[] = '--version';
                break;

            default:
                throw new Exception("Unknown type $type");
        }

        return $arguments;
    }
892426
public function uploadLocal($file)
    {
        // 格式 uploads/image/$folder/2018/02/02/
        $folderName = $this->rootFolder . $this->folder . DIRECTORY_SEPARATOR . date($this->dateFormat, time());

        // 将 public 目录的绝对路径和 上面定义的路径拼接到一起
        // 格式: /www/www.broqiang.com/public/uploads/image/$folder/2018/02/02/
        $uploadPath = public_path($folderName);

        // 拼接文件名
        $filename = $this->getFilename($file);

        // 将图片移动到我们的目标存储路径中
        $file->move($uploadPath, $filename);

        if ($this->maxWidth && $this->extension != 'gif') {
            $this->reduceSize($uploadPath . DIRECTORY_SEPARATOR . $filename, $this->maxWidth);
        }

        return $this->getUrlPath($folderName, $filename);
    }
979374
public function upload($file, $type)
    {
        if (!$file || !$type) {
            $this->setError('参数缺失');

            return false;
        }

        if (!file_exists($file)) {
            $this->setError('文件路径不正确');

            return false;
        }

        $data          = [];
        $data['media'] = '@' . realpath($file);

        Api::setPostQueryStr('type', $type);

        $node = 'upload';

        $res = $this->_post($node, $data, false);

        return $res;
    }
111769
protected static function getTypeFinfoExt($file) {

		$type = (new \finfo(FILEINFO_MIME_TYPE))->file($file);

		if($type) {
			return $type;
		}

		else {
			return self::getTypeFileExtList($file);
		}

	}
90452
public function cssMinify($file, $type = 'file')
    {
        $file = $this->getFile($file, $type);
        $file = $this->cleanSpaces($file);
        $file = $this->fixMaster($file);
        $file = $this->removeComments($file);

        return preg_replace(['/;[\s\r\n\t]*?}[\s\r\n\t]*/ims', '/;[\s\r\n\t]/ims', '/[\s\r\n\t]*:[\s\r\n\t][\s+\/]/ims', '/[\s\r\n\t]*,[\s\r\n\t]*?([^\s\r\n\t]\.[\s+\/])/ims', '/[\s\r\n\t]/ims', '/([\d\.]+)[\s\r\n\t]+(px|em|pt|%)/ims', '/([^\s\.]0)(px|em|pt|%|ex|mm|in|pc|vh|vw|vmin)/ims', '/\s+/'], ['}', ';$1', ',$1', '$1', '$1$2', '$1$2', ' '], $file);
    }
44974
public static String getFileMimeType(final File file) {
		if (file != null) {
			try {
				final Tika tika = new Tika();
				return tika.detect(file.getInputStream());
			} catch (IOException ex) {
				LOG.error("Invalid file, name " + file.getName(), ex);
			}
		}
		return null;
	}