This class manages web reponses. It supports cookies and headers management.
Author: Fabien Potencier (fabien.potencier@symfony-project.com)
Inheritance: extends sfResponse
 public static function addAssets(sfWebResponse $response)
 {
     $response->addStylesheet('yui/treeview/assets/skins/qubit/treeview-skin', 'first');
     $response->addJavaScript('/vendor/yui/treeview/treeview-min', 'last');
     $response->addJavaScript('/vendor/yui/dragdrop/dragdrop-min', 'last');
     $response->addJavaScript('treeView', 'last');
 }
 /**
  * This is the final Step in this 3 steps process:
  * <ol> 
  * <li>Step 1 consists in generating the XML bsaed raw data for the report. </li>
  * <li>Step 2 consists in merging this raw data with a XSL-FO template to give it
  * the presentation information. XSL-FO acts as an intermediate language used 
  * to render the final repor in any format with a last transformation. </li>
  * <li>Step 3 consists on rendering the XSL-FO representtion (the intermediate 
  * language) of the report to the PDF output fromat.</li>
  * <ol>
  * 
  * @param DOMDocument   $xslFo    The XSL-FO representation of the processed 
  * report, as we get it just after step 2 in this 3 steps process.
  * @param sfWebResponse $response The Response Object, should be passed all 
  * the way down from the action. So we can change some headers', ContentType
  * to 'application/pdf'.
  * 
  * @see %sf_plugins_dir%/NeatReports/config/sfExportGlobals.yml
  * @return String With the rendered report content. PDF Binary stream returned
  * by ApacheFop.
  */
 public function renderReport(DOMDocument $xslFo, sfWebResponse $response = null)
 {
     $response->setContentType('application/pdf');
     $response->setHttpHeader('Content-Disposition', "attachment; filename=report.pdf");
     $tStamp = microtime(true);
     $executable = stristr(PHP_OS, "WIN") ? 'fop.cmd' : 'fop';
     $output = array();
     $returnVar = 0;
     $foPath = __DIR__ . '/RenderPDF/tmp/report.fo.' . $tStamp;
     $pdfPath = __DIR__ . '/RenderPDF/tmp/report.pdf.' . $tStamp;
     try {
         file_put_contents($foPath, $xslFo->saveXML());
         $command = $this->_fopPath . $executable . ' -fo ' . $foPath . ' -pdf ' . $pdfPath;
         exec($command, $output, $returnVar);
         if ((bool) $returnVar) {
             throw new Exception(implode(PHP_EOL, $output), $returnVar);
         }
     } catch (Exception $e) {
         $ex = new Exception('Error executing Apache FOP, return value is pased to Exception Code.' . ' Command execution output follows:' . PHP_EOL . implode(PHP_EOL, $output), $returnVar, $e);
         throw $ex;
     }
     $out = file_get_contents($pdfPath);
     unlink($foPath);
     unlink($pdfPath);
     return $out;
 }
 public function executeSignout(sfWebResponse $request)
 {
     $this->getUser()->signOut();
     $signout_url = sfConfig::get('app_sf_guard_plugin_success_signout_url', $request->getReferer());
     $this->getUser()->setFlash('notice', 'U bent uitgelogd');
     $this->redirect('' != $signout_url ? $signout_url : '@homepage');
 }
Esempio n. 4
0
 /**
  * This is the final Step in this 3 steps process:
  * <ol> 
  * <li>Step 1 consists in generating the XML bsaed raw data for the report. </li>
  * <li>Step 2 consists in merging this raw data with a XSL-FO template to give it
  * the presentation information. XSL-FO acts as an intermediate language used 
  * to render the final repor in any format with a last transformation. </li>
  * <li>Step 3 consists on rendering the XSL-FO representtion (the intermediate 
  * language) of the report to the PDF output fromat.</li>
  * <ol>
  * Note that the PDF, will force download. You can override this.
  * 
  * @param DOMDocument   $xslFo    The XSL-FO representation of the processed 
  * report, as we get it just after step 2 in this 3 steps process.
  * @param sfWebResponse $response The Response Object, should be passed all 
  * the way down from the action. So we can change some headers', ContentType
  * to 'application/pdf'.
  * 
  * @see %sf_plugins_dir%/NeatReports/config/sfExportGlobals.yml
  * @return String With the rendered report content. PDF Binary stream returned
  * by ApacheFop.
  */
 public function renderReport(DOMDocument $xslFo, sfWebResponse $response = null)
 {
     $response->setContentType('application/pdf');
     $response->setHttpHeader('Content-Disposition', "attachment; filename=report.pdf");
     $this->_pdfRenderer = new RenderPDFConsummer($xslFo->saveXML());
     return $this->_pdfRenderer->getPdfStream();
 }
 public static function addAssets(sfWebResponse $response)
 {
     if (sfConfig::get('app_show_tooltips')) {
         $response->addJavaScript('description');
     } else {
         $response->addStylesheet('hide_tooltips');
     }
 }
 public function getResponse()
 {
     static $response;
     if (!$response) {
         $response = new sfWebResponse();
         $response->initialize($this);
     }
     return $response;
 }
Esempio n. 7
0
 public function getTitle()
 {
     $result = parent::getTitle();
     if (!$result) {
         $result = opConfig::get('sns_title') ? opConfig::get('sns_title') : opConfig::get('sns_name');
     }
     return $result;
 }
Esempio n. 8
0
 public function initialize(sfEventDispatcher $dispatcher, $options = array())
 {
     parent::initialize($dispatcher, $options);
     $this->javascriptConfig = array();
     $this->dispatcher->connect('user.change_culture', array($this, 'listenToChangeCultureEvent'));
     $this->dispatcher->connect('user.change_theme', array($this, 'listenToChangeThemeEvent'));
     $this->dispatcher->connect('user.remember_me', array($this, 'listenToRememberMeEvent'));
     $this->dispatcher->connect('user.sign_out', array($this, 'listenToSignOutEvent'));
 }
 public function getTitle()
 {
     $parts = array();
     if (parent::getTitle()) {
         $parts[] = parent::getTitle();
     }
     $parts[] = sfConfig::get('app_version_name');
     return implode(' - ', $parts);
 }
 /**
  * Replaces response original stylesheets by optimized ones (only if stylesheet 
  * optimization has been enabled by configuration)
  *
  * @param  sfWebresponse  $response
  */
 public function replaceStylesheets(sfWebResponse $response)
 {
     if (is_null($stylesheetOptimizer = $this->getOptimizer('stylesheet'))) {
         return;
     }
     foreach ($stylesheetOptimizer->getAssetFiles() as $file) {
         $response->removeStylesheet($file);
     }
     $response->addStylesheet($stylesheetOptimizer->getOptimizedFileWebPath(), 'first');
 }
 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');
         }
     }
 }
 protected function prepareAssetsForNativeApp(sfWebRequest $request, sfWebResponse $response, $buildSettings)
 {
     $this->isInitialRequest = !$request->isXmlHttpRequest();
     foreach ($buildSettings['javascripts'] as $file) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($file);
         if ($this->isInitialRequest) {
             $response->addJavascript($filename, $position);
         } else {
             $response->removeJavascript($filename, $position);
         }
     }
     foreach ($buildSettings['stylesheets'] as $file) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($file);
         if ($this->isInitialRequest) {
             $response->addStylesheet($filename, $position);
         } else {
             $response->removeStylesheet($filename, $position);
         }
     }
     $excludeStylesheets = $buildSettings['excludeStylesheets'];
     foreach ($excludeStylesheets as $assetResource) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($assetResource);
         $response->removeStylesheet($filename, $position);
     }
     $excludeJavascripts = $buildSettings['excludeJavascripts'];
     foreach ($excludeJavascripts as $assetResource) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($assetResource);
         $response->removeJavascript($filename, $position);
     }
     $context = $this->getContext();
     if (method_exists($context, 'getConfiguration') && method_exists($context->getConfiguration(), 'loadHelpers')) {
         $context->getConfiguration()->loadHelpers('Asset');
     } else {
         if (method_exists('sfLoader', 'loadHelpers')) {
             sfLoader::loadHelpers('Asset');
             //compatibility with symfony 1.0:
         }
     }
     sfConfig::set('symfony.asset.stylesheets_included', true);
     sfConfig::set('symfony.asset.javascripts_included', true);
     $css = '';
     $js = '';
     foreach (array('first', '', 'last') as $position) {
         $stylesheets = $response->getStylesheets($position);
         if (!empty($stylesheets)) {
             $css .= "\n/* position: {$position} */\n";
             $css .= $this->getCombinedAssetsAsString($stylesheets, 'stylesheet_path');
         }
         $javascripts = $response->getJavascripts($position);
         if (!empty($javascripts)) {
             $jsCurrent = $this->getCombinedAssetsAsString($javascripts, 'javascript_path');
             $jsCurrent = str_replace(array("'<script>", "</script>'"), array("'<scr'+'ipt>", "</scr'+'ipt>'"), $jsCurrent);
             //hack to avoid breaking code in jQuery mobile: domain && iframe_doc.write( '<script>document.domain="' + domain + '"</script>' );
             $js .= "\n/* position: {$position} */\n";
             $js .= $jsCurrent;
         }
     }
     if ($this->isInitialRequest) {
         //embed everything directly into main file
         $css = $this->base64EncodeImages($css);
         $this->cssContent = $css;
         $this->jsContent = $js;
         $this->jsContent2 = 'test';
     } else {
         $this->cssSrc = $this->getContentAsFileSrc($css, 'css');
         if (!$this->cssSrc) {
             $this->cssContent = $css;
         }
         //		    $this->jsSrc = $this->getContentAsFileSrc($js, 'js');
         //		    if (!$this->jsSrc) {
         //		    	$this->jsContent = $js;
         //		    }
         $this->jsContent = $js;
         //we have to load javascripts inline because iOs Safari loads external javascripts asynchronesly and thus we could nomore rely on events like pagecreate, pageshow, pagehide dom.ready etc
     }
 }
 /**
  * Initialize
  * 
  * @param   sfEventDispatcher   $dispatcher
  * @param   array               $options    Response options [optional]
  * @return  void
  */
 public function initialize(sfEventDispatcher $dispatcher, $options = array())
 {
     parent::initialize($dispatcher, $options);
 }
Esempio n. 16
0
 public function normalizeHeaderName($name)
 {
   return parent::normalizeHeaderName($name);
 }
        $response->addJavascript('multiple', 'last');
        $response->addStylesheet('last1', 'last');
        $response->addStylesheet('first1', 'first');
        $response->addStylesheet('middle');
        $response->addStylesheet('last2', 'last');
        $response->addStylesheet('multiple');
        $response->addStylesheet('multiple');
        $response->addStylesheet('first2', 'first');
        $response->addStylesheet('multiple', 'last');
        $filterChain->execute();
        // sfCommmonFilter has executed all its code
    }
}
$context = sfContext::getInstance();
$context->request = new myRequest();
$response = new sfWebResponse();
$response->initialize($context);
$context->response = $response;
$selector = execute_filter_chain($context, $t);
check_javascripts_included($t, $selector);
check_stylesheets_included($t, $selector);
// test disabling javascript and stylesheet automatic inclusion
$response->setParameter('stylesheets_included', true, 'symfony/view/asset');
$response->setParameter('javascripts_included', true, 'symfony/view/asset');
$selector = execute_filter_chain($context, $t);
$t->is($selector->getElements('head script'), array(), '->execute() does not add javascripts if you used get_javascripts() helper');
$t->is($selector->getElements('head link'), array(), '->execute() does not add stylesheets if you used get_stylesheets() helper');
$response->setParameter('stylesheets_included', true, 'symfony/view/asset');
$response->setParameter('javascripts_included', false, 'symfony/view/asset');
$selector = execute_filter_chain($context, $t);
check_javascripts_included($t, $selector);
    $t->pass('optimizeJavascripts() can optimize js files');
} catch (RuntimeException $e) {
    $t->fail('optimizeJavascripts() can optimize js files');
}
// optimizeStylesheets()
$t->diag('optimizeStylesheets()');
$service = new npAssetsOptimizerService($dispatcher, array('stylesheet' => array('enabled' => true, 'class' => 'npOptimizerStylesheet', 'params' => array('destination' => '/css/my_optimized.css', 'files' => array('foo.css')))), $baseAssetsDir);
try {
    $service->optimizeStylesheets();
    $t->pass('optimizeStylesheets() can optimize css files');
} catch (RuntimeException $e) {
    $t->fail('optimizeStylesheets() can optimize css files');
}
// replaceJavascripts()
$t->diag('replaceJavascripts()');
$service = new npAssetsOptimizerService($dispatcher, array('javascript' => array('enabled' => true, 'class' => 'npOptimizerJavascript', 'params' => array('destination' => '/js/my_optimized.js', 'files' => array('foo.js')))), $baseAssetsDir);
$response = new sfWebResponse($dispatcher, array());
$response->addJavascript('foo.js');
$service->replaceJavascripts($response);
$responseJS = array_keys($response->getJavascripts());
$t->is(count($responseJS), 1, 'replaceJavascripts() replaced javascripts');
$t->is($responseJS[0], '/js/my_optimized.js', 'replaceJavascripts() replaced javascripts');
// replaceStylesheets()
$t->diag('replaceStylesheets()');
$service = new npAssetsOptimizerService($dispatcher, array('stylesheet' => array('enabled' => true, 'class' => 'npOptimizerStylesheet', 'params' => array('destination' => '/css/my_optimized.css', 'files' => array('foo.css')))), $baseAssetsDir);
$response = new sfWebResponse($dispatcher, array());
$response->addStylesheet('foo.css');
$service->replaceStylesheets($response);
$responseCSS = array_keys($response->getStylesheets());
$t->is(count($responseCSS), 1, 'replaceStylesheets() replaced stylesheets');
$t->is($responseCSS[0], '/css/my_optimized.css', 'replaceStylesheets() replaced stylesheets');
 public static function addAssets(sfWebResponse $response)
 {
     $response->addStylesheet('/vendor/imageflow/imageflow.packed.css', 'first');
     $response->addJavaScript('/vendor/imageflow/imageflow.packed.js', 'last');
     $response->addJavaScript('imageflow', 'last');
 }
 /**
  * Convert the symfony 1.4 response to a Response.
  * @param  \sfWebResponse $legacyResponse
  * @return Response
  */
 private function convertResponse($legacyResponse)
 {
     $response = new Response($legacyResponse->getContent(), $legacyResponse->getStatusCode());
     $response->setCharset($legacyResponse->getCharset());
     $response->setStatusCode($legacyResponse->getStatusCode());
     foreach ($legacyResponse->getHttpHeaders() as $headerName => $headerValue) {
         $response->headers->set($headerName, $headerValue);
     }
     return $response;
 }
Esempio n. 21
0
 public function executePage4(sfWebRequest $request)
 {
     $this->getResponse()->setHttpHeader('Last-Modified', sfWebResponse::getDate(time() - 86400));
     $this->setTemplate('index');
 }
 /**
  *  Saves the visibility option of a poll in a cookie.
  * 
  * @param sfWebRequest $request
  * @param sfWebResponse $response
  * @param aPollPoll $poll
  * @param type $value
  * @throws sfException 
  */
 static function setShowPollToCookie(sfWebRequest $request, sfWebResponse $response, aPollPoll $poll, $value)
 {
     $id = $poll->getId();
     $cookie = self::getCookieContent($request);
     if (!($value === true || $value === false)) {
         throw new sfException(__FUNCTION__ . ' only accepts "true" and "false" as values.');
     }
     $cookie = array_merge($cookie, array($id => array('show' => $value, 'timeout' => time() + self::getCookieLifetime($poll))));
     $response->setCookie(self::getCookieName(), self::encodeForCookie($cookie), time() + self::getCookieLifetime($poll));
 }
 public function execute($dispatcher, $request)
 {
     $response = new sfWebResponse($dispatcher);
     $response->setContent($this->render($this->getTemplateValues($request)));
     return $response;
 }
 /**
  * Update the response meta values with the data contained within an array.
  *
  * @param array $data
  * @param sfWebResponse $sf_response
  * @return void
  */
 public static function setCommonMetas(array $data, sfWebResponse $sf_response)
 {
     foreach ($data as $key => $value) {
         $sf_response->addMeta($key, $value);
     }
 }
Esempio n. 25
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();
Esempio n. 26
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();
}
Esempio n. 27
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();
}
 /**
  * Gets the current response content
  *
  * @return string Content
  */
 public function getContent()
 {
     ProjectConfiguration::getActive()->loadHelpers(array('sfPlop'));
     return remove_whitespaces_from_html(parent::getContent());
 }
Esempio n. 29
0
 /**
  * Merges all properties from a given sfWebResponse object to the current one.
  *
  * @param sfWebResponse $response  An sfWebResponse instance
  */
 public function merge(sfWebResponse $response)
 {
     foreach ($this->getPositions() as $position) {
         $this->javascripts[$position] = array_merge($this->getJavascripts($position), $response->getJavascripts($position));
         $this->stylesheets[$position] = array_merge($this->getStylesheets($position), $response->getStylesheets($position));
     }
     $this->slots = array_merge($this->getSlots(), $response->getSlots());
 }
Esempio n. 30
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()
;