Skip to content

[AsseticBundle] added ETags to the development controller #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Feb 25, 2011
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
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy