Development

Changeset 7723

You must first sign up to be able to contribute.

Changeset 7723

Show
Ignore:
Timestamp:
03/03/08 12:24:09 (6 months ago)
Author:
fabien
Message:

added sfWebResponse::merge(), rename sfWebResponse::mergeProperties() to sfWebResponse::copyProperties(), added response in partial serialization (not used for now)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/response/sfWebResponse.class.php

    r7722 r7723  
    681681   * @param sfWebResponse A sfWebResponse instance 
    682682   */ 
    683   public function mergeProperties(sfWebResponse $response) 
    684   { 
    685     $this->options      = $response->getOptions(); 
    686     $this->headers      = $response->getHttpHeaders(); 
    687     $this->metas        = $response->getMetas(); 
    688     $this->httpMetas    = $response->getHttpMetas(); 
    689     $this->stylesheets  = $response->getStylesheets('ALL'); 
    690     $this->javascripts  = $response->getJavascripts('ALL'); 
    691     $this->slots        = $response->getSlots(); 
     683  public function copyProperties(sfWebResponse $response) 
     684  { 
     685    $this->options     = $response->getOptions(); 
     686    $this->headers     = $response->getHttpHeaders(); 
     687    $this->metas       = $response->getMetas(); 
     688    $this->httpMetas   = $response->getHttpMetas(); 
     689    $this->stylesheets = $response->getStylesheets('ALL'); 
     690    $this->javascripts = $response->getJavascripts('ALL'); 
     691    $this->slots       = $response->getSlots(); 
     692  } 
     693 
     694  /** 
     695   * Merges all properties from a given sfWebResponse object to the current one. 
     696   * 
     697   * @param sfWebResponse A sfWebResponse instance 
     698   */ 
     699  public function merge(sfWebResponse $response) 
     700  { 
     701    foreach ($this->getPositions() as $position) 
     702    { 
     703      $this->javascripts[$position] = array_merge($this->getJavascripts($position), $response->getJavascripts($position)); 
     704      $this->stylesheets[$position] = array_merge($this->getStylesheets($position), $response->getStylesheets($position)); 
     705    } 
     706 
     707    $this->slots = array_merge($this->getSlots(), $response->getSlots()); 
    692708  } 
    693709 
  • branches/1.1/lib/test/sfTestBrowser.class.php

    r5154 r7723  
    428428          $this->test->ok($content == $this->getResponse()->getContent(), 'content in cache is ok'); 
    429429        } 
    430         else if (true === $main) 
     430        else 
    431431        { 
    432432          $ret = unserialize($cacheManager->get($uri)); 
    433433          $content = $ret['content']; 
    434           $this->test->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok'); 
    435         } 
    436         else 
    437         { 
    438           $content = $cacheManager->get($uri); 
    439434          $this->test->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok'); 
    440435        } 
  • branches/1.1/lib/view/sfViewCacheManager.class.php

    r7722 r7723  
    559559 
    560560    // retrieve content from cache 
    561     $content = $this->get($uri); 
    562  
    563     if (is_null($content)) 
     561    $cache = $this->get($uri); 
     562 
     563    if (is_null($cache)) 
    564564    { 
    565565      return null; 
    566566    } 
     567 
     568    $cache = unserialize($cache); 
     569    $content = $cache['content']; 
     570    $this->context->getResponse()->merge($cache['response']); 
    567571 
    568572    if (sfConfig::get('sf_web_debug')) 
     
    591595    } 
    592596 
    593     $saved = $this->set($content, $uri); 
     597    $saved = $this->set(serialize(array('content' => $content, 'response' => $this->context->getResponse())), $uri); 
    594598 
    595599    if ($saved && sfConfig::get('sf_web_debug')) 
     
    638642    $content = $cache['content']; 
    639643    $cache['response']->setEventDispatcher($this->dispatcher); 
    640     $this->context->getResponse()->mergeProperties($cache['response']); 
     644    $this->context->getResponse()->copyProperties($cache['response']); 
    641645 
    642646    if (sfConfig::get('sf_web_debug')) 
  • branches/1.1/test/unit/response/sfWebResponseTest.php

    r7714 r7723  
    163163$t->is($response->getHttpHeader('Cache-Control'), 'max-age=12, no-cache', '->addCacheControlHttpHeader() respects ordering'); 
    164164 
    165 // ->mergeProperties() 
    166 $t->diag('->mergeProperties()'); 
     165// ->copyProperties() 
     166$t->diag('->copyProperties()'); 
    167167$response1 = new myWebResponse($dispatcher); 
    168168$response2 = new myWebResponse($dispatcher); 
     
    172172$response1->setTitle('My title'); 
    173173 
    174 $response2->mergeProperties($response1); 
    175 $t->is($response1->getHttpHeader('symfony'), $response2->getHttpHeader('symfony'), '->mergeProperties() merges http headers'); 
    176 $t->is($response1->getContentType(), $response2->getContentType(), '->mergeProperties() merges content type'); 
    177 $t->is($response1->getTitle(), $response2->getTitle(), '->mergeProperties() merges titles'); 
     174$response2->copyProperties($response1); 
     175$t->is($response1->getHttpHeader('symfony'), $response2->getHttpHeader('symfony'), '->copyProperties() merges http headers'); 
     176$t->is($response1->getContentType(), $response2->getContentType(), '->copyProperties() merges content type'); 
     177$t->is($response1->getTitle(), $response2->getTitle(), '->copyProperties() merges titles'); 
    178178 
    179179// ->addStylesheet()