Esempio n. 1
0
function cachedImageCallable(PageInfo $pageInfo, Request $request, Response $response, CachingFileResponseFactory $fileResponseFactory, $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) {
            $response->setStatus(304);
            return new EmptyBody();
        }
    }
    return $fileResponseFactory->create($filenameFound, $contentType);
}
Esempio n. 2
0
function renderFile(CachingFileResponseFactory $fileResponseFactory, $filename)
{
    return $fileResponseFactory->create($filename, "image/jpg");
}
Esempio n. 3
0
 public function getOriginalImage(Example $example, CachingFileResponseFactory $fileResponseFactory)
 {
     $filename = $example->getOriginalFilename();
     return $fileResponseFactory->create($filename, "image/jpg");
 }