Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[AsseticBundle] added etags to controller so changes to filters etc t…
…rigger invalidation
  • Loading branch information
kriswallsmith committed Feb 25, 2011
commit 968c870c9455c363ec14fed44e17313d6e4ec368
27 changes: 19 additions & 8 deletions src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Bundle\AsseticBundle\Controller;

use Assetic\Asset\AssetCache;
use Assetic\AssetManager;
use Assetic\Factory\LazyAssetManager;
use Assetic\Cache\CacheInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -29,7 +29,7 @@ class AsseticController
protected $am;
protected $cache;

public function __construct(Request $request, AssetManager $am, CacheInterface $cache)
public function __construct(Request $request, LazyAssetManager $am, CacheInterface $cache)
{
$this->request = $request;
$this->am = $am;
Expand All @@ -43,25 +43,36 @@ public function render($name)
}

$asset = $this->getAsset($name);
$response = $this->createResponse();

$response = new Response();

// validate if-modified-since
// last-modified
if (null !== $lastModified = $asset->getLastModified()) {
$date = new \DateTime();
$date->setTimestamp($lastModified);
$response->setLastModified($date);
}

// etag
if ($this->am->hasFormula($name)) {
$formula = $this->am->getFormula($name);
$formula['last_modified'] = $lastModified;
$response->setETag(md5(serialize($formula)));
}

if ($response->isNotModified($this->request)) {
return $response;
}
if ($response->isNotModified($this->request)) {
return $response;
}

$response->setContent($asset->dump());

return $response;
}

protected function createResponse()
{
return new Response();
}

protected function getAsset($name)
{
return new AssetCache($this->am->get($name), $this->cache);
Expand Down