Grab a files content but check to make sure it exists first

@param string $originalFile
@param string $cacheFile

@return string

@throws NotFoundException
176123
protected function getFileContent($originalFile, $cacheFile)
    {
        $this->beforeFilter($originalFile, $cacheFile);
        // Run through each filter
        foreach ($this->filters as $filterName => $Filter) {
            $arguments = isset($this->request->params[$filterName]) ?
                $this->request->params[$filterName] : array();
            if (! is_array($arguments)) {
                $arguments = array($filterName => $arguments);
            }
            // Do not minify if .min. is in the filename as it has already been minified
            if(strpos($originalFile, '.min.') !== FALSE) {
                $arguments['minify'] = false;
            }
            $Filter->doFilter($cacheFile, $arguments, $this->options);
        }

        $this->afterFilter($originalFile, $cacheFile);
        $this->lastModifiedDate = time();

        return file_get_contents($cacheFile);
    }
345090
public function check($cacheFile, $cacheTime)
    {
        // 缓存文件不存在, 直接返回false
        if (!file_exists($cacheFile)) {
            return false;
        }

        if (0 != $cacheTime && time() > filemtime($cacheFile) + $cacheTime) {
            // 缓存是否在有效期
            return false;
        }

        return true;
    }
180507
protected function updateAndGetCacheFileName($classFile)
    {
        $className = $this->className($classFile);

        if($this->hasChanged($classFile)){
            $content = $this->processClass($classFile);
            $this->writeCache($className, $content);
            $this->setDateFromClassFile($classFile);
        }

        return $this->cacheFile($className);
    }
585955
protected function readLine(string $cacheFile): string
    {
        $fp = fopen($cacheFile, 'r');
        $line = fgets($fp);
        fclose($fp);

        return $line;
    }
674069
public static function deleteUnusedFiles($originalContent, $content)
    {
        $originalFiles = self::findExternalLinks($originalContent);

        $deleted = [];

        if (empty($originalFiles)) {
            return $deleted;
        }

        $currentFiles = self::findExternalLinks($content);

        $diff = array_diff($originalFiles, $currentFiles);
        if (empty($diff)) {
            return $deleted;
        }

        foreach ($diff as $path) {
            // Skip absolute path
            if (strpos($path, 'http') === 0) {
                continue;
            }

            $file = File::find(ASSETS_DIR . $path);
            if ($file) {
                $deleted[] = $path;
                $file->delete();
            }
        }

        return $deleted;
    }
1019568
public function findFile(string $class)
    {
        static $isAllowedFilter = null, $isProduction = false;
        if (!$isAllowedFilter) {
            $isAllowedFilter = $this->fileEnumerator->getFilter();
            $isProduction    = !$this->options['debug'];
        }

        $file = $this->original->findFile($class);

        if ($file !== false) {
            $file = PathResolver::realpath($file)?:$file;
            $cacheState = $this->cacheState[$file] ?? null;
            if ($cacheState && $isProduction) {
                $file = $cacheState['cacheUri'] ?: $file;
            } elseif ($isAllowedFilter(new \SplFileInfo($file))) {
                // can be optimized here with $cacheState even for debug mode, but no needed right now
                $file = FilterInjectorTransformer::rewrite($file);
            }
        }

        return $file;
    }
429749
public function get($localFile, $remoteFile, $resumePosision = 0)
    {
        $mode = $this->getMode();
        $result = @ftp_get($this->connection, $localFile, $remoteFile, $mode, $resumePosision);

        if ($result === false)
        {
            throw new Exception(sprintf('Unable to get or save file "%s" from %s', $localFile, $remoteFile));
        }

        return $this;
    }
948418
public static function LoadCache ($ini_path, $cache_file_path) {
		clearstatcache(false, $cache_file_path);
		clearstatcache(false, $ini_path);
		return file_exists($cache_file_path) && filemtime($cache_file_path) < filemtime($ini_path) ? include $cache_file_path : null;
	}
602271
public static String generateCacheFileFullPath(Uri fileOriginalUri, File cacheDir, long createdTime) {
		String source = fileOriginalUri.toString() + Long.toString(createdTime);
		String fileName = md5(source);
		File cacheFile = new File(cacheDir, fileName);
		return cacheFile.getPath();
	}
451684
protected function check($cacheFile, $cacheTime) {
        // 缓存文件不存在, 直接返回false
        if (!file_exists($cacheFile)) {
            return false;
        }
        if (0 != $cacheTime && $_SERVER['REQUEST_TIME'] > filemtime($cacheFile) + $cacheTime) {
            // 缓存是否在有效期
            return false;
        }
        return true;
    }
26067
protected function beforeFilter($originalFile, $cacheFile)
    {
        if ($this->isLess($originalFile)) {
            $less = new lessc();
            try {
                $compiledLess = $less->cachedCompile($originalFile);
            } catch (\Exception $e) {
                throw new CompilationException('Error in LESS Compiler', 0, $e);
            }
            $compiledLess['compiled'] = $this->fixRelativePaths($compiledLess['compiled'], $originalFile);
            file_put_contents($cacheFile, serialize($compiledLess));
        } elseif ($this->isScss($originalFile)) {
            $scss = new ScssCompiler();
            $scss->addImportPath(pathinfo($originalFile, PATHINFO_DIRNAME));
            try {
                $compiled = $scss->compile(file_get_contents($originalFile));
            } catch (\Exception $e) {
                throw new CompilationException('Error in SCSS Compiler', 0, $e);
            }

            $content = compact('compiled');
            $parsedFiles = $scss->getParsedFiles();
            $parsedFiles[] = $originalFile;
            foreach ($parsedFiles as $file) {
                $content['files'][$file] = filemtime($file);
            }

            $content['compiled'] = $this->fixRelativePaths($content['compiled'], $originalFile);
            file_put_contents($cacheFile, serialize($content));
        } else {
            $content = file_get_contents($originalFile);
            file_put_contents($cacheFile, $this->fixRelativePaths($content, $originalFile));
        }
    }
732976
public function get($remFile, $locFile)
    {
        if (is_string($locFile)) {
            set_error_handler(function () {});
            $fileHandle = fopen($locFile, 'w+b');
            restore_error_handler();
        } else if (is_resource($locFile)) {
            $fileHandle = $locFile;
        } else {
            throw new InvalidArgumentException('Invalid local file');
        }

        if ($fileHandle === false) {
            throw new RuntimeException('File open error');
        }

        $writeBinn = new BinnList;

        $writeBinn->addUint8(self::FSERV_FILESEND);
        $writeBinn->addUint8(self::FSERV_DOWNLOAD_FR_SERVER);
        $writeBinn->addStr($remFile);

        $read = $this->writeAndReadSocket($writeBinn->serialize());

        $readBinn = new BinnList;
        $readBinn->binnOpen($read);
        $results = $readBinn->unserialize();

        if ($results[0] == self::FSERV_STATUS_OK) {
            throw new RuntimeException('Unexpected `OK` status. Expected `ready to transfer`');
        } else if ($results[0] != self::FSERV_STATUS_FILE_TRANSFER_READY) {
            throw new RuntimeException('Couldn\'t upload file: ' . isset($results[1]) ? $results[1] : 'Unknown');
        }

        $this->writeSocket(self::SOCKET_MSG_ENDL);

        $filesize = $results[2];
        $writed = 0;

        while($writed < $filesize) {
            if ($filesize - $writed > $this->maxBufsize) {
                $readlen = $this->maxBufsize;
            }
            else {
                $readlen = $filesize - $writed;
            }

            $socketRead = $this->readSocket($readlen, true);

            $writed += fwrite($fileHandle, $socketRead, $readlen);
        }

        if (is_resource($locFile)) {
            rewind($fileHandle);
            return $fileHandle;
        } else {
            fclose($fileHandle);
            return true;
        }
    }
1263926
public function read($cacheFile, $vars = [])
    {
        if (!empty($vars) && is_array($vars)) {
            // 模板阵列变量分解成为独立变量
            if (isset($vars['cacheFile'])) {
                $_think_cacheFile = $cacheFile;
                $cacheFile        = $vars['cacheFile'];
                unset($vars['cacheFile'], $vars['_think_cacheFile']);
                extract($vars);
                include $_think_cacheFile;
                return;
            }
            extract($vars);
        }

        //载入模版缓存文件
        include $cacheFile;
    }
762543
public function isExist($cacheName, $cacheDir = false)
    {
        $cacheDir = $cacheDir == false ? self::$cacheDir : $cacheDir;
        $dir = $cacheDir."/".$cacheName;

        return file_exists($dir);
    }
852603
public function get($cacheKey)
    {
        // TODO: Refactor for strict types!
        $path = $this->resolvePath($cacheKey, false);
        if (file_exists($path)) {
            return file_get_contents($path);
        }

        return null;
    }
1099364
public function copy_existing_file($oldfile) {
        if (array_key_exists($oldfile->get_contenthash(), $this->newfilehashes)) {
            return $this->newfilehashes[$oldfile->get_contenthash()];
        }
        $fs = get_file_storage();
        $file_record = $this->new_file_record_base($oldfile->get_filename());
        if ($dir = $this->get('format')->get_file_directory()) {
            $file_record->filepath = '/'. $dir . '/';
        }
        try {
            $newfile = $fs->create_file_from_storedfile($file_record, $oldfile->get_id());
            $this->newfilehashes[$newfile->get_contenthash()] = $newfile;
            return $newfile;
        } catch (file_exception $e) {
            return false;
        }
    }
301891
protected function extractCacheContent($file) {
		if ($this->_cacheContent !== null) {
			return $this->_cacheContent;
		}

		$this->_cacheContent = (string)file_get_contents($file);

		return $this->_cacheContent;
	}