Changeset 10514
- Timestamp:
- 07/30/08 17:37:02 (4 months ago)
- Files:
-
- branches/1.1/lib/util/sfToolkit.class.php (modified) (3 diffs)
- branches/1.1/test/unit/util/sfToolkitTest.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/util/sfToolkit.class.php
r9588 r10514 564 564 return $default; 565 565 } 566 $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 567 $offset = $end; 566 else if (is_array($array)) 567 { 568 $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 569 $offset = $end; 570 } 571 else 572 { 573 return $default; 574 } 568 575 } 569 576 … … 604 611 return false; 605 612 } 606 $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 607 $offset = $end; 613 else if (is_array($array)) 614 { 615 $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; 616 $offset = $end; 617 } 618 else 619 { 620 return false; 621 } 608 622 } 609 623 … … 658 672 return $default; 659 673 } 660 661 $parent = &$value; 662 $key = substr($name, $pos + 1, $end - $pos - 1); 663 $value = &$value[$key]; 664 $offset = $end; 674 else if (is_array($value)) 675 { 676 $parent = &$value; 677 $key = substr($name, $pos + 1, $end - $pos - 1); 678 $value = &$value[$key]; 679 $offset = $end; 680 } 681 else 682 { 683 return $default; 684 } 665 685 } 666 686 branches/1.1/test/unit/util/sfToolkitTest.php
r8532 r10514 11 11 require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 12 12 13 $t = new lime_test( 99, new lime_output_color());13 $t = new lime_test(103, new lime_output_color()); 14 14 15 15 // ::stringToArray() … … 197 197 'bar', 198 198 ), 199 'simple' => 'string', 199 200 ); 200 201 … … 214 215 $t->is(sfToolkit::hasArrayValueForPath($arr, 'bar[1]'), true, '::hasArrayValueForPath() can take an array indexed by integer'); 215 216 $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'); 216 219 217 220 // ::getArrayValueForPath() … … 234 237 $t->is(sfToolkit::getArrayValueForPath($arr, 'bar[2]'), null, '::getArrayValueForPath() can take an array indexed by integer'); 235 238 $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'); 236 241 237 242 // ::removeArrayValueForPath() … … 248 253 'bar', 249 254 ), 255 'simple' => 'string', 250 256 ), '::removeArrayValueForPath() removes a key'); 251 257 $t->is(sfToolkit::removeArrayValueForPath($arr, 'barfoo'), null, '::removeArrayValueForPath() returns null if the key does not exist'); 252 258 $t->is(sfToolkit::removeArrayValueForPath($arr, 'barfoo', 'bar'), 'bar', '::removeArrayValueForPath() takes the default value as a third argument'); 259 $t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[bar][baz][booze]'), null, '::removeArrayValueForPath() is not fooled by php mistaking strings and array'); 260 $t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[simple][bad]'), null, '::removeArrayValueForPath() is not fooled by php mistaking strings and array'); 253 261 254 262 $t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[bar][baz]'), 'foo bar', '::removeArrayValueForPath() works with deep paths'); … … 262 270 'bar', 263 271 ), 272 'simple' => 'string', 264 273 ), '::removeArrayValueForPath() works with deep paths');