Development

Changeset 23945

You must first sign up to be able to contribute.

Changeset 23945

Show
Ignore:
Timestamp:
11/14/09 19:12:41 (4 years ago)
Author:
fabien
Message:

[1.4] readded a non-deprecated method

Files:

Legend:

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

    r23942 r23945  
    439439 
    440440  /** 
     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  /** 
    441494   * Get path to php cli. 
    442495   * 
     
    513566  /** 
    514567   * Adds a path to the PHP include_path setting. 
    515    *  
     568   * 
    516569   * @param   mixed  $path     Single string path or an array of paths 
    517570   * @param   string $position Either 'front' or 'back' 
    518    *  
     571   * 
    519572   * @return  string The old include path 
    520573   */