Changeset 11089
- Timestamp:
- 08/25/08 08:24:38 (10 months ago)
- Files:
-
- branches/1.2/UPGRADE_TO_1_2 (modified) (4 diffs)
- branches/1.2/lib/helper/AssetHelper.php (modified) (2 diffs)
- branches/1.2/lib/response/sfWebResponse.class.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/UPGRADE_TO_1_2
r11083 r11089 54 54 charset for the response. This charset is automatically updated if 55 55 you change it by setting the content type. 56 57 The `getStylesheets()` and `getJavascripts()` methods now return all the 58 stylesheets and javascripts ordered by position if you pass `sfWebResponse::ALL` 59 as their first argument: 60 61 [php] 62 $response = new sfWebResponse(new sfEventDispatcher()); 63 $response->addStylesheet('foo.css'); 64 $response->addStylesheet('bar.css', 'first'); 65 66 var_export($response->getStylesheets(sfWebResponse::ALL)); 67 68 // outputs 69 array( 70 'bar.css' => array(), 71 'foo.css' => array(), 72 ) 73 74 The old behavior is still available by passing the `sfWebResponse::RAW` position: 75 76 [php] 77 var_export($response->getStylesheets(sfWebResponse::RAW)); 78 79 // outputs 80 array( 81 'first' => 82 array( 83 'bar.css' => array (), 84 ), 85 '' => 86 array( 87 'foo.css' => array(), 88 ), 89 'last' => array(), 90 ) 91 92 All the positions (first, '', and last) are now also available as constants: 93 94 [php] 95 sfWebResponse::FIRST === 'first' 96 sfWebResponse::MIDDLE === '' 97 sfWebResponse::LAST === 'last' 56 98 57 99 Validators … … 141 183 $yaml = new sfYamlParser(); 142 184 143 print_r($yaml->parse(<<<EOF185 var_export($yaml->parse(<<<EOF 144 186 default_param: &default_param 145 187 datasource: propel … … 157 199 )); 158 200 159 // displays 160 Array 161 ( 162 [default_param] => Array 163 ( 164 [datasource] => propel 165 [phptype] => mysql 166 [hostspec] => localhost 167 [database] => db 168 [username] => user 169 [password] => pass 170 ) 171 172 [param] => Array 173 ( 174 [datasource] => propel 175 [phptype] => mysql 176 [hostspec] => localhost 177 [database] => db 178 [username] => myuser 179 [password] => mypass 180 ) 181 201 // outputs 202 array( 203 'default_param' => array( 204 'datasource' => 'propel', 205 'phptype' => 'mysql', 206 'hostspec' => 'localhost', 207 'database' => 'db', 208 'username' => 'user', 209 'password' => 'pass', 210 ) 211 212 'param' => array( 213 'datasource' => 'propel', 214 'phptype' => 'mysql', 215 'hostspec' => 'localhost', 216 'database' => 'db', 217 'username' => 'myuser', 218 'password' => 'mypass', 219 ) 182 220 ) 183 221 … … 228 266 $log->log('foo'); 229 267 230 print_r($log->getLogs());268 var_export($log->getLogs()); 231 269 232 270 // outputs 233 Array(234 [0] => Array(235 [priority] => 6236 [priority_name] => info237 [time] => 1219385295238 [message] => foo239 [type] => sfOther240 [debug_stack] => Array()271 array( 272 0 => array( 273 'priority' => 6, 274 'priority_name' => 'info', 275 'time' => 1219385295, 276 'message' => 'foo', 277 'type' => 'sfOther', 278 'debug_stack' => array() 241 279 ) 242 280 ) branches/1.2/lib/helper/AssetHelper.php
r9101 r11089 461 461 sfConfig::set('symfony.asset.javascripts_included', true); 462 462 463 $already_seen = array();464 463 $html = ''; 465 466 foreach ($response->getPositions() as $position) 467 { 468 foreach ($response->getJavascripts($position) as $files => $options) 469 { 470 if (!is_array($files)) 471 { 472 $files = array($files); 473 } 474 475 foreach ($files as $file) 476 { 477 if (isset($already_seen[$file])) continue; 478 479 $already_seen[$file] = 1; 480 $html .= javascript_include_tag($file, $options); 481 } 482 } 464 foreach ($response->getJavascripts(sfWebResponse::ALL) as $file => $options) 465 { 466 $html .= javascript_include_tag($file, $options); 483 467 } 484 468 … … 510 494 sfConfig::set('symfony.asset.stylesheets_included', true); 511 495 512 $already_seen = array();513 496 $html = ''; 514 515 foreach ($response->getPositions() as $position) 516 { 517 foreach ($response->getStylesheets($position) as $files => $options) 518 { 519 if (!is_array($files)) 520 { 521 $files = array($files); 522 } 523 524 foreach ($files as $file) 525 { 526 if (isset($already_seen[$file])) continue; 527 528 $already_seen[$file] = 1; 529 $html .= stylesheet_tag($file, $options); 530 } 531 } 497 foreach ($response->getStylesheets(sfWebResponse::ALL) as $file => $options) 498 { 499 $html .= stylesheet_tag($file, $options); 532 500 } 533 501 branches/1.2/lib/response/sfWebResponse.class.php
r11059 r11089 21 21 class sfWebResponse extends sfResponse 22 22 { 23 const 24 FIRST = 'first', 25 MIDDLE = '', 26 LAST = 'last', 27 ALL = 'ALL', 28 RAW = 'RAW'; 29 23 30 protected 24 31 $cookies = array(), … … 578 585 * Retrieves stylesheets for the current web response. 579 586 * 580 * @param string $position 581 * 582 * @return string Stylesheets 587 * If you pass sfWebResponse::ALL as the position, 588 * the methods returns all stylesheets ordered by position. 589 * 590 * @param string $position The position 591 * 592 * @return array An associative array of javascript files as keys and options as values 583 593 */ 584 594 public function getStylesheets($position = '') 585 595 { 586 if ($position == 'ALL') 596 if (sfWebResponse::ALL === $position) 597 { 598 $stylesheets = array(); 599 foreach ($this->getPositions() as $position) 600 { 601 foreach ($this->stylesheets[$position] as $file => $options) 602 { 603 $stylesheets[$file] = $options; 604 } 605 } 606 607 return $stylesheets; 608 } 609 else if (sfWebResponse::RAW === $position) 587 610 { 588 611 return $this->stylesheets; … … 591 614 $this->validatePosition($position); 592 615 593 return isset($this->stylesheets[$position]) ? $this->stylesheets[$position] : array();616 return $this->stylesheets[$position]; 594 617 } 595 618 … … 597 620 * Adds a stylesheet to the current web response. 598 621 * 599 * @param string $ css Stylesheet622 * @param string $file The stylesheet file 600 623 * @param string $position Position 601 624 * @param string $options Stylesheet options 602 625 */ 603 public function addStylesheet($ css, $position = '', $options = array())626 public function addStylesheet($file, $position = '', $options = array()) 604 627 { 605 628 $this->validatePosition($position); 606 629 607 $this->stylesheets[$position][$ css] = $options;630 $this->stylesheets[$position][$file] = $options; 608 631 } 609 632 … … 611 634 * Removes a stylesheet from the current web response. 612 635 * 613 * @param string $css Stylesheet636 * @param string $css The stylesheet file 614 637 * @param string $position Position 615 638 */ 616 public function removeStylesheet($ css, $position = '')639 public function removeStylesheet($file, $position = '') 617 640 { 618 641 $this->validatePosition($position); 619 642 620 unset($this->stylesheets[$position][$css]); 621 } 622 623 /** 624 * Retrieves javascript code from the current web response. 625 * 626 * @param string $position Position 627 * 628 * @return string Javascript code 643 unset($this->stylesheets[$position][$file]); 644 } 645 646 /** 647 * Retrieves javascript files from the current web response. 648 * 649 * If you pass sfWebResponse::ALL as the position, 650 * the methods returns all javascripts ordered by position. 651 * 652 * @param string $position The position 653 * 654 * @return array An associative array of javascript files as keys and options as values 629 655 */ 630 656 public function getJavascripts($position = '') 631 657 { 632 if ($position == 'ALL') 658 if (sfWebResponse::ALL === $position) 659 { 660 $javascripts = array(); 661 foreach ($this->getPositions() as $position) 662 { 663 foreach ($this->javascripts[$position] as $file => $options) 664 { 665 $javascripts[$file] = $options; 666 } 667 } 668 669 return $javascripts; 670 } 671 else if (sfWebResponse::RAW === $position) 633 672 { 634 673 return $this->javascripts; … … 637 676 $this->validatePosition($position); 638 677 639 return isset($this->javascripts[$position]) ? $this->javascripts[$position] : array();678 return $this->javascripts[$position]; 640 679 } 641 680 … … 643 682 * Adds javascript code to the current web response. 644 683 * 645 * @param string $ js Javascript code684 * @param string $gile The JavaScript file 646 685 * @param string $position Position 647 686 * @param string $options Javascript options 648 687 */ 649 public function addJavascript($ js, $position = '', $options = array())688 public function addJavascript($file, $position = '', $options = array()) 650 689 { 651 690 $this->validatePosition($position); 652 691 653 $this->javascripts[$position][$ js] = $options;654 } 655 656 /** 657 * Removes javascript code from the current web response.658 * 659 * @param string $ js Javascript code692 $this->javascripts[$position][$file] = $options; 693 } 694 695 /** 696 * Removes a JavaScript file from the current web response. 697 * 698 * @param string $file The Javascript file 660 699 * @param string $position Position 661 700 */ 662 public function removeJavascript($ js, $position = '')701 public function removeJavascript($file, $position = '') 663 702 { 664 703 $this->validatePosition($position); 665 704 666 unset($this->javascripts[$position][$ js]);705 unset($this->javascripts[$position][$file]); 667 706 } 668 707 … … 727 766 $this->metas = $response->getMetas(); 728 767 $this->httpMetas = $response->getHttpMetas(); 729 $this->stylesheets = $response->getStylesheets( 'ALL');730 $this->javascripts = $response->getJavascripts( 'ALL');768 $this->stylesheets = $response->getStylesheets(sfWebResponse::RAW); 769 $this->javascripts = $response->getJavascripts(sfWebResponse::RAW); 731 770 $this->slots = $response->getSlots(); 732 771 }

