Skip to content

Commit

Permalink
Symfony 3.0 compatbility
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdebril committed May 31, 2015
1 parent 1bb246b commit 704d777
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions Controller/StreamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ class StreamController extends Controller

/**
* @Route("/stream/{id}")
* @Template()
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
$options = $request->attributes->get('_route_params');
$this->setModifiedSince($request);
$options['Since'] = $this->getModifiedSince();

return $this->createStreamResponse(
Expand All @@ -50,18 +52,29 @@ public function indexAction(Request $request)
protected function getModifiedSince()
{
if (is_null($this->since)) {
if ($this->getRequest()->headers->has('If-Modified-Since')) {
$string = $this->getRequest()->headers->get('If-Modified-Since');
$this->since = \DateTime::createFromFormat(\DateTime::RSS, $string);
} else {
$this->since = new \DateTime();
$this->since->setTimestamp(1);
}
$this->since = new \DateTime('@0');
}

return $this->since;
}

/**
* @param Request $request
* @return $this
*/
protected function setModifiedSince(Request $request)
{
$this->since = new \DateTime();
if ($request->headers->has('If-Modified-Since')) {
$string = $request->headers->get('If-Modified-Since');
$this->since = \DateTime::createFromFormat(\DateTime::RSS, $string);
} else {
$this->since->setTimestamp(1);
}

return $this;
}

/**
* Generate the HTTP response
* 200 : a full body containing the stream
Expand Down Expand Up @@ -100,7 +113,7 @@ protected function createStreamResponse(array $options, $format, $source = self:
* The FeedContentProviderInterface instance is provided as a service
* default : debril.provider.service.
*
* @param \Symfony\Component\OptionsResolver\Options $options
* @param array $options
* @param string $source
*
* @return \Debril\RssAtomBundle\Protocol\FeedOutInterface
Expand Down

0 comments on commit 704d777

Please sign in to comment.