예제 #1
0
 /**
  * From two arrays, returns only those elements that are present in one of the arrays but not in the other, as a
  * new array.
  *
  * None of the source arrays is modified by this method.
  *
  * You can use your own comparator for the comparison of the elements in the arrays, but the default comparator has
  * got you covered when comparing scalar values, such as `string`, `int`, `float`, and `bool`. And the default
  * comparator is smart enough to know how to compare objects of those classes that conform to the IEquality or
  * IEqualityAndOrder interface (static or not), including CArray and CMap. See the [CComparator](CComparator.html)
  * class for more on this.
  *
  * @param  array $leftArray The first array.
  * @param  array $rightArray The second array.
  * @param  callable $comparator **OPTIONAL. Default is** `CComparator::EQUALITY`. The function or method to be
  * used for the comparison of any two elements. If this parameter is provided, the comparator should take two
  * parameters, with the first parameter being an element from the first array and the second parameter being an
  * element from the second array, and return `true` if the two elements are equal and `false` otherwise.
  *
  * @return CArray The symmetric difference array between the two arrays.
  *
  * @link   CComparator.html CComparator
  */
 public static function symmetricDifference($leftArray, $rightArray, $comparator = CComparator::EQUALITY)
 {
     assert('is_carray($leftArray) && is_carray($rightArray) && is_callable($comparator)', vs(isset($this), get_defined_vars()));
     $leftArray = splarray($leftArray);
     $rightArray = splarray($rightArray);
     $unionArray = self::union($leftArray, $rightArray);
     $intersectionArray = self::intersection($leftArray, $rightArray, $comparator);
     return self::difference($unionArray, $intersectionArray, $comparator);
 }
예제 #2
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;
 }
예제 #3
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;
}
예제 #4
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;
 }