Esempio n. 1
0
 /**
  * Converts a PHP's associative array into an SplFixedArray object (called CArray).
  *
  * All keys in the PHP's associative array are discarded and indexes for the resulting array are generated
  * according to the order in which values appear in the associative array, without gaps.
  *
  * @param  map $map The PHP's associative array to be converted.
  *
  * @return CArray The resulting array.
  */
 public static function fromPArray($map)
 {
     assert('is_cmap($map)', vs(isset($this), get_defined_vars()));
     $map = parray($map);
     return SplFixedArray::fromArray($map, false);
 }
Esempio n. 2
0
 protected static function recurseMergingMaps(&$thisMap, $thatMap)
 {
     if (!is_array($thisMap)) {
         $thisMap =& $thisMap->toPArray();
     }
     $thatMap = parray($thatMap);
     foreach ($thatMap as $thatKey => $thatValue) {
         $goDeeper = false;
         $thisValue;
         if (is_cmap($thatValue) && self::hasKey($thisMap, $thatKey)) {
             $thisValue =& $thisMap[$thatKey];
             if (is_cmap($thisValue)) {
                 $goDeeper = true;
             }
         }
         if ($goDeeper) {
             self::recurseMergingMaps($thisValue, $thatValue);
         } else {
             $thisMap[$thatKey] = $thatValue;
         }
     }
 }
Esempio n. 3
0
 function parray($array, $prep = '')
 {
     $ret = "";
     $prep = "{$prep}|";
     if (is_array($array) || is_object($array)) {
         if (is_object($array)) {
             $array = get_object_vars($array);
         }
         while (list($key, $val) = each($array)) {
             $type = gettype($val);
             if (is_array($val)) {
                 $line = "-+ {$key} ({$type})\n";
                 $line .= parray($val, "{$prep} ");
             } else {
                 if (is_object($val)) {
                     // C'est un object
                     $line = "-+ {$key} ({$type})\n";
                     $line .= parray(get_object_vars($val), "{$prep} ");
                 } else {
                     $line = "=> {$key} = \"{$val}\" ({$type})\n";
                 }
             }
             $ret .= $prep . $line;
         }
     }
     return $ret;
 }
Esempio n. 4
0
/**
 * @ignore
 */
function _from_oop_tp($value)
{
    // Only used with OOP wrapping for third-party components.
    if (is_carray($value)) {
        $value = splarray($value);
        $len = CArray::length($value);
        for ($i = 0; $i < $len; $i++) {
            $value[$i] = _from_oop_tp($value[$i]);
        }
        return $value->toArray();
    }
    if (is_cmap($value)) {
        $value = parray($value);
        foreach ($value as &$mapValue) {
            $mapValue = _from_oop_tp($mapValue);
        }
        unset($mapValue);
        return $value;
    }
    return $value;
}
Esempio n. 5
0
 protected static function recurseQueryValueBeforeComposingQs($value, $currDepth)
 {
     if ($currDepth == self::$ms_maxRecursionDepth) {
         return $value;
     }
     $currDepth++;
     if (!is_collection($value)) {
         if (!is_cstring($value)) {
             if (is_bool($value)) {
                 $value = CString::fromBool10($value);
             } else {
                 if (is_int($value)) {
                     $value = CString::fromInt($value);
                 } else {
                     if (is_float($value)) {
                         $value = CString::fromFloat($value);
                     } else {
                         assert('false', vs(isset($this), get_defined_vars()));
                     }
                 }
             }
         }
         return $value;
     }
     if (is_carray($value)) {
         $value = splarray($value)->toArray();
     } else {
         $value = parray($value);
     }
     foreach ($value as &$mapValue) {
         $mapValue = self::recurseQueryValueBeforeComposingQs($mapValue, $currDepth);
     }
     unset($mapValue);
     return $value;
 }
Esempio n. 6
0
 protected static function recurseValueBeforeEncoding($value, $currDepth)
 {
     if ($currDepth == self::$ms_maxRecursionDepth) {
         return $value;
     }
     $currDepth++;
     if (is_cstring($value)) {
         return $value;
     }
     if (is_cmap($value)) {
         $value = parray($value);
         foreach ($value as &$valueInMap) {
             $valueInMap = self::recurseValueBeforeEncoding($valueInMap, $currDepth);
         }
         unset($valueInMap);
         $value = (object) $value;
     } else {
         if (is_carray($value)) {
             $value = splarray($value);
             $len = CArray::length($value);
             for ($i = 0; $i < $len; $i++) {
                 $value[$i] = self::recurseValueBeforeEncoding($value[$i], $currDepth);
             }
             $value = CArray::toPArray($value);
         }
     }
     return $value;
 }