Development

Changeset 11102

You must first sign up to be able to contribute.

Changeset 11102

Show
Ignore:
Timestamp:
08/25/08 11:33:39 (10 months ago)
Author:
fabien
Message:

[1.2] changed the default position to sfWebResponse::ALL for the getStylesheets() and getJavascripts() methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/UPGRADE_TO_1_2

    r11098 r11102  
    6464    $response->addStylesheet('bar.css', 'first'); 
    6565 
    66     var_export($response->getStylesheets(sfWebResponse::ALL)); 
     66    var_export($response->getStylesheets()); 
    6767 
    6868    // outputs 
     
    7171      'foo.css' => array(), 
    7272    ) 
     73 
     74The `sfWebResponse::ALL` is also now the default value for the position argument. 
     75In symfony 1.1, as the default value is the empty string, the methods only return 
     76the files registered for the default position by default, which is not very intuitive. 
    7377 
    7478In symfony 1.1, you was able to get all the files by passing the `'ALL'` string 
  • branches/1.2/lib/helper/AssetHelper.php

    r11089 r11102  
    462462 
    463463  $html = ''; 
    464   foreach ($response->getJavascripts(sfWebResponse::ALL) as $file => $options) 
     464  foreach ($response->getJavascripts() as $file => $options) 
    465465  { 
    466466    $html .= javascript_include_tag($file, $options); 
     
    495495 
    496496  $html = ''; 
    497   foreach ($response->getStylesheets(sfWebResponse::ALL) as $file => $options) 
     497  foreach ($response->getStylesheets() as $file => $options) 
    498498  { 
    499499    $html .= stylesheet_tag($file, $options); 
  • branches/1.2/lib/response/sfWebResponse.class.php

    r11098 r11102  
    585585   * Retrieves stylesheets for the current web response. 
    586586   * 
    587    * If you pass sfWebResponse::ALL as the position
    588    * the methods returns all stylesheets ordered by position. 
     587   * By default, the position is sfWebResponse::ALL
     588   * and the method returns all stylesheets ordered by position. 
    589589   * 
    590590   * @param  string  $position The position 
    591591   * 
    592    * @return array   An associative array of javascript files as keys and options as values 
    593    */ 
    594   public function getStylesheets($position = ''
    595   { 
    596     if (sfWebResponse::ALL === $position) 
     592   * @return array   An associative array of stylesheet files as keys and options as values 
     593   */ 
     594  public function getStylesheets($position = self::ALL
     595  { 
     596    if (self::ALL === $position) 
    597597    { 
    598598      $stylesheets = array(); 
     
    607607      return $stylesheets; 
    608608    } 
    609     else if (sfWebResponse::RAW === $position) 
     609    else if (self::RAW === $position) 
    610610    { 
    611611      return $this->stylesheets; 
     
    647647   * Retrieves javascript files from the current web response. 
    648648   * 
    649    * If you pass sfWebResponse::ALL as the position
    650    * the methods returns all javascripts ordered by position. 
     649   * By default, the position is sfWebResponse::ALL
     650   * and the method returns all javascripts ordered by position. 
    651651   * 
    652652   * @param  string $position  The position 
     
    654654   * @return array An associative array of javascript files as keys and options as values 
    655655   */ 
    656   public function getJavascripts($position = ''
    657   { 
    658     if (sfWebResponse::ALL === $position) 
     656  public function getJavascripts($position = self::ALL
     657  { 
     658    if (self::ALL === $position) 
    659659    { 
    660660      $javascripts = array(); 
     
    669669      return $javascripts; 
    670670    } 
    671     else if (sfWebResponse::RAW === $position) 
     671    else if (self::RAW === $position) 
    672672    { 
    673673      return $this->javascripts; 
     
    766766    $this->metas       = $response->getMetas(); 
    767767    $this->httpMetas   = $response->getHttpMetas(); 
    768     $this->stylesheets = $response->getStylesheets(sfWebResponse::RAW); 
    769     $this->javascripts = $response->getJavascripts(sfWebResponse::RAW); 
     768    $this->stylesheets = $response->getStylesheets(self::RAW); 
     769    $this->javascripts = $response->getJavascripts(self::RAW); 
    770770    $this->slots       = $response->getSlots(); 
    771771  } 
  • branches/1.2/test/unit/response/sfWebResponseTest.php

    r11098 r11102  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(79, new lime_output_color()); 
     13$t = new lime_test(81, new lime_output_color()); 
    1414 
    1515class myWebResponse extends sfWebResponse 
     
    218218// ->getStylesheets() 
    219219$t->diag('->getStylesheets()'); 
    220 $t->is($response->getStylesheets(), array('test' => array(), 'foo' => array(), 'bar' => array('media' => 'print')), '->getStylesheets() returns all current registered stylesheets'); 
     220$t->is(array_keys($response->getStylesheets()), array('first', 'test', 'foo', 'bar', 'last'), '->getStylesheets() returns all current registered stylesheets ordered by position'); 
     221$t->is($response->getStylesheets(''), array('test' => array(), 'foo' => array(), 'bar' => array('media' => 'print')), '->getStylesheets() takes a position as its first argument'); 
    221222$t->is($response->getStylesheets('first'), array('first' => array()), '->getStylesheets() takes a position as its first argument'); 
    222223$t->is($response->getStylesheets('last'), array('last' => array()), '->getStylesheets() takes a position as its first argument'); 
     
    224225$t->diag('->removeStylesheet()'); 
    225226$response->removeStylesheet('foo'); 
    226 $t->is(array_keys($response->getStylesheets(sfWebResponse::ALL)), array('first', 'test', 'bar', 'last'), '->getStylesheets() removes a stylesheet from the response'); 
     227$t->is(array_keys($response->getStylesheets()), array('first', 'test', 'bar', 'last'), '->getStylesheets() removes a stylesheet from the response'); 
    227228 
    228229$response->removeStylesheet('first'); 
    229 $t->is(array_keys($response->getStylesheets(sfWebResponse::ALL)), array('test', 'bar', 'last'), '->getStylesheets() removes a stylesheet from the response'); 
     230$t->is(array_keys($response->getStylesheets()), array('test', 'bar', 'last'), '->getStylesheets() removes a stylesheet from the response'); 
    230231 
    231232// ->addJavascript() 
     
    253254// ->getJavascripts() 
    254255$t->diag('->getJavascripts()'); 
    255 $t->is($response->getJavascripts(), array('test' => array(), 'foo' => array('raw_name' => true)), '->getJavascripts() returns all current registered javascripts'); 
     256$t->is(array_keys($response->getJavascripts()), array('first_js', 'test', 'foo', 'last_js'), '->getJavascripts() returns all current registered javascripts ordered by position'); 
     257$t->is($response->getJavascripts(''), array('test' => array(), 'foo' => array('raw_name' => true)), '->getJavascripts() takes a position as its first argument'); 
    256258$t->is($response->getJavascripts('first'), array('first_js' => array()), '->getJavascripts() takes a position as its first argument'); 
    257259$t->is($response->getJavascripts('last'), array('last_js' => array()), '->getJavascripts() takes a position as its first argument'); 
     
    259261$t->diag('->removeJavascript()'); 
    260262$response->removeJavascript('test'); 
    261 $t->is(array_keys($response->getJavascripts(sfWebResponse::ALL)), array('first_js', 'foo', 'last_js'), '->removeJavascripts() removes a javascript file'); 
     263$t->is(array_keys($response->getJavascripts()), array('first_js', 'foo', 'last_js'), '->removeJavascripts() removes a javascript file'); 
    262264 
    263265$response->removeJavascript('first_js'); 
    264 $t->is(array_keys($response->getJavascripts(sfWebResponse::ALL)), array('foo', 'last_js'), '->removeJavascripts() removes a javascript file'); 
     266$t->is(array_keys($response->getJavascripts()), array('foo', 'last_js'), '->removeJavascripts() removes a javascript file'); 
    265267 
    266268// ->setCookie() ->getCookies() 

The Sensio Labs Network

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