Pchp.Library.Arrays.SplitArraysAndComparers C# (CSharp) Method

SplitArraysAndComparers() private static method

There have to be at least 1 value in vars. The last is converted to callback, the rest to arrays.
private static SplitArraysAndComparers ( int comparerCount, PhpArray array, PhpValue vars, PhpArray &arrays, IPhpCallable &cmp1, IPhpCallable &cmp2 ) : bool
comparerCount int
array Pchp.Core.PhpArray
vars Pchp.Core.PhpValue
arrays Pchp.Core.PhpArray
cmp1 IPhpCallable
cmp2 IPhpCallable
return bool
        private static bool SplitArraysAndComparers(int comparerCount, PhpArray array, PhpValue[] vars, out PhpArray[] arrays, out IPhpCallable cmp1, out IPhpCallable cmp2)
        {
            arrays = null;
            cmp1 = cmp2 = null;

            if (vars == null || vars.Length == 0)
            {
                // TODO: PhpException.InvalidArgumentCount(null, null);
                return false;
            }

            // the first callback:
            cmp1 = vars[vars.Length - comparerCount].AsCallable();
            if (PhpVariable.IsValidCallback(cmp1)) return false;

            // the second callback:
            if (comparerCount > 1)
            {
                cmp2 = vars[vars.Length - 1].AsCallable();
                if (!PhpVariable.IsValidCallback(cmp2)) return false;
            }

            // remaining arguments should be arrays:
            arrays = new PhpArray[vars.Length - comparerCount + 1];
            arrays[0] = array;
            for (int i = 0; i < vars.Length - comparerCount; i++)
            {
                var var = vars[i];
                if ((arrays[i + 1] = vars[i].AsArray()) == null)
                {
                    // TODO: PhpException.Throw(PhpError.Warning, LibResources.GetString("argument_not_array", i + 3));
                    return false;
                }
            }

            //
            return true;
        }