Skip to content

Instantly share code, notes, and snippets.

@tystr
Created March 8, 2018 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tystr/b4c36defa376028f62bf4decaeff411c to your computer and use it in GitHub Desktop.
Save tystr/b4c36defa376028f62bf4decaeff411c to your computer and use it in GitHub Desktop.
<?php
namespace App\Response;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Response;
class TransparentImagePixelResponse extends Response
{
/**
* @var string
*/
const IMAGE_CONTENT = 'R0lGODlhAQABAJAAAP8AAAAAACH5BAUQAAAALAAAAAABAAEAAAICBAEAOw==';
/**
* @var string
*/
const CONTENT_TYPE = 'image/gif';
public function __construct()
{
parent::__construct(base64_decode(static::IMAGE_CONTENT));
$this->headers->set('Content-Type', static::CONTENT_TYPE);
$this->setPrivate();
$this->headers->addCacheControlDirective('no-cache', true);
$this->headers->addCacheControlDirective('must-revalidate', true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment