1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys PackBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\PackBundle
;
14 use Rapsys\PackBundle\Util\ImageUtil
;
15 use Rapsys\PackBundle\Util\SluggerUtil
;
17 use Psr\Container\ContainerInterface
;
19 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController
;
20 use Symfony\Component\Filesystem\Exception\IOExceptionInterface
;
21 use Symfony\Component\Filesystem\Filesystem
;
22 use Symfony\Component\HttpFoundation\BinaryFileResponse
;
23 use Symfony\Component\HttpFoundation\HeaderUtils
;
24 use Symfony\Component\HttpFoundation\Request
;
25 use Symfony\Component\HttpFoundation\Response
;
26 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
27 use Symfony\Component\Routing\RequestContext
;
28 use Symfony\Contracts\Service\ServiceSubscriberInterface
;
33 class Controller
extends AbstractController
implements ServiceSubscriberInterface
{
37 protected string $alias;
42 protected array $config;
52 protected string $version;
55 * Creates a new image controller
57 * @param ContainerInterface $container The ContainerInterface instance
58 * @param ImageUtil $image The MapUtil instance
59 * @param SluggerUtil $slugger The SluggerUtil instance
61 function __construct(protected ContainerInterface
$container, protected ImageUtil
$image, protected SluggerUtil
$slugger) {
63 $this->config
= $container->getParameter($this->alias
= RapsysPackBundle
::getAlias());
66 $this->ctx
= stream_context_create(
69 'max_redirects' => $_ENV['RAPSYSPACK_REDIRECT'] ?? 20,
70 'timeout' => $_ENV['RAPSYSPACK_TIMEOUT'] ?? (($timeout = ini_get('default_socket_timeout')) !== false && $timeout !== '' ? (float)$timeout : 60),
71 'user_agent' => $_ENV['RAPSYSPACK_AGENT'] ?? (($agent = ini_get('user_agent')) !== false && $agent !== '' ? (string)$agent : $this->alias
.'/'.($this->version
= RapsysPackBundle
::getVersion()))
78 * Return captcha image
80 * @param Request $request The Request instance
81 * @param string $hash The hash
82 * @param string $equation The shorted equation
83 * @param int $width The width
84 * @param int $height The height
85 * @return Response The rendered image
87 public function captcha(Request
$request, string $hash, string $equation, int $width, int $height, string $_format): Response
{
88 //Without matching hash
89 if ($hash !== $this->slugger
->serialize([$equation, $width, $height])) {
91 throw new NotFoundHttpException(sprintf('Unable to match captcha hash: %s', $hash));
92 //Without valid format
93 } elseif ($_format !== 'jpeg' && $_format !== 'png' && $_format !== 'webp') {
95 throw new NotFoundHttpException('Invalid thumb format');
99 $equation = $this->slugger
->unshort($short = $equation);
102 $hashed = str_split(strval($equation));
105 $captcha = $this->config
['cache'].'/'.$this->config
['prefixes']['captcha'].'/'.$hashed[0].'/'.$hashed[4].'/'.$hashed[8].'/'.$short.'.'.$_format;
107 //Without captcha up to date file
108 if (!is_file($captcha) || !($mtime = stat($captcha)['mtime']) || $mtime < (new \
DateTime('-1 hour'))->getTimestamp()) {
109 //Without existing captcha path
110 if (!is_dir($dir = dirname($captcha))) {
111 //Create filesystem object
112 $filesystem = new Filesystem();
116 //XXX: set as 0775, symfony umask (0022) will reduce rights (0755)
117 //XXX: on CoW filesystems execute a chattr +C before filling
118 $filesystem->mkdir($dir, 0775);
119 } catch (IOExceptionInterface
$e) {
121 throw new \
Exception(sprintf('Output path "%s" do not exists and unable to create it', $dir), 0, $e);
125 //Create image instance
126 $image = new \
Imagick();
128 //Add imagick draw instance
129 //XXX: see https://www.php.net/manual/fr/imagick.examples-1.php#example-3916
130 $draw = new \
ImagickDraw();
133 $draw->setTextAntialias(true);
135 //Set stroke antialias
136 $draw->setStrokeAntialias(true);
139 $draw->setTextAlignment(\Imagick
::ALIGN_CENTER
);
142 $draw->setGravity(\Imagick
::GRAVITY_CENTER
);
145 $draw->setFillColor($this->config
['captcha']['fill']);
148 $draw->setStrokeColor($this->config
['captcha']['border']);
151 $draw->setFontSize($this->config
['captcha']['size'] / 1.5);
154 $draw->setStrokeWidth($this->config
['captcha']['thickness'] / 3);
157 $draw->rotate($rotate = (rand(25, 75)*(rand(0,1)?-.1:.1)));
160 $metrics2 = $image->queryFontMetrics($draw, strval('stop spam'));
163 $draw->annotation($width / 2 - ceil(rand(intval(-$metrics2['textWidth']), intval($metrics2['textWidth'])) / 2) - abs($rotate), ceil($metrics2['textHeight'] +
$metrics2['descender'] +
$metrics2['ascender']) / 2 - $this->config
['captcha']['thickness'] - $rotate, strval('stop spam'));
166 $draw->rotate(-$rotate);
169 $draw->setFontSize($this->config
['captcha']['size']);
172 $draw->setStrokeWidth($this->config
['captcha']['thickness']);
175 $draw->rotate($rotate = (rand(25, 50)*(rand(0,1)?-.1:.1)));
178 $metrics = $image->queryFontMetrics($draw, strval($equation));
181 $draw->annotation($width / 2, ceil($metrics['textHeight'] +
$metrics['descender'] +
$metrics['ascender']) / 2 - $this->config
['captcha']['thickness'], strval($equation));
184 $draw->rotate(-$rotate);
187 #$image->newImage(intval(ceil($metrics['textWidth'])), intval(ceil($metrics['textHeight'] + $metrics['descender'])), new \ImagickPixel($this->config['captcha']['background']), 'jpeg');
188 $image->newImage($width, $height, new \
ImagickPixel($this->config
['captcha']['background']), $_format);
191 $image->drawImage($draw);
193 //Strip image exif data and properties
194 $image->stripImage();
196 //Set compression quality
197 $image->setImageCompressionQuality(70);
200 if (!$image->writeImage($captcha)) {
202 throw new \
Exception(sprintf('Unable to write image "%s"', $captcha));
206 $mtime = stat($captcha)['mtime'];
209 //Read captcha from cache
210 $response = new BinaryFileResponse($captcha);
213 $response->setContentDisposition(HeaderUtils
::DISPOSITION_INLINE
, 'captcha-stop-spam-'.str_replace([' ', '*', '+'], ['-', 'mul', 'add'], $equation).'.'.$_format);
216 $response->setEtag(md5($hash));
219 $response->setLastModified(\DateTime
::createFromFormat('U', strval($mtime)));
222 $response->setPublic();
224 //Return 304 response if not modified
225 $response->isNotModified($request);
232 * Return facebook image
234 * @param Request $request The Request instance
235 * @param string $hash The hash
236 * @param string $path The image path
237 * @param int $width The width
238 * @param int $height The height
239 * @return Response The rendered image
241 public function facebook(Request
$request, string $hash, string $path, int $width, int $height, string $_format): Response
{
242 //Without matching hash
243 if ($hash !== $this->slugger
->serialize([$path, $width, $height])) {
244 //Throw new exception
245 throw new NotFoundHttpException(sprintf('Unable to match facebook hash: %s', $hash));
246 //Without matching format
247 } elseif ($_format !== 'jpeg' && $_format !== 'png' && $_format !== 'webp') {
248 //Throw new exception
249 throw new NotFoundHttpException(sprintf('Invalid facebook format: %s', $_format));
253 $path = $this->slugger
->unshort($short = $path);
255 //Without facebook file
256 if (!is_file($facebook = $this->config
['cache'].'/'.$this->config
['prefixes']['facebook'].$path.'.'.$_format)) {
257 //Throw new exception
258 throw new NotFoundHttpException('Unable to get facebook file');
261 //Read facebook from cache
262 $response = new BinaryFileResponse($facebook);
265 $response->setContentDisposition(HeaderUtils
::DISPOSITION_INLINE
, 'facebook-'.$hash.'.'.$_format);
268 $response->setEtag(md5($hash));
271 $response->setLastModified(\DateTime
::createFromFormat('U', strval(stat($facebook)['mtime'])));
274 $response->setPublic();
276 //Return 304 response if not modified
277 $response->isNotModified($request);
286 * @param Request $request The Request instance
287 * @param string $hash The hash
288 * @param int $updated The updated timestamp
289 * @param float $latitude The latitude
290 * @param float $longitude The longitude
291 * @param int $zoom The zoom
292 * @param int $width The width
293 * @param int $height The height
294 * @return Response The rendered image
296 public function map(Request
$request, string $hash, float $latitude, float $longitude, int $height, int $width, int $zoom, string $_format): Response
{
297 //Without matching hash
298 if ($hash !== $this->slugger
->hash([$height, $width, $zoom, $latitude, $longitude])) {
299 //Throw new exception
300 throw new NotFoundHttpException(sprintf('Unable to match map hash: %s', $hash));
304 $map = $this->config
['cache'].'/'.$this->config
['prefixes']['map'].'/'.$zoom.'/'.($latitude*1000000%
10).'/'.($longitude*1000000%
10).'/'.$latitude.','.$longitude.'-'.$zoom.'-'.$width.'x'.$height.'.'.$_format;
307 //TODO: refresh after config modification ?
308 if (!is_file($map)) {
309 //Without existing map path
310 if (!is_dir($dir = dirname($map))) {
311 //Create filesystem object
312 $filesystem = new Filesystem();
316 //XXX: set as 0775, symfony umask (0022) will reduce rights (0755)
317 //XXX: on CoW filesystems execute a chattr +C before filling
318 $filesystem->mkdir($dir, 0775);
319 } catch (IOExceptionInterface
$e) {
321 throw new \
Exception(sprintf('Output directory "%s" do not exists and unable to create it', $dir), 0, $e);
325 //Create image instance
326 $image = new \
Imagick();
329 $image->newImage($width, $height, new \
ImagickPixel('transparent'), $_format);
331 //Create tile instance
332 $tile = new \
Imagick();
335 $centerX = $this->image
->longitudeToX($longitude, $zoom);
336 $centerY = $this->image
->latitudeToY($latitude, $zoom);
339 $startX = floor(floor($centerX) - $width / $this->config
['map']['tz']);
340 $startY = floor(floor($centerY) - $height / $this->config
['map']['tz']);
343 $endX = ceil(ceil($centerX) +
$width / $this->config
['map']['tz']);
344 $endY = ceil(ceil($centerY) +
$height / $this->config
['map']['tz']);
346 for($x = $startX; $x <= $endX; $x++
) {
347 for($y = $startY; $y <= $endY; $y++
) {
349 $cache = $this->config
['cache'].'/'.$this->config
['prefixes']['map'].'/'.$zoom.'/'.($x%
10).'/'.($y%
10).'/'.$x.','.$y.'.png';
351 //Without cache image
352 if (!is_file($cache)) {
354 $tileUri = str_replace(['{Z}', '{X}', '{Y}'], [$zoom, $x, $y], $this->config
['servers'][$this->config
['map']['server']]);
357 if (!is_dir($dir = dirname($cache))) {
358 //Create filesystem object
359 $filesystem = new Filesystem();
363 //XXX: set as 0775, symfony umask (0022) will reduce rights (0755)
364 $filesystem->mkdir($dir, 0775);
365 } catch (IOExceptionInterface
$e) {
367 throw new \
Exception(sprintf('Output directory "%s" do not exists and unable to create it', $dir), 0, $e);
371 //Store tile in cache
372 file_put_contents($cache, file_get_contents($tileUri, false, $this->ctx
));
376 $destX = intval(floor($width / 2 - $this->config
['map']['tz'] * ($centerX - $x)));
379 $destY = intval(floor($height / 2 - $this->config
['map']['tz'] * ($centerY - $y)));
381 //Read tile from cache
382 $tile->readImage($cache);
385 $image->compositeImage($tile, \Imagick
::COMPOSITE_OVER
, $destX, $destY);
392 //Add imagick draw instance
393 //XXX: see https://www.php.net/manual/fr/imagick.examples-1.php#example-3916
394 $draw = new \
ImagickDraw();
397 $draw->setTextAntialias(true);
399 //Set stroke antialias
400 $draw->setStrokeAntialias(true);
403 $draw->setTextAlignment(\Imagick
::ALIGN_CENTER
);
406 $draw->setGravity(\Imagick
::GRAVITY_CENTER
);
409 $draw->setFillColor($this->config
['map']['fill']);
412 $draw->setStrokeColor($this->config
['map']['border']);
415 $draw->setStrokeWidth($this->config
['map']['thickness']);
418 $draw->circle($width/2 - $this->config
['map']['radius'], $height/2 - $this->config
['map']['radius'], $width/2 +
$this->config
['map']['radius'], $height/2 +
$this->config
['map']['radius']);
421 $image->drawImage($draw);
423 //Strip image exif data and properties
424 $image->stripImage();
427 //XXX: not supported by imagick :'(
428 $image->setImageProperty('exif:GPSLatitude', $this->image
->latitudeToSexagesimal($latitude));
431 //XXX: not supported by imagick :'(
432 $image->setImageProperty('exif:GPSLongitude', $this->image
->longitudeToSexagesimal($longitude));
434 //Set progressive jpeg
435 $image->setInterlaceScheme(\Imagick
::INTERLACE_PLANE
);
437 //Set compression quality
438 $image->setImageCompressionQuality($this->config
['map']['quality']);
441 if (!$image->writeImage($map)) {
443 throw new \
Exception(sprintf('Unable to write image "%s"', $map));
447 //Read map from cache
448 $response = new BinaryFileResponse($map);
451 $response->setContentDisposition(HeaderUtils
::DISPOSITION_INLINE
, basename($map));
454 $response->setEtag(md5(serialize([$height, $width, $zoom, $latitude, $longitude])));
457 $response->setLastModified(\DateTime
::createFromFormat('U', strval(stat($map)['mtime'])));
459 //Disable robot index
460 $response->headers
->set('X-Robots-Tag', 'noindex');
463 $response->setPublic();
465 //Return 304 response if not modified
466 $response->isNotModified($request);
473 * Return multi map image
475 * @param Request $request The Request instance
476 * @param string $hash The hash
477 * @param int $updated The updated timestamp
478 * @param float $latitude The latitude
479 * @param float $longitude The longitude
480 * @param string $coordinates The coordinates
481 * @param int $zoom The zoom
482 * @param int $width The width
483 * @param int $height The height
484 * @return Response The rendered image
486 public function multi(Request
$request, string $hash, string $coordinate, int $height, int $width, int $zoom, string $_format): Response
{
487 //Without matching hash
488 if ($hash !== $this->slugger
->hash([$height, $width, $zoom, $coordinate])) {
489 //Throw new exception
490 throw new NotFoundHttpException(sprintf('Unable to match multi map hash: %s', $hash));
493 //Set latitudes and longitudes array
494 $latitudes = $longitudes = [];
497 $coordinates = array_map(
498 function ($v) use (&$latitudes, &$longitudes) {
499 list($latitude, $longitude) = explode(',', $v);
500 $latitudes[] = $latitude;
501 $longitudes[] = $longitude;
502 return [ $latitude, $longitude ];
504 explode('-', $coordinate)
508 $latitude = round((min($latitudes)+
max($latitudes))/2, 6);
511 $longitude = round((min($longitudes)+
max($longitudes))/2, 6);
514 $map = $this->config
['cache'].'/'.$this->config
['prefixes']['multi'].'/'.$zoom.'/'.($latitude*1000000%
10).'/'.($longitude*1000000%
10).'/'.$coordinate.'-'.$zoom.'-'.$width.'x'.$height.'.'.$_format;
517 if (!is_file($map)) {
518 //Without existing multi path
519 if (!is_dir($dir = dirname($map))) {
520 //Create filesystem object
521 $filesystem = new Filesystem();
525 //XXX: set as 0775, symfony umask (0022) will reduce rights (0755)
526 //XXX: on CoW filesystems execute a chattr +C before filling
527 $filesystem->mkdir($dir, 0775);
528 } catch (IOExceptionInterface
$e) {
530 throw new \
Exception(sprintf('Output directory "%s" do not exists and unable to create it', $dir), 0, $e);
534 //Create image instance
535 $image = new \
Imagick();
538 $image->newImage($width, $height, new \
ImagickPixel('transparent'), $_format);
540 //Create tile instance
541 $tile = new \
Imagick();
544 $centerX = $this->image
->longitudeToX($longitude, $zoom);
545 $centerY = $this->image
->latitudeToY($latitude, $zoom);
548 $startX = floor(floor($centerX) - $width / $this->config
['multi']['tz']);
549 $startY = floor(floor($centerY) - $height / $this->config
['multi']['tz']);
552 $endX = ceil(ceil($centerX) +
$width / $this->config
['multi']['tz']);
553 $endY = ceil(ceil($centerY) +
$height / $this->config
['multi']['tz']);
555 for($x = $startX; $x <= $endX; $x++
) {
556 for($y = $startY; $y <= $endY; $y++
) {
558 $cache = $this->config
['cache'].'/'.$this->config
['prefixes']['multi'].'/'.$zoom.'/'.($x%
10).'/'.($y%
10).'/'.$x.','.$y.'.png';
560 //Without cache image
561 if (!is_file($cache)) {
563 $tileUri = str_replace(['{Z}', '{X}', '{Y}'], [$zoom, $x, $y], $this->config
['servers'][$this->config
['multi']['server']]);
566 if (!is_dir($dir = dirname($cache))) {
567 //Create filesystem object
568 $filesystem = new Filesystem();
572 //XXX: set as 0775, symfony umask (0022) will reduce rights (0755)
573 $filesystem->mkdir($dir, 0775);
574 } catch (IOExceptionInterface
$e) {
576 throw new \
Exception(sprintf('Output directory "%s" do not exists and unable to create it', $dir), 0, $e);
580 //Store tile in cache
581 file_put_contents($cache, file_get_contents($tileUri, false, $this->ctx
));
585 $destX = intval(floor($width / 2 - $this->config
['multi']['tz'] * ($centerX - $x)));
588 $destY = intval(floor($height / 2 - $this->config
['multi']['tz'] * ($centerY - $y)));
590 //Read tile from cache
591 $tile->readImage($cache);
594 $image->compositeImage($tile, \Imagick
::COMPOSITE_OVER
, $destX, $destY);
601 //Add imagick draw instance
602 //XXX: see https://www.php.net/manual/fr/imagick.examples-1.php#example-3916
603 $draw = new \
ImagickDraw();
606 $draw->setTextAntialias(true);
608 //Set stroke antialias
609 $draw->setStrokeAntialias(true);
612 $draw->setTextAlignment(\Imagick
::ALIGN_CENTER
);
615 $draw->setGravity(\Imagick
::GRAVITY_CENTER
);
617 //Iterate on locations
618 foreach($coordinates as $id => $coordinate) {
620 list($clatitude, $clongitude) = $coordinate;
623 $destX = intval(floor($width / 2 - $this->config
['multi']['tz'] * ($centerX - $this->image
->longitudeToX(floatval($clongitude), $zoom))));
626 $destY = intval(floor($height / 2 - $this->config
['multi']['tz'] * ($centerY - $this->image
->latitudeToY(floatval($clatitude), $zoom))));
629 $draw->setFillColor($this->config
['multi']['fill']);
632 $draw->setFontSize($this->config
['multi']['size']);
635 $draw->setStrokeColor($this->config
['multi']['border']);
638 $radius = $this->config
['multi']['radius'];
641 $stroke = $this->config
['multi']['thickness'];
643 //With matching position
644 if ($clatitude === $latitude && $clongitude == $longitude) {
646 $draw->setFillColor($this->config
['multi']['highfill']);
649 $draw->setFontSize($this->config
['multi']['highsize']);
652 $draw->setStrokeColor($this->config
['multi']['highborder']);
655 $radius = $this->config
['multi']['highradius'];
658 $stroke = $this->config
['multi']['highthickness'];
662 $draw->setStrokeWidth($stroke);
665 $draw->circle($destX - $radius, $destY - $radius, $destX +
$radius, $destY +
$radius);
668 $draw->setFillColor($draw->getStrokeColor());
671 $draw->setStrokeWidth($stroke / 4);
674 #$metrics = $image->queryFontMetrics($draw, strval($id));
677 $draw->annotation($destX - $radius, $destY +
$stroke, strval($id));
681 $image->drawImage($draw);
683 //Strip image exif data and properties
684 $image->stripImage();
687 //XXX: not supported by imagick :'(
688 $image->setImageProperty('exif:GPSLatitude', $this->image
->latitudeToSexagesimal($latitude));
691 //XXX: not supported by imagick :'(
692 $image->setImageProperty('exif:GPSLongitude', $this->image
->longitudeToSexagesimal($longitude));
695 //XXX: not supported by imagick :'(
696 #$image->setImageProperty('exif:Description', $caption);
698 //Set progressive jpeg
699 $image->setInterlaceScheme(\Imagick
::INTERLACE_PLANE
);
701 //Set compression quality
702 $image->setImageCompressionQuality($this->config
['multi']['quality']);
705 if (!$image->writeImage($map)) {
707 throw new \
Exception(sprintf('Unable to write image "%s"', $path));
711 //Read map from cache
712 $response = new BinaryFileResponse($map);
715 #$response->setContentDisposition(HeaderUtils::DISPOSITION_INLINE, 'multimap-'.$latitude.','.$longitude.'-'.$zoom.'-'.$width.'x'.$height.'.jpeg');
716 $response->setContentDisposition(HeaderUtils
::DISPOSITION_INLINE
, basename($map));
719 $response->setEtag(md5(serialize([$height, $width, $zoom, $coordinate])));
722 $response->setLastModified(\DateTime
::createFromFormat('U', strval(stat($map)['mtime'])));
724 //Disable robot index
725 $response->headers
->set('X-Robots-Tag', 'noindex');
728 $response->setPublic();
730 //Return 304 response if not modified
731 $response->isNotModified($request);
740 * @param Request $request The Request instance
741 * @param string $hash The hash
742 * @param string $path The image path
743 * @param int $width The width
744 * @param int $height The height
745 * @return Response The rendered image
747 public function thumb(Request
$request, string $hash, string $path, int $width, int $height, string $_format): Response
{
748 //Without matching hash
749 if ($hash !== $this->slugger
->serialize([$path, $width, $height])) {
750 //Throw new exception
751 throw new NotFoundHttpException('Invalid thumb hash');
752 //Without valid format
753 } elseif ($_format !== 'jpeg' && $_format !== 'png' && $_format !== 'webp') {
754 //Throw new exception
755 throw new NotFoundHttpException('Invalid thumb format');
759 $path = $this->slugger
->unshort($short = $path);
762 $thumb = $this->config
['cache'].'/'.$this->config
['prefixes']['thumb'].$path.'.'.$_format;
765 if (!is_file($path) || !($updated = stat($path)['mtime'])) {
766 //Throw new exception
767 throw new NotFoundHttpException('Unable to get thumb file');
770 //Without thumb up to date file
771 if (!is_file($thumb) || !($mtime = stat($thumb)['mtime']) || $mtime < $updated) {
772 //Without existing thumb path
773 if (!is_dir($dir = dirname($thumb))) {
774 //Create filesystem object
775 $filesystem = new Filesystem();
779 //XXX: set as 0775, symfony umask (0022) will reduce rights (0755)
780 //XXX: on CoW filesystems execute a chattr +C before filling
781 $filesystem->mkdir($dir, 0775);
782 } catch (IOExceptionInterface
$e) {
784 throw new \
Exception(sprintf('Output path "%s" do not exists and unable to create it', $dir), 0, $e);
788 //Create image instance
789 $image = new \
Imagick();
792 $image->readImage(realpath($path));
794 //Crop using aspect ratio
795 //XXX: for better result upload image directly in aspect ratio :)
796 $image->cropThumbnailImage($width, $height);
798 //Strip image exif data and properties
799 $image->stripImage();
801 //Set compression quality
803 $image->setImageCompressionQuality(70);
806 #$image->setImageFormat($_format);
809 if (!$image->writeImage($thumb)) {
811 throw new \
Exception(sprintf('Unable to write image "%s"', $thumb));
815 $mtime = stat($thumb)['mtime'];
818 //Read thumb from cache
819 $response = new BinaryFileResponse($thumb);
822 $response->setContentDisposition(HeaderUtils
::DISPOSITION_INLINE
, 'thumb-'.$hash.'.'.$_format);
825 $response->setEtag(md5($hash));
828 $response->setLastModified(\DateTime
::createFromFormat('U', strval($mtime)));
831 $response->setPublic();
833 //Return 304 response if not modified
834 $response->isNotModified($request);