function _cmp_deeply($have, $exp, $path = '') { if (is_array($exp)) { if (!is_array($have)) { return _diff($path, _repl($have), $path, _repl($exp)); } $gk = array_keys($have); $ek = array_keys($exp); $mc = max(count($gk), count($ek)); for ($el = 0; $el < $mc; $el++) { # One array shorter than the other? if ($el >= count($ek)) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), 'missing', 'nothing'); } else { if ($el >= count($gk)) { return _diff('missing', 'nothing', _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } } # Keys differ? if ($gk[$el] != $ek[$el]) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } # Recurse $rc = _cmp_deeply($have[$gk[$el]], $exp[$ek[$el]], _idx($gk[$el], $path)); if (!is_null($rc)) { return $rc; } } } elseif (is_numeric($have) && is_numeric($exp)) { // why trim - good question, but it helps? if (0 + trim($have) !== 0 + trim($exp)) { return _diff($path, _repl($have), $path, _repl($exp)); } } else { # Default to serialize hack if (serialize($have) != serialize($exp)) { return _diff($path, _repl($have), $path, _repl($exp)); } } return null; }
/** this function returns the permission values of the user with the given user name. if the user is not found in the user database, this function returns NULL, otherwise, it returns the permissions of the user. */ function user_get_permissions($username) { // try to find the user in the user database $data = user_find($username, NULL); // return NULL if the user does not exists if (!isset($data)) { return; } // return the user permissions return $data[_idx('permissions')]; }
function _cmp_deeply($have, $exp, $path = '') { if (is_array($exp)) { //diag("using recursive cmp in is_deeply"); if (!is_array($have)) { return _diff($path, _repl($have), $path, _repl($exp)); } $gk = array_keys($have); $ek = array_keys($exp); $mc = max(count($gk), count($ek)); for ($el = 0; $el < $mc; $el++) { # One array shorter than the other? if ($el >= count($ek)) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), 'missing', 'nothing'); } else { if ($el >= count($gk)) { return _diff('missing', 'nothing', _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } } # Keys differ? if ($gk[$el] != $ek[$el]) { return _diff(_idx($gk[$el], $path), _repl($have[$gk[$el]]), _idx($ek[$el], $path), _repl($exp[$ek[$el]])); } # Recurse $rc = _cmp_deeply($have[$gk[$el]], $exp[$ek[$el]], _idx($gk[$el], $path)); if (!is_null($rc)) { return $rc; } } } else { # Default to serialize hack //diag("using serialize() in is_deeply"); if (serialize($have) != serialize($exp)) { return _diff($path, _repl($have), $path, _repl($exp)); } } return null; }