| | 441 | * Returns an array value for a path. |
|---|
| | 442 | * |
|---|
| | 443 | * @param array $values The values to search |
|---|
| | 444 | * @param string $name The token name |
|---|
| | 445 | * @param array $default Default if not found |
|---|
| | 446 | * |
|---|
| | 447 | * @return array |
|---|
| | 448 | */ |
|---|
| | 449 | public static function getArrayValueForPath($values, $name, $default = null) |
|---|
| | 450 | { |
|---|
| | 451 | if (false === $offset = strpos($name, '[')) |
|---|
| | 452 | { |
|---|
| | 453 | return isset($values[$name]) ? $values[$name] : $default; |
|---|
| | 454 | } |
|---|
| | 455 | |
|---|
| | 456 | if (!isset($values[substr($name, 0, $offset)])) |
|---|
| | 457 | { |
|---|
| | 458 | return $default; |
|---|
| | 459 | } |
|---|
| | 460 | |
|---|
| | 461 | $array = $values[substr($name, 0, $offset)]; |
|---|
| | 462 | |
|---|
| | 463 | while (false !== $pos = strpos($name, '[', $offset)) |
|---|
| | 464 | { |
|---|
| | 465 | $end = strpos($name, ']', $pos); |
|---|
| | 466 | if ($end == $pos + 1) |
|---|
| | 467 | { |
|---|
| | 468 | // reached a [] |
|---|
| | 469 | if (!is_array($array)) |
|---|
| | 470 | { |
|---|
| | 471 | return $default; |
|---|
| | 472 | } |
|---|
| | 473 | break; |
|---|
| | 474 | } |
|---|
| | 475 | else if (!isset($array[substr($name, $pos + 1, $end - $pos - 1)])) |
|---|
| | 476 | { |
|---|
| | 477 | return $default; |
|---|
| | 478 | } |
|---|
| | 479 | else if (is_array($array)) |
|---|
| | 480 | { |
|---|
| | 481 | $array = $array[substr($name, $pos + 1, $end - $pos - 1)]; |
|---|
| | 482 | $offset = $end; |
|---|
| | 483 | } |
|---|
| | 484 | else |
|---|
| | 485 | { |
|---|
| | 486 | return $default; |
|---|
| | 487 | } |
|---|
| | 488 | } |
|---|
| | 489 | |
|---|
| | 490 | return $array; |
|---|
| | 491 | } |
|---|
| | 492 | |
|---|
| | 493 | /** |
|---|