getDate() public static method

Retrieves a formated date.
public static getDate ( string $timestamp, string $type = 'rfc1123' ) : string
$timestamp string Timestamp
$type string Format type
return string Formatted date
 public function execute($request)
 {
     $css = Doctrine::getTable('SnsConfig')->get('customizing_css', '');
     $this->getResponse()->setContent($css);
     $this->getResponse()->setContentType('text/css');
     // cache
     $filesystem = new sfFilesystem();
     $dir = sfConfig::get('sf_web_dir') . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'css';
     @$filesystem->mkdirs($dir);
     file_put_contents($dir . DIRECTORY_SEPARATOR . 'customizing.css', $css);
     $this->getResponse()->setHttpHeader('Last-Modified', sfWebResponse::getDate(time()));
     return sfView::NONE;
 }
 /**
  * Executes this filter.
  *
  * @param sfFilterChain $filterChain A sfFilterChain instance
  */
 public function execute($filterChain)
 {
     $filterChain->execute();
     $response = $this->getContext()->getResponse();
     $request = $this->getContext()->getRequest();
     if (!headers_sent()) {
         if ($request->getMobile()->isEZweb()) {
             $response->setHttpHeader('Expires', sfWebResponse::getDate(577731600));
             $response->setHttpHeader('LastModified', sfWebResponse::getDate(time()));
             $response->addCacheControlHttpHeader('no-store');
             $response->addCacheControlHttpHeader('no-cache');
             $response->addCacheControlHttpHeader('must-revalidate');
             $response->addCacheControlHttpHeader('post-check', 0);
             $response->addCacheControlHttpHeader('pre-check', 0);
             $response->setHttpHeader('Pragma', 'no-cache');
         }
     }
 }
 /**
  * Executes this filter.
  *
  * @param sfFilterChain $filterChain A sfFilterChain instance
  */
 public function execute($filterChain)
 {
     $filterChain->execute();
     if (!headers_sent()) {
         $response = $this->getContext()->getResponse();
         if (!$response->hasHttpHeader('Pragma') && !$response->hasHttpHeader('Expires') && !$response->hasHttpHeader('Cache-Control')) {
             $response->setHttpHeader('Expires', sfWebResponse::getDate(577731600));
             $response->setHttpHeader('LastModified', sfWebResponse::getDate(time()));
             $response->addCacheControlHttpHeader('no-store');
             $response->addCacheControlHttpHeader('no-cache');
             $response->addCacheControlHttpHeader('private');
             $response->addCacheControlHttpHeader('max-age', 0);
             $response->addCacheControlHttpHeader('must-revalidate');
             $response->addCacheControlHttpHeader('post-check', 0);
             $response->addCacheControlHttpHeader('pre-check', 0);
             $response->setHttpHeader('Pragma', 'no-cache');
         }
     }
 }
Exemplo n.º 4
0
<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <*****@*****.**>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
$app = 'cache';
if (!(include dirname(__FILE__) . '/../bootstrap/functional.php')) {
    return;
}
$b = new sfTestFunctional(new sfBrowser());
$b->info('No expiration (client_lifetime is 0)')->get('/httpcache/page1')->with('response')->begin()->isHeader('Last-Modified', '/^' . substr(preg_quote(sfWebResponse::getDate(time()), '/'), 5, 16) . '/')->isHeader('ETag', true)->isHeader('Expires', false)->isHeader('Cache-Control', false)->end();
$b->info('Expiration (client_lifetime is 86400)')->get('/httpcache/page2')->with('response')->begin()->isHeader('Last-Modified', false)->isHeader('ETag', false)->isHeader('Expires', '/^' . substr(preg_quote(sfWebResponse::getDate(time() + 86400), '/'), 5, 16) . '/')->isHeader('Cache-Control', '/max-age=86400/')->end();
$b->info('Expiration (client_lifetime is 86400) but the developer has set a Last-Modified header')->get('/httpcache/page3')->with('response')->begin()->isHeader('Last-Modified', '/^' . substr(preg_quote(sfWebResponse::getDate(time() - 86400), '/'), 5, 16) . '/')->isHeader('ETag', false)->isHeader('Expires', false)->isHeader('Cache-Control', false)->end();
$b->info('No expiration and the developer has set a Last-Modified header')->get('/httpcache/page4')->with('response')->begin()->isHeader('Last-Modified', '/^' . substr(preg_quote(sfWebResponse::getDate(time() - 86400), '/'), 5, 16) . '/')->isHeader('ETag', true)->isHeader('Expires', false)->isHeader('Cache-Control', false)->end();
Exemplo n.º 5
0
        $content2 = $response->getContent();
        $contentType2 = $response->getContentType();
        $headers2 = $response->getHttpHeaders();
        $b->test()->is($content1, $content2, 'response content is the same');
        $b->test()->is($contentType1, $contentType2, 'response content type is the same');
        $b->test()->is($headers1, $headers2, 'response http headers are the same');
    }
}
$b = new myTestBrowser();
// non HTML cache
$image = file_get_contents(__DIR__ . '/fixtures/apps/cache/modules/cache/data/ok48.png');
sfConfig::set('sf_web_debug', true);
$b->get('/cache/imageWithLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (with layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageWithLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (with layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageWithLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (with layout/action cache) in cache is not decorated when web_debug is on')->get('/cache/imageWithLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (with layout/action cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (no layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheWithLayout')->with('view_cache')->isCached(true, true)->checkResponseContent($image, 'image (no layout/page cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (no layout/action cache) in cache is not decorated when web_debug is on')->get('/cache/imageNoLayoutCacheNoLayout')->with('view_cache')->isCached(true)->checkResponseContent($image, 'image (no layout/action cache) in cache is not decorated when web_debug is on');
sfConfig::set('sf_web_debug', false);
// check stylesheets, javascripts inclusions
sfToolkit::clearDirectory(sfConfig::get('sf_app_cache_dir'));
$b->get('/cache/multiBis')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'multiBis')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]')->checkElement('script[src*="/main_js"]')->checkElement('link[href*="/partial_css"]')->checkElement('script[src*="/partial_js"]')->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]')->checkElement('script[src*="/component_js"]')->checkElement('#partial_slot_content', 'Partial')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', 'Component')->end()->get('/cache/multiBis')->with('response')->begin()->checkElement('link[href*="/main_css"]')->checkElement('script[src*="/main_js"]')->checkElement('link[href*="/partial_css"]')->checkElement('script[src*="/partial_js"]')->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]')->checkElement('script[src*="/component_js"]')->checkElement('#partial_slot_content', 'Partial')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', 'Component')->end();
$b->get('/cache/partial')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'partial')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]', false)->checkElement('script[src*="/main_js"]', false)->checkElement('link[href*="/partial_css"]')->checkElement('script[src*="/partial_js"]')->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]', false)->checkElement('script[src*="/component_js"]', false)->checkElement('#partial_slot_content', 'Partial')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', '')->end()->get('/cache/anotherPartial')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'anotherPartial')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]', false)->checkElement('script[src*="/main_js"]', false)->checkElement('link[href*="/partial_css"]', false)->checkElement('script[src*="/partial_js"]', false)->checkElement('link[href*="/another_partial_css"]')->checkElement('script[src*="/another_partial_js"]')->checkElement('link[href*="/component_css"]', false)->checkElement('script[src*="/component_js"]', false)->checkElement('#partial_slot_content', '')->checkElement('#another_partial_slot_content', 'Another Partial')->checkElement('#component_slot_content', '')->end()->get('/cache/component')->with('request')->begin()->isParameter('module', 'cache')->isParameter('action', 'component')->end()->with('response')->begin()->isStatusCode(200)->checkElement('link[href*="/main_css"]', false)->checkElement('script[src*="/main_js"]', false)->checkElement('link[href*="/partial_css"]', false)->checkElement('script[src*="/partial_js"]', false)->checkElement('link[href*="/another_partial_css"]', false)->checkElement('script[src*="/another_partial_js"]', false)->checkElement('link[href*="/component_css"]')->checkElement('script[src*="/component_js"]')->checkElement('#partial_slot_content', '')->checkElement('#another_partial_slot_content', '')->checkElement('#component_slot_content', 'Component')->end();
$b->get('/')->with('view_cache')->isUriCached('cache/list', false)->get('/cache/list')->with('view_cache')->isUriCached('cache/list', true)->with('view_cache')->isUriCached('cache/list?page=10', false)->get('/cache/list?page=10')->with('response')->checkElement('#page', '10')->with('view_cache')->isUriCached('cache/list?page=10', true)->with('view_cache')->isUriCached('cache/list?page=20', false)->get('/cache/list?page=20')->with('response')->checkElement('#page', '20')->with('view_cache')->isUriCached('cache/list?page=20', true);
// check for 304 response
sfConfig::set('LAST_MODIFIED', strtotime('2010-01-01'));
$b->get('/cache/lastModifiedResponse')->with('response')->isStatusCode(200);
$b->setHttpHeader('If-Modified-Since', sfWebResponse::getDate(sfConfig::get('LAST_MODIFIED')))->get('/cache/lastModifiedResponse')->with('response')->isStatusCode(304);
// test with sfFileCache class (default)
$b->launch();
// test with sfSQLiteCache class
if (extension_loaded('SQLite') || extension_loaded('pdo_SQLite')) {
    sfConfig::set('sf_factory_view_cache', 'sfSQLiteCache');
    sfConfig::set('sf_factory_view_cache_parameters', array('database' => sfConfig::get('sf_template_cache_dir') . DIRECTORY_SEPARATOR . 'cache.db'));
    $b->launch();
}
Exemplo n.º 6
0
 public function executePage4(sfWebRequest $request)
 {
     $this->getResponse()->setHttpHeader('Last-Modified', sfWebResponse::getDate(time() - 86400));
     $this->setTemplate('index');
 }
Exemplo n.º 7
0
  ->with('view_cache')->isUriCached('cache/list?page=10', true)

  // include different GET parameters
  ->with('view_cache')->isUriCached('cache/list?page=20', false)
  ->get('/cache/list?page=20')
  ->with('response')->checkElement('#page', '20')
  ->with('view_cache')->isUriCached('cache/list?page=20', true)
;

// check for 304 response
sfConfig::set('LAST_MODIFIED', strtotime('2010-01-01'));
$b->get('/cache/lastModifiedResponse')
  ->with('response')->isStatusCode(200)
;

$b->setHttpHeader('If-Modified-Since', sfWebResponse::getDate(sfConfig::get('LAST_MODIFIED')))
  ->get('/cache/lastModifiedResponse')
  ->with('response')->isStatusCode(304)
;

// test with sfFileCache class (default)
$b->launch();

// test with sfSQLiteCache class
if (extension_loaded('SQLite') || extension_loaded('pdo_SQLite'))
{
  sfConfig::set('sf_factory_view_cache', 'sfSQLiteCache');
  sfConfig::set('sf_factory_view_cache_parameters', array('database' => sfConfig::get('sf_template_cache_dir').DIRECTORY_SEPARATOR.'cache.db'));
  $b->launch();
}
Exemplo n.º 8
0
  get('/httpcache/page2')->
  with('response')->begin()->
    isHeader('Last-Modified', false)->
    isHeader('ETag', false)->
    isHeader('Expires', '/^'.substr(preg_quote(sfWebResponse::getDate(time() + 86400), '/'), 5, 16).'/')->
    isHeader('Cache-Control', '/max-age=86400/')->
  end()
;

$b->
  info('Expiration (client_lifetime is 86400) but the developer has set a Last-Modified header')->
  get('/httpcache/page3')->
  with('response')->begin()->
    isHeader('Last-Modified', '/^'.substr(preg_quote(sfWebResponse::getDate(time() - 86400), '/'), 5, 16).'/')->
    isHeader('ETag', false)->
    isHeader('Expires', false)->
    isHeader('Cache-Control', false)->
  end()
;

$b->
  info('No expiration and the developer has set a Last-Modified header')->
  get('/httpcache/page4')->
  with('response')->begin()->
    isHeader('Last-Modified', '/^'.substr(preg_quote(sfWebResponse::getDate(time() - 86400), '/'), 5, 16).'/')->
    isHeader('ETag', true)->
    isHeader('Expires', false)->
    isHeader('Cache-Control', false)->
  end()
;