public function testBasic() { $mockStrategy = Mockery::mock('Room11\\Caching\\LastModifiedStrategy'); $mockStrategy->shouldReceive('getHeaders')->once()->andReturn([]); $cachingFileResponse = new CachingFileBodyFactory($mockStrategy); $cachingFileResponse->create(__FILE__, "text/plain", []); }
public function cachedImageCallable(PageInfo $pageInfo, CachingFileBodyFactory $fileBodyFactory, $params) { $filename = $this->imageCachePath->getImageCacheFilename($pageInfo, $params); $extensions = ["jpg", 'jpeg', "gif", "png"]; $contentType = false; $filenameFound = false; $extension = null; foreach ($extensions as $extension) { $filenameWithExtension = $filename . "." . $extension; if (file_exists($filenameWithExtension) == true) { //TODO - content type should actually be image/jpeg $contentType = "image/" . $extension; $filenameFound = $filenameWithExtension; break; } } if ($filenameFound == false || $extension == null) { return false; } $simpleNameWithExtension = $pageInfo->getSimpleName($params) . '.' . $extension; return $fileBodyFactory->create($filenameFound, $simpleNameWithExtension, $contentType); }
function renderFile(CachingFileBodyFactory $fileResponseFactory, $filename) { return $fileResponseFactory->create($filename, "image/jpg"); }
public function getOriginalImage(Example $example, CachingFileBodyFactory $fileBodyFactory) { $filename = $example->getOriginalFilename(); return $fileBodyFactory->create($filename, "image/jpg"); }
function cachedImageCallable(PageInfo $pageInfo, Request $request, CachingFileBodyFactory $fileBodyFactory, $params) { $filename = getImageCacheFilename($pageInfo, $params); $extensions = ["jpg", 'jpeg', "gif", "png"]; $contentType = false; $filenameFound = false; foreach ($extensions as $extension) { $filenameWithExtension = $filename . "." . $extension; if (file_exists($filenameWithExtension) == true) { //TODO - content type should actually be image/jpeg $contentType = "image/" . $extension; $filenameFound = $filenameWithExtension; break; } } if ($filenameFound == false) { return false; } if ($request->hasHeader('HTTP_IF_MODIFIED_SINCE')) { $lastModifiedTime = filemtime($filenameFound); if (strtotime($request->getHeader('HTTP_IF_MODIFIED_SINCE')) >= $lastModifiedTime) { return new EmptyBody(304); } } return $fileBodyFactory->create($filenameFound, $contentType); }