Changeset 10518
- Timestamp:
- 07/30/08 18:06:02 (1 year ago)
- Files:
-
- branches/1.2/lib/util/sfToolkit.class.php (modified) (4 diffs)
- branches/1.2/test/unit/util/sfToolkitTest.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.2/lib/util/sfToolkit.class.php
r9588 r10518 518 518 return $default; 519 519 } 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 } 522 529 } 523 530 … … 564 571 return $default; 565 572 } 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 } 568 582 } 569 583 … … 604 618 return false; 605 619 } 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 } 608 629 } 609 630 … … 658 679 return $default; 659 680 } 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 } 665 692 } 666 693 branches/1.2/test/unit/util/sfToolkitTest.php
r8532 r10518 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(104, 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'); 241 $t->is(sfToolkit::getArrayValueForPathByRef($arr, 'foo[bar][baz][booze]'), null, '::getArrayValueForPathByRef() is not fooled by php mistaking strings and array'); 236 242 237 243 // ::removeArrayValueForPath() … … 248 254 'bar', 249 255 ), 256 'simple' => 'string', 250 257 ), '::removeArrayValueForPath() removes a key'); 251 258 $t->is(sfToolkit::removeArrayValueForPath($arr, 'barfoo'), null, '::removeArrayValueForPath() returns null if the key does not exist'); 252 259 $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'); 253 262 254 263 $t->is(sfToolkit::removeArrayValueForPath($arr, 'foo[bar][baz]'), 'foo bar', '::removeArrayValueForPath() works with deep paths'); … … 262 271 'bar', 263 272 ), 273 'simple' => 'string', 264 274 ), '::removeArrayValueForPath() works with deep paths');

