Skip to content

Instantly share code, notes, and snippets.

@jenkoian
Created January 29, 2013 22:07
Show Gist options
  • Save jenkoian/4668398 to your computer and use it in GitHub Desktop.
Save jenkoian/4668398 to your computer and use it in GitHub Desktop.
Abstract parent class for common rest controller methods.
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\View\View;
use Doctrine\ORM\EntityRepository;
abstract class RestController extends FOSRestController
{
/**
* @var Response
*/
protected $lastModifiedResponse;
/**
* @param \DateTime $lastModified
* @return bool
*/
public function isNotModified(\DateTime $lastModified)
{
$this->lastModifiedResponse = new Response();
$this->lastModifiedResponse->setLastModified($lastModified);
$this->lastModifiedResponse->setPublic();
if ($this->lastModifiedResponse->isNotModified($this->getRequest())) {
return true;
}
return false;
}
/**
* @return Response
*/
public function getLastModifiedResponse()
{
return $this->lastModifiedResponse;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment