<?php
namespace wcf\util;
+use wcf\system\Callback;
use wcf\system\exception\SystemException;
/**
* @param callable $callback
* @return boolean
*/
- public static function compare(array $array1, array $array2, $callback = null) {
+ public static function compare(array $array1, array $array2, Callback $callback = null) {
return static::compareHelper('value', $array1, $array2, $callback);
}
* @param callable $callback
* @return boolean
*/
- public static function compareKey(array $array1, array $array2, $callback = null) {
+ public static function compareKey(array $array1, array $array2, Callback $callback = null) {
return static::compareHelper('key', $array1, $array2, $callback);
}
* @param callable $callback
* @return boolean
*/
- public static function compareAssoc(array $array1, array $array2, $callback = null) {
+ public static function compareAssoc(array $array1, array $array2, Callback $callback = null) {
return static::compareHelper('assoc', $array1, $array2, $callback);
}
* @param callable $callback
* @return boolean
*/
- protected static function compareHelper($method, array $array1, array $array2, $callback) {
+ protected static function compareHelper($method, array $array1, array $array2, Callback $callback) {
// get function name
$function = null;
if ($method === 'value') {
$function = ($callback === null) ? 'array_diff_assoc' : 'array_diff_uassoc';
}
+ // check function name
+ if ($function === null) {
+ throw new SystemException('Unknown comparison method '.$method);
+ }
+
// get parameters
$params1 = array($array1, $array2);
$params2 = array($array2, $array1);
$params2[] = $callback;
}
- // check function name
- if ($function === null) {
- throw new SystemException('Unknown comparison method '.$method);
- }
-
- // check callback
- if (($callback !== null) && !is_callable($callback)) {
- throw new SystemException('Invalid callback specified');
- }
-
// compare the arrays
return ((count(call_user_func_array($function, $params1)) === 0) && (count(call_user_func_array($function, $params2)) === 0));
}