private static int MultiSortResolveArgs(
Context ctx,
PhpArray first,
PhpValue[] args,
PhpArray[] arrays,
IComparer<KeyValuePair<IntStringKey, PhpValue>>[] comparers)
{
int col_count = 1;
int row_count = first.Count;
ComparisonMethod method = ComparisonMethod.Undefined;
SortingOrder order = SortingOrder.Undefined;
if (arrays != null)
{
arrays[0] = first;
}
for (int i = 0; i < args.Length; i++)
{
var arg = args[i];
if (arg.IsArray)
{
var array = arg.Array;
// checks whether the currently processed array has the same length as the first one:
if (array.Count != row_count)
{
//PhpException.Throw(PhpError.Warning, CoreResources.GetString("lengths_are_different", "the first array", string.Format("{0}-th array", col_count)));
//return 0;
throw new ArgumentException();
}
// sets next array:
if (arrays != null)
arrays[col_count] = array;
// sets comparer of the previous array:
if (comparers != null)
comparers[col_count - 1] = GetComparer(ctx, method, order, false);
// resets values:
method = ComparisonMethod.Undefined;
order = SortingOrder.Undefined;
col_count++;
}
else if (arg.TypeCode == PhpTypeCode.Long)
{
var num = (int)arg.ToLong();
switch (num)
{
case (int)ComparisonMethod.Numeric:
case (int)ComparisonMethod.Regular:
case (int)ComparisonMethod.String:
case (int)ComparisonMethod.LocaleString:
if (method != ComparisonMethod.Undefined)
{
//PhpException.Throw(PhpError.Warning, LibResources.GetString("sorting_flag_already_specified", i));
//return 0;
throw new ArgumentException();
}
else
{
method = (ComparisonMethod)num;
}
break;
case (int)SortingOrder.Ascending:
case (int)SortingOrder.Descending:
if (order != SortingOrder.Undefined)
{
//PhpException.Throw(PhpError.Warning, LibResources.GetString("sorting_flag_already_specified", i));
//return 0;
throw new ArgumentException();
}
else
{
order = (SortingOrder)num;
}
break;
default:
//PhpException.Throw(PhpError.Warning, LibResources.GetString("argument_not_array_or_sort_flag", i));
//return 0;
throw new ArgumentException();
}
}
else
{
//PhpException.Throw(PhpError.Warning, LibResources.GetString("argument_not_array_or_sort_flag", i));
//return 0;
throw new ArgumentException();
}
}
// sets comparer of the previous array:
if (comparers != null)
comparers[col_count - 1] = GetComparer(ctx, method, order, false);
return col_count;
}