This commit is contained in:
Malte Hübner 2018-02-14 18:26:22 +01:00
parent c32c5ff1a0
commit 864f2be68f
4 changed files with 21 additions and 25 deletions

View File

@ -0,0 +1,17 @@
<?php
namespace StaticMapLite\Output;
abstract class AbstractOutput implements OutputInterface
{
public function sendHeader(): OutputInterface
{
header('Content-Type: image/png');
$expires = 60 * 60 * 24 * 14;
header('Pragma: public');
header('Cache-Control: maxage=' . $expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
return $this;
}
}

View File

@ -2,7 +2,7 @@
namespace StaticMapLite\Output;
class CacheOutput implements OutputInterface
class CacheOutput extends AbstractOutput
{
protected $filename;
@ -13,17 +13,6 @@ class CacheOutput implements OutputInterface
return $this;
}
public function sendHeader(): OutputInterface
{
header('Content-Type: image/png');
$expires = 60 * 60 * 24 * 14;
header('Pragma: public');
header('Cache-Control: maxage=' . $expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
return $this;
}
public function sendImage(): void
{
echo file_get_contents($this->filename);

View File

@ -2,7 +2,7 @@
namespace StaticMapLite\Output;
class ImageOutput implements OutputInterface
class ImageOutput extends AbstractOutput
{
protected $image;
@ -13,17 +13,6 @@ class ImageOutput implements OutputInterface
return $this;
}
public function sendHeader(): OutputInterface
{
header('Content-Type: image/png');
$expires = 60 * 60 * 24 * 14;
header('Pragma: public');
header('Cache-Control: maxage=' . $expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
return $this;
}
public function sendImage(): bool
{
return imagepng($this->image);

View File

@ -4,5 +4,6 @@ namespace StaticMapLite\Output;
interface OutputInterface
{
public function sendHeader();
public function sendImage();
}