コード例 #1
0
ファイル: Test.php プロジェクト: giftnuss/test.php
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;
}
コード例 #2
0
ファイル: user.php プロジェクト: morovan/granitpiestany.sk
/**
  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')];
}
コード例 #3
0
ファイル: TestMore.php プロジェクト: karpet/dezi-client-php
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;
}