Development

Changeset 6375

You must first sign up to be able to contribute.

Changeset 6375

Show
Ignore:
Timestamp:
12/07/07 21:11:13 (2 years ago)
Author:
fabien
Message:

changed implementation of sfCultureInfo::simplify (closes #1821)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/lib/i18n/sfCultureInfo.class.php

    r5776 r6375  
    633633   * @return array simplified array. 
    634634   */ 
    635   protected function simplify($array) 
    636   { 
    637     for ($i = 0, $max = count($array); $i < $max; $i++) 
    638     { 
    639       $key = key($array); 
    640       if (is_array($array[$key]) && count($array[$key]) == 1) 
    641       { 
    642         $array[$key] = $array[$key][0]; 
    643       } 
    644       next($array); 
     635  static protected function simplify($array) 
     636  { 
     637    foreach ($array as &$item) 
     638    { 
     639      if (is_array($item) && count($item) == 1) 
     640      { 
     641        $item = $item[0]; 
     642      } 
    645643    } 
    646644 
  • branches/1.0/test/unit/i18n/sfCultureInfoTest.php

    r2834 r6375  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(52, new lime_output_color()); 
     13$t = new lime_test(56, new lime_output_color()); 
    1414 
    1515// __construct() 
     
    189189$c->NumberFormat = '#'; 
    190190$t->is($c->getNumberFormat(), '#', '->setNumberFormat() is equivalent to ->NumberFormat = '); 
     191 
     192// ->simplify() 
     193$t->diag('->simplify()'); 
     194 
     195class myCultureInfo extends sfCultureInfo 
     196{ 
     197  static public function simplify($array) 
     198  { 
     199    return parent::simplify($array); 
     200  } 
     201} 
     202 
     203$array1 = array(0 => 'hello', 1 => 'world'); 
     204$array2 = array(0 => array('hello'), 1 => 'world'); 
     205$array3 = array(0 => array('hello', 'hi'), 1 => 'world'); 
     206 
     207$ci = new myCultureInfo(); 
     208 
     209$t->isa_ok($ci->simplify($array1), 'array', '::simplify() returns an array'); 
     210$t->is_deeply($ci->simplify($array1), $array1, '::simplify() leaves 1D-arrays unchanged'); 
     211$t->is_deeply($ci->simplify($array2), $array1, '::simplify() simplifies arrays'); 
     212$t->is_deeply($ci->simplify($array3), $array3, '::simplify() leaves not-simplifiable arrays unchanged'); 

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.