Development

Changeset 4895

You must first sign up to be able to contribute.

Changeset 4895

Show
Ignore:
Timestamp:
08/24/07 15:26:53 (2 years ago)
Author:
fabien
Message:

refactored request and response classes

  • removed sfContext dependency for sfRequest (optional takes a logger and a routing object)
  • removed sfContext dependency for sfResponse (optional takes a logger object)
  • changed sfWebRequest::getError() to return non internationalized data (form_error() still returns internationalized data)
  • changed sfWebResponse::addMeta() to return non internationalized data (include_metas() still returns internationalized data)
  • removed the shutdown() method from request and response classes
  • added a way to remove a meta or http meta from the response (just set the value to null)
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/data/generator/sfPropelAdmin/default/template/templates/_edit_messages.php

    r2786 r4895  
    55[?php foreach ($sf_request->getErrorNames() as $name): ?] 
    66  <dt>[?php echo __($labels[$name]) ?]</dt> 
    7   <dd>[?php echo $sf_request->getError($name) ?]</dd> 
     7  <dd>[?php echo __($sf_request->getError($name)) ?]</dd> 
    88[?php endforeach; ?] 
    99</dl> 
  • trunk/data/generator/sfPropelAdmin/default/template/templates/_list_messages.php

    r4622 r4895  
    1 [?php if ($sf_request->getError('delete')): ?] 
     1[?php if ($sf_request->hasError('delete')): ?] 
    22<div class="form-errors"> 
    33  <h2>[?php echo __('Could not delete the selected %name%', array('%name%' => '<?php echo sfInflector::humanize($this->getSingularName()) ?>')) ?]</h2> 
    44  <ul> 
    5     <li>[?php echo $sf_request->getError('delete') ?]</li> 
     5    <li>[?php echo __($sf_request->getError('delete')) ?]</li> 
    66  </ul> 
    77</div> 
  • trunk/lib/config/sfFactoryConfigHandler.class.php

    r4894 r4895  
    111111 
    112112          // append instance initialization 
    113           $inits[] = sprintf("  \$this->factories['request']->initialize(\$this, sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", var_export($parameters, true)); 
     113          $inits[] = sprintf("  \$this->factories['request']->initialize(\$this->factories['logger'], \$this->factories['routing'], sfConfig::get('sf_factory_request_parameters', %s), sfConfig::get('sf_factory_request_attributes', array()));", var_export($parameters, true)); 
    114114          break; 
    115115 
     
    119119 
    120120          // append instance initialization 
    121           $inits[] = sprintf("  \$this->factories['response']->initialize(\$this, sfConfig::get('sf_factory_response_parameters', %s));", var_export($parameters, true)); 
     121          $inits[] = sprintf("  \$this->factories['response']->initialize(\$this->factories['logger'], sfConfig::get('sf_factory_response_parameters', %s));", var_export($parameters, true)); 
     122          $inits[] = sprintf("  if ('HEAD' == \$this->factories['request']->getMethodName())\n  {  \n    \$this->factories['response']->setHeaderOnly(true);\n  }\n"); 
    122123          break; 
    123124 
  • trunk/lib/helper/AssetHelper.php

    r4885 r4895  
    384384 * </code> 
    385385 * 
    386  * <b>Note:</b> Modify the sfResponse object or the view.yml to change, add or remove metas. 
     386 * <b>Note:</b> Modify the view.yml or use sfWebResponse::addMeta() to change, add or remove metas. 
    387387 * 
    388388 * @return string XHTML compliant <meta> tag(s) 
    389389 * @see    include_http_metas  
     390 * @see    sfWebResponse::addMeta() 
    390391 */ 
    391392function include_metas() 
    392393{ 
    393   foreach (sfContext::getInstance()->getResponse()->getMetas() as $name => $content) 
    394   { 
    395     echo tag('meta', array('name' => $name, 'content' => $content))."\n"; 
     394  $context = sfContext::getInstance(); 
     395  $i18n = sfConfig::get('sf_i18n') ? $context->getI18N() : null; 
     396  foreach ($context->getResponse()->getMetas() as $name => $content) 
     397  { 
     398    echo tag('meta', array('name' => $name, 'content' => is_null($i18n) ? $content : $i18n->__($content)))."\n"; 
    396399  } 
    397400} 
     
    407410 * </code> 
    408411 * 
    409  * <b>Note:</b> Modify the sfResponse object or the view.yml to change, add or remove metas. 
     412 * <b>Note:</b> Modify the view.yml or use sfWebResponse::addMeta() to change, add or remove HTTP metas. 
    410413 * 
    411414 * @return string XHTML compliant <meta> tag(s) 
    412  * @see    include_metas  
     415 * @see    include_metas 
     416 * @see    sfWebResponse::addHttpMeta() 
    413417 */ 
    414418function include_http_metas() 
  • trunk/lib/helper/ValidationHelper.php

    r1553 r4895  
    3030  $options = _parse_attributes($options); 
    3131 
    32   $request = sfContext::getInstance()->getRequest(); 
     32  $context = sfContext::getInstance(); 
     33  $request = $context->getRequest(); 
    3334 
    3435  $style = $request->hasError($param_for_sf) ? '' : 'display:none;'; 
     
    5859  } 
    5960 
    60   $error = $request->getError($param_for_sf, $catalogue); 
     61  // translate error message if needed 
     62  $error = $request->getError($param_for_sf); 
     63  if (sfConfig::get('sf_i18n')) 
     64  { 
     65    $error = $context->getI18N()->__($error, null, $catalogue); 
     66  } 
    6167 
    6268  return content_tag('div', $prefix.$error.$suffix, $options)."\n"; 
  • trunk/lib/request/sfConsoleRequest.class.php

    r3597 r4895  
    2323   * Initializes this sfRequest. 
    2424   * 
    25    * @param sfContext A sfContext instance 
    26    * @param array   An associative array of initialization parameters 
    27    * @param array   An associative array of initialization attributes 
     25   * @param sfLogger  A sfLogger instance (can be null) 
     26   * @param sfRouting A sfRouting instance (can be null) 
     27   * @param array     An associative array of initialization parameters 
     28   * @param array     An associative array of initialization attributes 
    2829   * 
    29    * @return boolean true, if initialization completes successfully, otherwise false 
     30   * @return Boolean true, if initialization completes successfully, otherwise false 
    3031   * 
    3132   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
    3233   */ 
    33   public function initialize($context, $parameters = array(), $attributes = array()) 
     34  public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 
    3435  { 
    35     parent::initialize($context, $parameters, $attributes); 
     36    parent::initialize($logger, $routing, $parameters, $attributes); 
    3637 
    3738    $this->getParameterHolder()->add($_SERVER['argv']); 
    3839  } 
    39  
    40   /** 
    41    * Executes the shutdown procedure. 
    42    * 
    43    */ 
    44   public function shutdown() 
    45   { 
    46   } 
    4740} 
  • trunk/lib/request/sfRequest.class.php

    r4597 r4895  
    6161  protected 
    6262    $errors          = array(), 
    63     $context         = null, 
     63    $logger          = null, 
     64    $routing         = null, 
    6465    $method          = null, 
    6566    $parameterHolder = null, 
     
    6869 
    6970  /** 
     71   * Initializes this sfRequest. 
     72   * 
     73   * @param  sfLogger  A sfLogger instance (can be null) 
     74   * @param  sfRouting A sfRouting instance (can be null) 
     75   * @param  array     An associative array of initialization parameters 
     76   * @param  array     An associative array of initialization attributes 
     77   * 
     78   * @return Boolean   true, if initialization completes successfully, otherwise false 
     79   * 
     80   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
     81   */ 
     82  public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 
     83  { 
     84    $this->logger  = $logger; 
     85    $this->routing = $routing; 
     86 
     87    // initialize parameter and attribute holders 
     88    $this->parameterHolder = new sfParameterHolder(); 
     89    $this->attributeHolder = new sfParameterHolder(); 
     90 
     91    $this->parameterHolder->add($parameters); 
     92    $this->attributeHolder->add($attributes); 
     93  } 
     94 
     95  /** 
    7096   * Extracts parameter values from the request. 
    7197   * 
     
    76102   *               be returned for its value 
    77103   */ 
    78   public function & extractParameters($names) 
     104  public function extractParameters($names) 
    79105  { 
    80106    $array = array(); 
    81107 
    82     $parameters =& $this->parameterHolder->getAll(); 
    83     foreach ($parameters as $key => &$value) 
     108    $parameters = $this->parameterHolder->getAll(); 
     109    foreach ($parameters as $key => $value) 
    84110    { 
    85111      if (in_array($key, $names)) 
    86112      { 
    87         $array[$key] =& $value; 
     113        $array[$key] = $value; 
    88114      } 
    89115    } 
     
    99125   * @return string An error message, if the error exists, otherwise null 
    100126   */ 
    101   public function getError($name, $catalogue = 'messages') 
    102   { 
    103     $retval = null; 
    104  
    105     if (isset($this->errors[$name])) 
    106     { 
    107       $retval = $this->errors[$name]; 
    108  
    109       // translate error message if needed 
    110       if (sfConfig::get('sf_i18n')) 
    111       { 
    112         $retval = $this->context->getI18N()->__($retval, null, $catalogue); 
    113       } 
    114     } 
    115  
    116     return $retval; 
     127  public function getError($name) 
     128  { 
     129    return isset($this->errors[$name]) ? $this->errors[$name] : null; 
    117130  } 
    118131 
     
    168181  public function hasErrors() 
    169182  { 
    170     return (count($this->errors) > 0); 
    171   } 
    172  
    173   /** 
    174    * Initializes this sfRequest. 
    175    * 
    176    * @param sfContext A sfContext instance 
    177    * @param array   An associative array of initialization parameters 
    178    * @param array   An associative array of initialization attributes 
    179    * 
    180    * @return boolean true, if initialization completes successfully, otherwise false 
    181    * 
    182    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
    183    */ 
    184   public function initialize($context, $parameters = array(), $attributes = array()) 
    185   { 
    186     $this->context = $context; 
    187  
    188     // initialize parameter and attribute holders 
    189     $this->parameterHolder = new sfParameterHolder(); 
    190     $this->attributeHolder = new sfParameterHolder(); 
    191  
    192     $this->parameterHolder->add($parameters); 
    193     $this->attributeHolder->add($attributes); 
    194   } 
    195  
    196   /** 
    197    * Retrieves the current application context. 
    198    * 
    199    * @return sfContext Current application context 
    200    */ 
    201   public function getContext() 
    202   { 
    203     return $this->context; 
     183    return count($this->errors) > 0; 
    204184  } 
    205185 
     
    232212   * @return string An error message, if the error was removed, otherwise null 
    233213   */ 
    234   public function & removeError($name) 
     214  public function removeError($name) 
    235215  { 
    236216    $retval = null; 
     
    238218    if (isset($this->errors[$name])) 
    239219    { 
    240       $retval =& $this->errors[$name]; 
     220      $retval = $this->errors[$name]; 
    241221 
    242222      unset($this->errors[$name]); 
     
    255235  public function setError($name, $message) 
    256236  { 
    257     if (sfConfig::get('sf_logging_enabled')) 
    258     { 
    259       $this->context->getLogger()->info('{sfRequest} error in form for parameter "'.$name.'" (with message "'.$message.'")'); 
     237    if (!is_null($this->logger)) 
     238    { 
     239      $this->logger->info('{sfRequest} error in form for parameter "'.$name.'" (with message "'.$message.'")'); 
    260240    } 
    261241 
     
    406386 
    407387  /** 
    408    * Executes the shutdown procedure. 
    409    * 
    410    */ 
    411   abstract function shutdown(); 
    412  
    413   /** 
    414388   * Overloads a given method. 
    415389   * 
  • trunk/lib/request/sfWebRequest.class.php

    r4892 r4895  
    3535 
    3636  /** 
     37   * Initializes this sfRequest. 
     38   * 
     39   * @param  sfLogger  A sfLogger instance (can be null) 
     40   * @param  sfRouting A sfRouting instance (can be null) 
     41   * @param  array     An associative array of initialization parameters 
     42   * @param  array     An associative array of initialization attributes 
     43   * 
     44   * @return Boolean   true, if initialization completes successfully, otherwise false 
     45   * 
     46   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
     47   */ 
     48  public function initialize(sfLogger $logger = null, sfRouting $routing = null, $parameters = array(), $attributes = array()) 
     49  { 
     50    parent::initialize($logger, $routing, $parameters, $attributes); 
     51 
     52    if (isset($_SERVER['REQUEST_METHOD'])) 
     53    { 
     54      switch ($_SERVER['REQUEST_METHOD']) 
     55      { 
     56        case 'GET': 
     57          $this->setMethod(self::GET); 
     58          break; 
     59 
     60        case 'POST': 
     61          $this->setMethod(self::POST); 
     62          break; 
     63 
     64        case 'PUT': 
     65          $this->setMethod(self::PUT); 
     66          break; 
     67 
     68        case 'DELETE': 
     69          $this->setMethod(self::DELETE); 
     70          break; 
     71 
     72        case 'HEAD': 
     73          $this->setMethod(self::HEAD); 
     74          break; 
     75 
     76        default: 
     77          $this->setMethod(self::GET); 
     78      } 
     79    } 
     80    else 
     81    { 
     82      // set the default method 
     83      $this->setMethod(self::GET); 
     84    } 
     85 
     86    // load parameters from GET/PATH_INFO/POST 
     87    $this->loadParameters(); 
     88  } 
     89 
     90  /** 
    3791   * Retrieves an array of file information. 
    3892   * 
     
    263317 
    264318    return isset($mimeTypes[$fileType]) ? '.'.$mimeTypes[$fileType] : '.bin'; 
    265   } 
    266  
    267   /** 
    268    * Initializes this sfRequest. 
    269    * 
    270    * @param sfContext A sfContext instance 
    271    * @param array   An associative array of initialization parameters 
    272    * @param array   An associative array of initialization attributes 
    273    * 
    274    * @return boolean true, if initialization completes successfully, otherwise false 
    275    * 
    276    * @throws <b>sfInitializationException</b> If an error occurs while initializing this Request 
    277    */ 
    278   public function initialize($context, $parameters = array(), $attributes = array()) 
    279   { 
    280     parent::initialize($context, $parameters, $attributes); 
    281  
    282     if (isset($_SERVER['REQUEST_METHOD'])) 
    283     { 
    284       switch ($_SERVER['REQUEST_METHOD']) 
    285       { 
    286         case 'GET': 
    287           $this->setMethod(self::GET); 
    288           break; 
    289  
    290         case 'POST': 
    291           $this->setMethod(self::POST); 
    292           break; 
    293  
    294         case 'PUT': 
    295           $this->setMethod(self::PUT); 
    296           break; 
    297  
    298         case 'DELETE': 
    299           $this->setMethod(self::DELETE); 
    300           break; 
    301  
    302         case 'HEAD': 
    303           $this->setMethod(self::HEAD); 
    304           break; 
    305  
    306         default: 
    307           $this->setMethod(self::GET); 
    308       } 
    309     } 
    310     else 
    311     { 
    312       // set the default method 
    313       $this->setMethod(self::GET); 
    314     } 
    315  
    316     // load parameters from GET/PATH_INFO/POST 
    317     $this->loadParameters(); 
    318319  } 
    319320 
     
    724725 
    725726  /** 
    726    * Executes the shutdown procedure. 
    727    * 
    728    */ 
    729   public function shutdown() 
    730   { 
    731   } 
    732  
    733   /** 
    734727   * Splits an HTTP header for the current web request. 
    735728   * 
     
    789782  protected function parseRoutingParameters() 
    790783  { 
    791     $parameters = $this->context->getRouting()->parse($this->getPathInfo()); 
     784    if (is_null($this->routing)) 
     785    { 
     786      return; 
     787    } 
     788 
     789    $parameters = $this->routing->parse($this->getPathInfo()); 
    792790    if (!is_null($parameters)) 
    793791    { 
    794792      if (!isset($parameters['module'])) 
    795793      { 
    796         $parameters['module'] = sfConfig::get('sf_default_module'); 
     794        $parameters['module'] = sfConfig::get('sf_default_module', 'default'); 
    797795      } 
    798796 
    799797      if (!isset($parameters['action'])) 
    800798      { 
    801         $parameters['action'] = sfConfig::get('sf_default_action'); 
     799        $parameters['action'] = sfConfig::get('sf_default_action', 'index'); 
    802800      } 
    803801    } 
    804802    else 
    805803    { 
    806       $parameters['module'] = sfConfig::get('sf_error_404_module'); 
    807       $parameters['action'] = sfConfig::get('sf_error_404_action'); 
     804      $parameters['module'] = sfConfig::get('sf_error_404_module', 'default'); 
     805      $parameters['action'] = sfConfig::get('sf_error_404_action', 'error404'); 
    808806    } 
    809807 
     
    839837    } 
    840838 
    841     if (sfConfig::get('sf_logging_enabled')) 
    842     { 
    843       $this->context->getLogger()->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); 
     839    if (!is_null($this->logger)) 
     840    { 
     841      $this->logger->info(sprintf('{sfRequest} request parameters %s', str_replace("\n", '', var_export($this->getParameterHolder()->getAll(), true)))); 
    844842    } 
    845843  } 
  • trunk/lib/response/sfConsoleResponse.class.php

    r3250 r4895  
    1919class sfConsoleResponse extends sfResponse 
    2020{ 
    21   /** 
    22    * Executes the shutdown procedure. 
    23    * 
    24    */ 
    25   public function shutdown() 
    26   { 
    27   } 
    2821} 
  • trunk/lib/response/sfResponse.class.php

    r4597 r4895  
    2222  protected 
    2323    $parameterHolder = null, 
    24     $context         = null, 
     24    $logger          = null, 
    2525    $content         = ''; 
    2626 
     
    2828   * Initializes this sfResponse. 
    2929   * 
    30    * @param sfContext A sfContext instance 
     30   * @param sfLogger  A sfLogger instance (can be null) 
    3131   * 
    32    * @return boolean true, if initialization completes successfully, otherwise false 
     32   * @return Boolean  true, if initialization completes successfully, otherwise false 
    3333   * 
    3434   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Response 
    3535   */ 
    36   public function initialize($context, $parameters = array()) 
     36  public function initialize(sfLogger $logger = null, $parameters = array()) 
    3737  { 
    38     $this->context = $context
     38    $this->logger = $logger
    3939 
    4040    $this->parameterHolder = new sfParameterHolder(); 
    4141    $this->parameterHolder->add($parameters); 
    42   } 
    43  
    44   /** 
    45    * Retrieves the current application context. 
    46    * 
    47    * @return sfContext The application context 
    48    */ 
    49   public function getContext() 
    50   { 
    51     return $this->context; 
    5242  } 
    5343 
     
    5949   * @return sfResponse A sfResponse implementation instance 
    6050   * 
    61    * @throws <b>sfFactoryException</b> If a request implementation instance cannot be created 
     51   * @throws <b>sfFactoryException</b> If a response implementation instance cannot be created 
    6252   */ 
    6353  public static function newInstance($class) 
     
    9888  public function sendContent() 
    9989  { 
    100     if (sfConfig::get('sf_logging_enabled')) 
     90    if (!is_null($this->logger)) 
    10191    { 
    102       $this->context->getLogger()->info('{sfResponse} send content ('.strlen($this->getContent()).' o)'); 
     92      $this->logger->info('{sfResponse} send content ('.strlen($this->getContent()).' o)'); 
    10393    } 
    10494 
     
    156146 
    157147  /** 
    158    * Executes the shutdown procedure. 
    159    * 
    160    */ 
    161   abstract function shutdown(); 
    162  
    163   /** 
    164148   * Overloads a given method. 
    165149   * 
  • trunk/lib/response/sfWebResponse.class.php

    r4604 r4895  
    3131   * Initializes this sfWebResponse. 
    3232   * 
    33    * @param sfContext A sfContext instance 
    34    * 
    35    * @return boolean true, if initialization completes successfully, otherwise false 
     33   * @param sfLogger  A sfLogger instance (can be null) 
     34   * 
     35   * @return Boolean  true, if initialization completes successfully, otherwise false 
    3636   * 
    3737   * @throws <b>sfInitializationException</b> If an error occurs while initializing this Response 
    3838   */ 
    39   public function initialize($context, $parameters = array()) 
    40   { 
    41     parent::initialize($context, $parameters); 
    42  
    43     if ('HEAD' == $context->getRequest()->getMethodName()) 
    44     { 
    45       $this->setHeaderOnly(true); 
    46     } 
     39  public function initialize(sfLogger $logger = null, $parameters = array()) 
     40  { 
     41    parent::initialize($logger, $parameters); 
    4742 
    4843    $this->statusTexts = array( 
     
    179174   * Sets a HTTP header. 
    180175   * 
    181    * @param string HTTP header name 
    182    * @param string Value 
     176   * @param string HTTP header name 
     177   * @param string Value (if null, remove the HTTP header) 
    183178   * @param boolean Replace for the value 
    184179   * 
     
    187182  { 
    188183    $name = $this->normalizeHeaderName($name); 
     184 
     185    if (is_null($value)) 
     186    { 
     187      $this->getParameterHolder()->remove($name, 'symfony/response/http/headers'); 
     188 
     189      return; 
     190    } 
    189191 
    190192    if ('Content-Type' == $name) 
     
    264266    header($status); 
    265267 
    266     if (sfConfig::get('sf_logging_enabled')) 
    267     { 
    268       $this->context->getLogger()->info('{sfResponse} send status "'.$status.'"'); 
     268    if (!is_null($this->logger)) 
     269    { 
     270      $this->logger->info('{sfResponse} send status "'.$status.'"'); 
    269271    } 
    270272 
     
    274276      header($name.': '.$value); 
    275277 
    276       if (sfConfig::get('sf_logging_enabled') && $value != '') 
    277       { 
    278         $this->context->getLogger()->info('{sfResponse} send header "'.$name.'": "'.$value.'"'); 
     278      if (!is_null($this->logger) && $value != '') 
     279      { 
     280        $this->logger->info('{sfResponse} send header "'.$name.'": "'.$value.'"'); 
    279281      } 
    280282    } 
     
    292294      } 
    293295 
    294       if (sfConfig::get('sf_logging_enabled')) 
    295       { 
    296         $this->context->getLogger()->info('{sfResponse} send cookie "'.$cookie['name'].'": "'.$cookie['value'].'"'); 
     296      if (!is_null($this->logger)) 
     297      { 
     298        $this->logger->info('{sfResponse} send cookie "'.$cookie['name'].'": "'.$cookie['value'].'"'); 
    297299      } 
    298300    } 
     
    415417 
    416418  /** 
    417    * Adds meta headers to the current web response
    418    * 
    419    * @param string Key to replace 
    420    * @param string Value for the replacement 
     419   * Adds a HTTP meta header
     420   * 
     421   * @param string Key to replace 
     422   * @param string HTTP meta header value (if null, remove the HTTP meta) 
    421423   * @param boolean Replace or not 
    422424   */ 
     
    428430    $this->setHttpHeader($key, $value, $replace); 
    429431 
     432    if (is_null($value)) 
     433    { 
     434      $this->getParameterHolder()->remove($key, 'helper/asset/auto/httpmeta'); 
     435 
     436      return; 
     437    } 
     438 
    430439    if ('Content-Type' == $key) 
    431440    { 
     
    443452 
    444453  /** 
    445    * Retrieves all meta headers for the current web response
     454   * Retrieves all meta headers
    446455   * 
    447456   * @return array List of meta headers 
     
    453462 
    454463  /** 
    455    * Adds a meta header to the current web response
    456    * 
    457    * @param string Name of the header 
    458    * @param string Meta header to be set 
     464   * Adds a meta header
     465   * 
     466   * @param string Name of the header 
     467   * @param string Meta header value (if null, remove the meta) 
    459468   * @param boolean true if it's replaceable 
    460469   * @param boolean true for escaping the header 
     
    464473    $key = strtolower($key); 
    465474 
    466     if (sfConfig::get('sf_i18n')) 
    467     { 
    468       $value = $this->context->getI18N()->__($value); 
    469     } 
    470  
     475    if (is_null($value)) 
     476    { 
     477      $this->getParameterHolder()->remove($key, 'helper/asset/auto/meta'); 
     478 
     479      return; 
     480    } 
     481 
     482    // FIXME: If you use the i18n layer and escape the data here, it won't work 
     483    // see include_metas() in AssetHelper 
    471484    if ($escape) 
    472485    { 
     
    600613  public function serialize() 
    601614  { 
    602     return serialize(array($this->content, $this->statusCode, $this->statusText, $this->parameterHolder)); 
     615    return serialize(array($this->content, $this->statusCode, $this->statusText, $this->parameterHolder, $this->cookies, $this->headerOnly)); 
    603616  } 
    604617 
     
    610623    $data = unserialize($serialized); 
    611624 
    612     $this->initialize(sfContext::getInstance()); 
    613  
    614     $this->content = $data[0]; 
    615     $this->statusCode = $data[1]; 
    616     $this->statusText = $data[2]; 
     625    $this->initialize(); 
     626 
     627    $this->content         = $data[0]; 
     628    $this->statusCode      = $data[1]; 
     629    $this->statusText      = $data[2]; 
    617630    $this->parameterHolder = $data[3]; 
    618   } 
    619  
    620   /** 
    621    * Executes the shutdown procedure. 
    622    */ 
    623   public function shutdown() 
    624   { 
     631    $this->cookies         = $data[4]; 
     632    $this->headerOnly      = $data[5]; 
    625633  } 
    626634} 
  • trunk/lib/util/sfContext.class.php

    r4887 r4895  
    355355    $this->getUser()->shutdown(); 
    356356    $this->getStorage()->shutdown(); 
    357     $this->getRequest()->shutdown(); 
    358     $this->getResponse()->shutdown(); 
    359357    $this->getRouting()->shutdown(); 
    360358 
  • trunk/test/unit/helper/AssetHelperTest.php

    r4440 r4895  
    1414sfLoader::loadHelpers(array('Helper', 'Tag', 'Url', 'Asset')); 
    1515 
    16 $t = new lime_test(37, new lime_output_color()); 
     16$t = new lime_test(45, new lime_output_color()); 
    1717 
    1818class myRequest 
     
    3636} 
    3737 
    38 $context = sfContext::getInstance(array('request' => 'myRequest')); 
     38$context = sfContext::getInstance(array('request' => 'myRequest', 'response' => 'sfWebResponse')); 
    3939 
    4040// _compute_public_path() 
     
    118118$t->is(image_path('img.jpg', true), 'http://localhost/images/img.jpg', 'image_path() accepts a second parameter to output an absolute resource path'); 
    119119 
    120 /* 
     120// use_javascript() get_javascripts() 
     121$t->diag('use_javascript() get_javascripts()'); 
     122use_javascript('xmlhr'); 
     123$t->is(get_javascripts(), 
     124  '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n",  
     125  'get_javascripts() returns a javascript previously added by use_javascript()'); 
     126use_javascript('xmlhr', '', array('raw_name' => true)); 
     127$t->is(get_javascripts(), 
     128  '<script type="text/javascript" src="xmlhr"></script>'."\n",  
     129  'use_javascript() accepts an array of options as a third parameter'); 
     130use_javascript('xmlhr', '', array('absolute' => true)); 
     131$t->is(get_javascripts(), 
     132  '<script type="text/javascript" src="http://localhost/js/xmlhr.js"></script>'."\n",  
     133  'use_javascript() accepts an array of options as a third parameter'); 
     134use_javascript('xmlhr'); 
     135use_javascript('xmlhr2'); 
     136$t->is(get_javascripts(), 
     137  '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n".'<script type="text/javascript" src="/js/xmlhr2.js"></script>'."\n",  
     138  'get_javascripts() returns all the javascripts previously added by use_javascript()'); 
    121139 
    122 // auto_discovery_link_tag() 
    123 $t->is(auto_discovery_link_tag(), 
    124   '<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />'); 
    125  
    126 $t->is(auto_discovery_link_tag('atom'), 
    127   '<link href="http://www.example.com" rel="alternate" title="ATOM" type="application/atom+xml" />'); 
    128  
    129 $t->is(auto_discovery_link_tag('rss', array('action' => 'feed')), 
    130   '<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />'); 
    131  
    132 $context->request = new sfWebRequest(); 
    133 sfConfig::set('test_sfWebRequest_relative_url_root', '/mypath'); 
    134  
    135 // auto_discovery() 
    136 $t->is(auto_discovery_link_tag('rss', array('action' => 'feed')), 
    137   '<link href="http://www.example.com/mypath" rel="alternate" title="RSS" type="application/rss+xml" />'); 
    138  
    139 $t->is(auto_discovery_link_tag('atom'), 
    140   '<link href="http://www.example.com/mypath" rel="alternate" title="ATOM" type="application/atom+xml" />'); 
    141  
    142 $t->is(auto_discovery_link_tag(), 
    143   '<link href="http://www.example.com/mypath" rel="alternate" title="RSS" type="application/rss+xml" />'); 
    144  
    145 */ 
     140// use_stylesheet() get_stylesheets() 
     141$t->diag('use_stylesheet() get_stylesheets()'); 
     142use_stylesheet('style'); 
     143$t->is(get_stylesheets(), 
     144  '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n",  
     145  'get_stylesheets() returns a stylesheet previously added by use_stylesheet()'); 
     146use_stylesheet('style', '', array('raw_name' => true)); 
     147$t->is(get_stylesheets(), 
     148  '<link rel="stylesheet" type="text/css" media="screen" href="style" />'."\n",  
     149  'use_stylesheet() accepts an array of options as a third parameter'); 
     150use_stylesheet('style', '', array('absolute' => true)); 
     151$t->is(get_stylesheets(), 
     152  '<link rel="stylesheet" type="text/css" media="screen" href="http://localhost/css/style.css" />'."\n",  
     153  'use_stylesheet() accepts an array of options as a third parameter'); 
     154use_stylesheet('style'); 
     155use_stylesheet('style2'); 
     156$t->is(get_stylesheets(), 
     157  '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n".'<link rel="stylesheet" type="text/css" media="screen" href="/css/style2.css" />'."\n", 
     158  'get_stylesheets() returns all the stylesheets previously added by use_stylesheet()'); 
  • trunk/test/unit/request/sfRequestTest.php

    r4440 r4895  
    1010 
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    1312 
    1413class myRequest extends sfRequest 
    1514{ 
    16   function shutdown() {} 
     15  public function getRouting() 
     16  { 
     17    return $this->routing; 
     18  } 
    1719} 
    1820 
     
    2123} 
    2224 
    23 $t = new lime_test(54, new lime_output_color()); 
     25$t = new lime_test(53, new lime_output_color()); 
    2426 
    25 $context = sfContext::getInstance(array('routing' => 'sfNoRouting')); 
    26 $context->getRouting()->clearRoutes(); 
     27$routing = new sfNoRouting(); 
     28$routing->initialize(); 
    2729 
    2830// ::newInstance() 
     
    4446$t->diag('->initialize()'); 
    4547$request = sfRequest::newInstance('myRequest'); 
    46 $t->is($request->getContext(), null, '->initialize() takes a sfContext object as its first argument'); 
    47 $request->initialize($context, array('foo' => 'bar')); 
     48$request->initialize(null, $routing); 
     49$t->is($routing, $request->getRouting(), '->initialize() takes a sfRouting object as its second argument'); 
     50$request->initialize(null, $routing, array('foo' => 'bar')); 
    4851$t->is($request->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 
    49  
    50 // ->getContext() 
    51 $t->diag('->getContext()'); 
    52 $request->initialize($context); 
    53 $t->is($request->getContext(), $context, '->getContext() returns the current context'); 
    5452 
    5553// ->getMethod() ->setMethod() 
     
    7068// ->extractParameters() 
    7169$t->diag('->extractParameters()'); 
    72 $request->initialize($context, array('foo' => 'foo', 'bar' => 'bar')); 
     70$request->initialize(null, $routing, array('foo' => 'foo', 'bar' => 'bar')); 
    7371$t->is($request->extractParameters(array()), array(), '->extractParameters() returns parameters'); 
    7472$t->is($request->extractParameters(array('foo')), array('foo' => 'foo'), '->extractParameters() returns parameters for keys in its first parameter'); 
     
    7674 
    7775$request = sfRequest::newInstance('myRequest'); 
    78 $request->initialize($context); 
     76$request->initialize(null, $routing); 
    7977 
    8078// ->setError() ->hasError() ->hasErrors() ->getError() ->removeError() ->getErrorNames 
  • trunk/test/unit/response/sfResponseTest.php

    r4534 r4895  
    1010 
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    1312 
    1413class myResponse extends sfResponse 
    1514{ 
    16   function shutdown() {} 
    1715  function serialize() {} 
    1816  function unserialize($serialized) {} 
     
    2321} 
    2422 
    25 $t = new lime_test(25, new lime_output_color()); 
    26  
    27 $context = sfContext::getInstance(); 
     23$t = new lime_test(23, new lime_output_color()); 
    2824 
    2925// ::newInstance() 
     
    4541$t->diag('->initialize()'); 
    4642$response = sfResponse::newInstance('myResponse'); 
    47 $t->is($response->getContext(), null, '->initialize() takes a sfContext object as its first argument'); 
    48 $response->initialize($context, array('foo' => 'bar')); 
     43$response->initialize(null, array('foo' => 'bar')); 
    4944$t->is($response->getParameter('foo'), 'bar', '->initialize() takes an array of parameters as its second argument'); 
    50  
    51 // ->getContext() 
    52 $t->diag('->getContext()'); 
    53 $response->initialize($context); 
    54 $t->is($response->getContext(), $context, '->getContext() returns the current context'); 
    5545 
    5646// ->getContent() ->setContent() 
     
    7363// parameter holder proxy 
    7464require_once($_test_dir.'/unit/sfParameterHolderTest.class.php'); 
     65$response = sfResponse::newInstance('myResponse'); 
     66$response->initialize(); 
    7567$pht = new sfParameterHolderProxyTest($t); 
    7668$pht->launchTests($response, 'parameter'); 
  • trunk/test/unit/response/sfWebResponseTest.php

    r4892 r4895  
    1010 
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 
    13  
    14 $t = new lime_test(72, new lime_output_color()); 
     12 
     13$t = new lime_test(64, new lime_output_color()); 
    1514 
    1615class myWebResponse extends sfWebResponse 
     
    2726} 
    2827 
    29 $context = sfContext::getInstance(array('routing' => 'sfNoRouting', 'request' => 'sfWebRequest', 'response' => 'myWebResponse')); 
    30 $response = $context->response
     28$response = new myWebResponse(); 
     29$response->initialize()
    3130 
    3231// ->getStatusCode() ->setStatusCode() 
     
    162161$t->diag('->mergeProperties()'); 
    163162$response1 = sfResponse::newInstance('myWebResponse'); 
    164 $response1->initialize($context); 
     163$response1->initialize(); 
    165164$response2 = sfResponse::newInstance('myWebResponse'); 
    166 $response2->initialize($context); 
     165$response2->initialize(); 
    167166 
    168167$response1->setHttpHeader('symfony', 'foo'); 
     
    178177$t->diag('->addStylesheet()'); 
    179178$response = sfResponse::newInstance('myWebResponse'); 
    180 $response->initialize($context); 
     179$response->initialize(); 
    181180$response->addStylesheet('test'); 
    182181$t->ok($response->getParameterHolder()->has('test', 'helper/asset/auto/stylesheet'), '->addStylesheet() adds a new stylesheet for the response'); 
     
    199198$t->diag('->addJavascript()'); 
    200199$response = sfResponse::newInstance('myWebResponse'); 
    201 $response->initialize($context); 
     200$response->initialize(); 
    202201$response->addJavascript('test'); 
    203202$t->ok($response->getParameterHolder()->has('test', 'helper/asset/auto/javascript'), '->addJavascript() adds a new javascript for the response'); 
     
    223222$t->diag('->setHeaderOnly() ->isHeaderOnly()'); 
    224223$response = sfResponse::newInstance('myWebResponse'); 
    225 $response->initialize($context); 
     224$response->initialize(); 
    226225$t->is($response->isHeaderOnly(), false, '->isHeaderOnly() returns false if the content must be send to the client'); 
    227226$response->setHeaderOnly(true); 
     
    245244$t->diag('->serialize() ->unserialize()'); 
    246245$t->ok($response == unserialize(serialize($response)), 'sfWebResponse implements the Serializable interface'); 
    247  
    248 sfLoader::loadHelpers(array('Helper', 'Tag', 'Url', 'Asset')); 
    249 $_SERVER['SCRIPT_NAME'] = ''; 
    250  
    251 // use and get javascript() 
    252 $t->diag('use and get javascript from the template'); 
    253 use_javascript('xmlhr'); 
    254 $t->is(get_javascripts(), 
    255   '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n",  
    256   'get_javascripts() returns a javascript previously added by use_javascript()'); 
    257 use_javascript('xmlhr', '', array('raw_name' => true)); 
    258 $t->is(get_javascripts(), 
    259   '<script type="text/javascript" src="xmlhr"></script>'."\n",  
    260   'use_javascript() accepts an array of options as a third parameter'); 
    261 use_javascript('xmlhr', '', array('absolute' => true)); 
    262 $t->is(get_javascripts(), 
    263   '<script type="text/javascript" src="http:///js/xmlhr.js"></script>'."\n",  
    264   'use_javascript() accepts an array of options as a third parameter'); 
    265 use_javascript('xmlhr'); 
    266 use_javascript('xmlhr2'); 
    267 $t->is(get_javascripts(), 
    268   '<script type="text/javascript" src="/js/xmlhr.js"></script>'."\n".'<script type="text/javascript" src="/js/xmlhr2.js"></script>'."\n",  
    269   'get_javascripts() returns all the javascripts previously added by use_javascript()'); 
    270  
    271 // use and get stylesheet() 
    272 $t->diag('use and get stylesheet from the template'); 
    273 use_stylesheet('style'); 
    274 $t->is(get_stylesheets(), 
    275   '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n",  
    276   'get_stylesheets() returns a stylesheet previously added by use_stylesheet()'); 
    277 use_stylesheet('style', '', array('raw_name' => true)); 
    278 $t->is(get_stylesheets(), 
    279   '<link rel="stylesheet" type="text/css" media="screen" href="style" />'."\n",  
    280   'use_stylesheet() accepts an array of options as a third parameter'); 
    281 use_stylesheet('style', '', array('absolute' => true)); 
    282 $t->is(get_stylesheets(), 
    283   '<link rel="stylesheet" type="text/css" media="screen" href="http:///css/style.css" />'."\n",  
    284   'use_stylesheet() accepts an array of options as a third parameter'); 
    285 use_stylesheet('style'); 
    286 use_stylesheet('style2'); 
    287 $t->is(get_stylesheets(), 
    288   '<link rel="stylesheet" type="text/css" media="screen" href="/css/style.css" />'."\n".'<link rel="stylesheet" type="text/css" media="screen" href="/css/style2.css" />'."\n", 
    289   'get_stylesheets() returns all the stylesheets previously added by use_stylesheet()'); 
  • trunk/test/unit/sfContextMock.class.php

    r4892 r4895  
    8585    if (method_exists($object, 'initialize')) 
    8686    { 
    87       in_array($type, array('routing')) ? $object->initialize(null, $parameters) : $object->initialize($this, $parameters); 
     87      switch ($type) 
     88      { 
     89        case 'routing': 
     90        case 'response': 
     91          $object->initialize(null, $parameters); 
     92          break; 
     93        case request: 
     94          $object->initialize(null, $this->routing, $parameters); 
     95          break; 
     96        default: 
     97          $object->initialize($this, $parameters); 
     98      } 
    8899    } 
    89100    $this->$type = $object; 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.