Changeset 6690
- Timestamp:
- 12/24/07 13:56:19 (1 year ago)
- Files:
-
- branches/1.1/lib/request/sfWebRequest.class.php (modified) (1 diff)
- branches/1.1/test/unit/request/sfWebRequestTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/request/sfWebRequest.class.php
r6510 r6690 553 553 554 554 return isset($pathArray['REQUEST_METHOD']) ? $pathArray['REQUEST_METHOD'] : 'GET'; 555 } 556 557 /** 558 * Returns the preferred culture for the current request. 559 * 560 * @param array An array of ordered cultures available 561 * 562 * @return string The preferred culture 563 */ 564 public function getPreferredCulture(array $cultures = null) 565 { 566 $preferredCultures = $this->getLanguages(); 567 568 if (is_null($cultures)) 569 { 570 return isset($preferredCultures[0]) ? $preferredCultures[0] : null; 571 } 572 573 if (!$preferredCultures) 574 { 575 return $cultures[0]; 576 } 577 578 $preferredCultures = array_values(array_intersect($preferredCultures, $cultures)); 579 580 return isset($preferredCultures[0]) ? $preferredCultures[0] : null; 555 581 } 556 582 branches/1.1/test/unit/request/sfWebRequestTest.php
r4957 r6690 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test(1 3, new lime_output_color());13 $t = new lime_test(16, new lime_output_color()); 14 14 15 15 class myRequest extends sfWebRequest … … 35 35 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-us,en;q=0.5,fr;q=0.3'; 36 36 $t->is($request->getLanguages(), array('en_US', 'en', 'fr'), '->getLanguages() returns an array with all accepted languages'); 37 38 // ->getPreferredCulture() 39 $t->diag('->getPreferredCulture()'); 40 $request->languages = null; 41 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = ''; 42 $t->is($request->getPreferredCulture(array('fr', 'en')), 'fr', '->getPreferredCulture() returns the first given culture if the client do not send an ACCEPT_LANGUAGE header'); 43 44 $request->languages = null; 45 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-us,en;q=0.5,fr;q=0.3'; 46 $t->is($request->getPreferredCulture(array('fr', 'en')), 'en', '->getPreferredCulture() returns the preferred culture'); 47 48 $request->languages = null; 49 $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-us,en;q=0.5,fr'; 50 $t->is($request->getPreferredCulture(array('fr', 'en')), 'fr', '->getPreferredCulture() returns the preferred culture'); 37 51 38 52 // ->getCharsets()