Development

Changeset 10518

You must first sign up to be able to contribute.

Changeset 10518

Show
Ignore:
Timestamp:
07/30/08 18:06:02 (1 year ago)
Author:
hartym
Message:

[1.2] *forthported r10514 and r10516 to 1.2 branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/lib/util/sfToolkit.class.php

    r9588 r10518  
    518518        return $default; 
    519519      } 
    520       $array = &$array[substr($name, $pos + 1, $end - $pos - 1)]; 
    521       $offset = $end; 
     520      else if (is_array($array)) 
     521      { 
     522        $array = &$array[substr($name, $pos + 1, $end - $pos - 1)]; 
     523        $offset = $end; 
     524      } 
     525      else 
     526      { 
     527        return $default; 
     528      } 
    522529    } 
    523530 
     
    564571        return $default; 
    565572      } 
    566       $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
    567       $offset = $end; 
     573      else if (is_array($array)) 
     574      { 
     575        $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
     576        $offset = $end; 
     577      } 
     578      else 
     579      { 
     580        return $default; 
     581      } 
    568582    } 
    569583 
     
    604618        return false; 
    605619      } 
    606       $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
    607       $offset = $end; 
     620      else if (is_array($array)) 
     621      { 
     622        $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 
     623        $offset = $end; 
     624      } 
     625      else 
     626      { 
     627        return false; 
     628      } 
    608629    } 
    609630 
     
    658679        return $default; 
    659680      } 
    660  
    661       $parent = &$value; 
    662       $key = substr($name, $pos + 1, $end - $pos - 1); 
    663       $value = &$value[$key]; 
    664       $offset = $end; 
     681      else if (is_array($value)) 
     682      { 
     683        $parent = &$value; 
     684        $key = substr($name, $pos + 1, $end - $pos - 1); 
     685        $value = &$value[$key]; 
     686        $offset = $end; 
     687      } 
     688      else 
     689      { 
     690        return $default; 
     691      } 
    665692    } 
    666693 
  • branches/1.2/test/unit/util/sfToolkitTest.php

    r8532 r10518  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(99, new lime_output_color()); 
     13$t = new lime_test(104, new lime_output_color()); 
    1414 
    1515// ::stringToArray() 
     
    197197    'bar', 
    198198  ), 
     199  'simple' => 'string', 
    199200); 
    200201 
     
    214215$t->is(sfToolkit::hasArrayValueForPath($arr, 'bar[1]'), true, '::hasArrayValueForPath() can take an array indexed by integer'); 
    215216$t->is(sfToolkit::hasArrayValueForPath($arr, 'bar[2]'), false, '::hasArrayValueForPath() can take an array indexed by integer'); 
     217 
     218$t->is(sfToolkit::hasArrayValueForPath($arr, 'foo[bar][baz][booze]'), false, '::hasArrayValueForPath() is not fooled by php mistaking strings and array'); 
    216219 
    217220// ::getArrayValueForPath() 
     
    234237$t->is(sfToolkit::getArrayValueForPath($arr, 'bar[2]'), null, '::getArrayValueForPath() can take an array indexed by integer'); 
    235238$t->is(sfToolkit::getArrayValueForPath($arr, 'bar[2]', 'foo'), 'foo', '::getArrayValueForPath() can take an array indexed by integer'); 
     239 
     240$t->is(sfToolkit::getArrayValueForPath($arr, 'foo[bar][baz][booze]'), null, '::getArrayValueForPath() is not fooled by php mistaking strings and array'); 
     241$t->is(sfToolkit::getArrayValueForPathByRef($arr, 'foo[bar][baz][booze]'), null, '::getArrayValueForPathByRef() is not fooled by php mistaking strings and array'); 
    236242 
    237243// ::removeArrayValueForPath() 
     
    248254    'bar', 
    249255  ), 
     256  'simple' => 'string', 
    250257), '::removeArrayValueForPath() removes a key'); 
    251258$t->is(sfToolkit::removeArrayValueForPath($arr, 'barfoo'), null, '::removeArrayValueForPath() returns null if the key does not exist'); 
    252259$t->is(sfToolkit::removeArrayValueForPath($arr, 'barfoo', 'bar'), 'bar', '::removeArrayValueForPath() takes the default value as a third argument'); 
     260$t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[bar][baz][booze]'), null, '::removeArrayValueForPath() is not fooled by php mistaking strings and array'); 
     261$t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[simple][bad]'), null, '::removeArrayValueForPath() is not fooled by php mistaking strings and array'); 
    253262 
    254263$t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[bar][baz]'), 'foo bar', '::removeArrayValueForPath() works with deep paths'); 
     
    262271    'bar', 
    263272  ), 
     273  'simple' => 'string', 
    264274), '::removeArrayValueForPath() works with deep paths'); 

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.