Changeset 2205

Show
Ignore:
Timestamp:
12/06/07 02:46:59 (13 months ago)
Author:
david
Message:

Fixed an issue where output types of forwards were not honored completely. Closes #629. Also redone the global request data locking during template rendering and fixed global request data serialization in execution containers. Closes #628 and #633.
This change adds an output type member to response. Use that to check for the actual response content type, not the one in the execution container - it's more reliable. See changes done to FPF and ETF in this commit.

Location:
branches/0.11/src
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/src/controller/AgaviController.class.php

    r2108 r2205  
    195195       
    196196      if($this->getParameter('send_response')) { 
    197         $response->send($container->getOutputType()); 
     197        $response->send(); 
    198198      } 
    199199       
  • branches/0.11/src/controller/AgaviExecutionContainer.class.php

    r2115 r2205  
    120120    $this->outputTypeName = $this->outputType->getName(); 
    121121    $arr = get_object_vars($this); 
    122     unset($arr['context'], $arr['outputType'], $arr['requestData']); 
     122    unset($arr['context'], $arr['outputType'], $arr['requestData'], $arr['globalRequestData']); 
    123123    return array_keys($arr); 
    124124  } 
     
    137137    $this->context = AgaviContext::getInstance($this->contextName); 
    138138    $this->outputType = $this->context->getController()->getOutputType($this->outputTypeName); 
    139     $rq = $this->context->getRequest(); 
    140     if($rq->isLocked()) { 
    141       $this->requestData = new AgaviRequestDataHolder(); 
    142     } else { 
    143       $this->requestData = $rq->getRequestData(); 
     139    try { 
     140      $this->globalRequestData = $this->context->getRequest()->getRequestData(); 
     141    } catch(AgaviException $e) { 
     142      $this->globalRequestData = new AgaviRequestDataHolder(); 
    144143    } 
    145144    unset($this->contextName, $this->outputTypeName); 
     
    162161 
    163162    $this->parameters = $parameters; 
     163 
     164    $rfi = $this->context->getFactoryInfo('response'); 
     165    $this->response = new $rfi['class']; 
     166    $this->response->initialize($this->context, $rfi['parameters']); 
    164167  } 
    165168 
     
    481484  { 
    482485    $this->response = $response; 
     486    // do not set the output type on the response here! 
    483487  } 
    484488 
     
    507511  { 
    508512    $this->outputType = $outputType; 
     513    if($this->response) { 
     514      $this->response->setOutputType($outputType); 
     515    } 
    509516  } 
    510517 
  • branches/0.11/src/filter/AgaviExecutionFilter.class.php

    r2200 r2205  
    302302    } 
    303303 
    304     // create a new response instance for this action 
    305     $rfi = $this->context->getFactoryInfo('response'); 
    306     $response = new $rfi['class']; 
    307     $response->initialize($this->context, $rfi['parameters']); 
    308     $container->setResponse($response); 
     304    // clear the response 
     305    $response = $container->getResponse(); 
     306    $response->clear(); 
    309307 
    310308    // clear any forward set, it's ze view's job 
     
    435433        $attributes =& $viewInstance->getAttributes(); 
    436434 
    437         // lock the request. doing it here for all runs is fine, and quicker too 
    438         $key = $request->toggleLock(); 
    439435        // $lm->log('Starting rendering...'); 
    440436        for($i = 0; $i < count($layers); $i++) { 
     
    469465            'view' => $viewInstance, 
    470466          ); 
     467          // lock the request. can't be done outside the loop for the whole run, see #628 
     468          $key = $request->toggleLock(); 
    471469          $nextOutput = $layer->getRenderer()->render($layer, $attributes, $output, $moreAssigns); 
     470          // and unlock the request again 
     471          $request->toggleLock($key); 
    472472 
    473473          $response->setContent($nextOutput); 
     
    480480          $output[$layer->getName()] = $nextOutput; 
    481481        } 
    482         // and unlock the request again 
    483         $request->toggleLock($key); 
    484482      } 
    485483 
  • branches/0.11/src/filter/AgaviExecutionTimeFilter.class.php

    r1680 r2205  
    6464    $filterChain->execute($container); 
    6565     
    66     $outputTypes = (array) $this->getParameter('output_types'); 
    67     if(is_array($outputTypes) && !in_array($container->getOutputType()->getName(), $outputTypes)) { 
    68       return; 
    69     } 
    70      
    7166    $response = $container->getResponse(); 
    7267     
    73     if(!$response->isContentMutable()) { 
     68    $outputTypes = (array) $this->getParameter('output_types'); 
     69    if(!$response->isContentMutable() || (is_array($outputTypes) && !in_array($response->getOutputType()->getName(), $outputTypes))) { 
    7470      return; 
    7571    } 
  • branches/0.11/src/filter/AgaviFormPopulationFilter.class.php

    r2168 r2205  
    7878    $cfg = $rq->getAttributes('org.agavi.filter.FormPopulationFilter'); 
    7979 
    80     $ot = $container->getOutputType(); 
     80    $ot = $response->getOutputType(); 
    8181 
    8282    if(is_array($cfg['output_types']) && !in_array($ot->getName(), $cfg['output_types'])) { 
  • branches/0.11/src/response/AgaviResponse.class.php

    r1960 r2205  
    4141   
    4242  /** 
     43   * @var        AgaviOutputType The output type of this response. 
     44   */ 
     45  protected $outputType = null; 
     46   
     47  /** 
    4348   * Pre-serialization callback. 
    4449   * 
     
    5055  public function __sleep() 
    5156  { 
     57    $vars = get_object_vars($this); 
     58    $also = array(); 
     59     
    5260    $this->contextName = $this->context->getName(); 
     61    unset($vars['context']); 
     62    $also[] = 'contextName'; 
     63     
     64    if($this->outputType) { 
     65      $this->outputTypeName = $this->outputType->getName(); 
     66      unset($vars['outputType']); 
     67      $also[] = 'outputTypeName'; 
     68    } 
     69     
    5370    if(is_resource($this->content)) { 
    5471      $this->contentStreamMeta = stream_get_meta_data($this->content); 
    55     } 
    56     $arr = get_object_vars($this); 
    57     unset($arr['context']); 
    58     if(isset($this->contentStreamMeta)) { 
    59       unset($arr['content']); 
    60     } 
    61     return array_keys($arr); 
     72      unset($vars['content']); 
     73      $also[] = 'contentStreamMeta'; 
     74    } 
     75     
     76    return array_merge(array_keys($vars), $also); 
    6277  } 
    6378   
     
    7489    $this->context = AgaviContext::getInstance($this->contextName); 
    7590    unset($this->contextName); 
     91     
     92    if(isset($this->outputTypeName)) { 
     93      $this->outputType = $this->context->getController()->getOutputType($this->outputTypeName); 
     94      unset($this->outputTypeName); 
     95    } 
     96     
    7697    if(isset($this->contentStreamMeta)) { 
    7798      // contrary to what the documentation says, stream_get_meta_data() will not return a list of filters attached to the stream, so we cannot restore these, unfortunately. 
     
    107128    $this->context = $context; 
    108129    $this->setParameters($parameters); 
     130  } 
     131   
     132  /** 
     133   * Get the Output Type to use with this response. 
     134   * 
     135   * @return     AgaviOutputType The Output Type instance associated with. 
     136   * 
     137   * @author     David Zülke <dz@bitxtender.com> 
     138   * @since      0.11.1 
     139   */ 
     140  public function getOutputType() 
     141  { 
     142    return $this->outputType; 
     143  } 
     144   
     145  /** 
     146   * Set the Output Type to use with this response. 
     147   * 
     148   * @param      AgaviOutputType The Output Type instance to associate with. 
     149   * 
     150   * @author     David Zülke <dz@bitxtender.com> 
     151   * @since      0.11.1 
     152   */ 
     153  public function setOutputType(AgaviOutputType $outputType) 
     154  { 
     155    $this->outputType = $outputType; 
     156  } 
     157   
     158  /** 
     159   * Clear the Output Type to use with this response. 
     160   * 
     161   * @author     David Zülke <dz@bitxtender.com> 
     162   * @since      0.11.1 
     163   */ 
     164  public function clearOutputType() 
     165  { 
     166    $this->outputType = null; 
    109167  } 
    110168   
  • branches/0.11/src/response/AgaviWebResponse.class.php

    r2171 r2205  
    592592  protected function sendHttpResponseHeaders(AgaviOutputType $outputType = null) 
    593593  { 
     594    if($outputType === null) { 
     595      $outputType = $this->getOutputType(); 
     596    } 
     597     
    594598    $file = $line = ''; 
    595599    if(headers_sent($file, $line)) {