Beispiel #1
0
 protected static function recurseValueBeforeFiltering($value, $inputFilterOrFilterCollection, &$success, $currDepth)
 {
     assert('$inputFilterOrFilterCollection instanceof CInputFilter || ' . 'is_collection($inputFilterOrFilterCollection)', vs(isset($this), get_defined_vars()));
     if ($currDepth == self::$ms_maxRecursionDepth) {
         $success = false;
         return;
     }
     $currDepth++;
     if (!is_cmap($value)) {
         // Only interested in PHP arrays.
         return $value;
     }
     if (is_carray($inputFilterOrFilterCollection)) {
         // The output value is expected to be a CArray; the keys in the arrived PHP array should be sequential.
         if (!CMap::areKeysSequential($value)) {
             $success = false;
             return;
         }
         $value = CArray::fromPArray($value);
         $len = CArray::length($value);
         if ($len != CArray::length($inputFilterOrFilterCollection)) {
             $success = false;
             return;
         }
         for ($i = 0; $i < $len; $i++) {
             $inputValue = $value[$i];
             $inputFilterElement = $inputFilterOrFilterCollection[$i];
             $inputValue = self::recurseValueBeforeFiltering($inputValue, $inputFilterElement, $success, $currDepth);
             if (!$success) {
                 return;
             }
             $value[$i] = $inputValue;
         }
     } else {
         if (is_cmap($inputFilterOrFilterCollection)) {
             // The output value is expected to be a CMap; already got one.
             foreach ($value as $inputKey => &$inputValue) {
                 if (!CMap::hasKey($inputFilterOrFilterCollection, $inputKey)) {
                     $success = false;
                     return;
                 }
                 $inputFilterElement = $inputFilterOrFilterCollection[$inputKey];
                 $inputValue = self::recurseValueBeforeFiltering($inputValue, $inputFilterElement, $success, $currDepth);
                 if (!$success) {
                     return;
                 }
             }
             unset($inputValue);
         } else {
             $success = false;
             return;
         }
     }
     return $value;
 }
Beispiel #2
0
 /**
  * Determines if the keys in a map are all integer and sequential.
  *
  * Sequential keys are a sequence of integers that start with a `0` and go up, incrementing exactly by one.
  *
  * This method could be useful to see if a PHP's associative array (a map) can be naturally converted into a
  * regular array (an OOP array) when dealing with interfaces that are using the PHP's associative array in the role
  * of a regular array.
  *
  * As a special case, the method returns `true` for an empty map.
  *
  * @return bool `true` if all keys in the map are integer and sequential, `false` otherwise.
  */
 public function areKeysSequential()
 {
     return CMap::areKeysSequential($this->m_map);
 }
Beispiel #3
0
 public function testAreKeysSequential()
 {
     $map = [0 => "a", 1 => "b", 2 => "c", 3 => "d", 4 => "e"];
     $this->assertTrue(CMap::areKeysSequential($map));
     $map = [0 => "a", 1 => "b", 2 => "c", 4 => "d", 5 => "e"];
     $this->assertFalse(CMap::areKeysSequential($map));
     $map = [0 => "a", 1 => "b", 2 => "c", "three" => "d", 4 => "e"];
     $this->assertFalse(CMap::areKeysSequential($map));
 }
Beispiel #4
0
/**
 * @ignore
 */
function _to_oop_tp($value)
{
    // Only used with OOP wrapping for third-party components.
    if (is_array($value)) {
        foreach ($value as &$mapValue) {
            $mapValue = _to_oop_tp($mapValue);
        }
        unset($mapValue);
        if (!CMap::areKeysSequential($value)) {
            $value = oop_m($value);
        } else {
            $value = oop_a(CArray::fromPArray($value));
        }
        return $value;
    }
    if ($value instanceof SplFixedArray) {
        $len = CArray::length($value);
        for ($i = 0; $i < $len; $i++) {
            $value[$i] = _to_oop_tp($value[$i]);
        }
        return oop_a($value);
    }
    return $value;
}
Beispiel #5
0
 protected static function recurseQueryValueAfterParsing($value, $currDepth)
 {
     if ($currDepth == self::$ms_maxRecursionDepth) {
         return $value;
     }
     $currDepth++;
     if (!is_cmap($value)) {
         // Only interested in PHP's associative arrays.
         return $value;
     }
     if (CMap::areKeysSequential($value)) {
         $value = CArray::fromPArray($value);
         $len = CArray::length($value);
         for ($i = 0; $i < $len; $i++) {
             $value[$i] = self::recurseQueryValueAfterParsing($value[$i], $currDepth);
         }
         return oop_a($value);
     } else {
         foreach ($value as &$mapValue) {
             $mapValue = self::recurseQueryValueAfterParsing($mapValue, $currDepth);
         }
         unset($mapValue);
         return oop_m($value);
     }
 }