src/acdhOeaw/fedora/acl/CheckAcess.php
static public function check(FedoraResource $res): bool {
        if (self::$client === null) {
            self::$client = new Client([
                'verify'  => false,
            ]);
        }

        $headers = [];
        if (isset($_SERVER['PHP_AUTH_USER'])) {
            $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']);
        }
        $cookies = [];
        foreach ($_COOKIE as $k => $v) {
            $cookies[] = $k . '=' . $v;
        }
        if (count($cookies) > 0) {
            $headers['Cookie'] = implode('; ', $cookies);
        }

        $req = new Request('GET', $res->getUri() . '/fcr:metadata', $headers);
        try {
            $resp = self::$client->send($req);
            return true;
        } catch (RequestException $ex) {
            if ($ex->hasResponse()) {
                $resp = $ex->getResponse();
                if (in_array($resp->getStatusCode(), [401, 403])) {
                    return false;
                }
            }
            throw $ex;
        }
    }
static public function check(FedoraResource $res): bool {
        if (self::$client === null) {
            self::$client = new Client([
                'verify'  => false,
            ]);
        }

        $headers = [];
        if (isset($_SERVER['PHP_AUTH_USER'])) {
            $headers['Authorization'] = 'Basic ' . base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']);
        }
        $cookies = [];
        foreach ($_COOKIE as $k => $v) {
            $cookies[] = $k . '=' . $v;
        }
        if (count($cookies) > 0) {
            $headers['Cookie'] = implode('; ', $cookies);
        }

        $req = new Request('GET', $res->getUri() . '/fcr:metadata', $headers);
        try {
            $resp = self::$client->send($req);
            return true;
        } catch (RequestException $ex) {
            if ($ex->hasResponse()) {
                $resp = $ex->getResponse();
                if (in_array($resp->getStatusCode(), [401, 403])) {
                    return false;
                }
            }
            throw $ex;
        }
    }
static public function check ( FedoraResource $ res ) : bool { if ( self :: $ client === null ) { self :: $ client = new Client ( [ 'verify' => false , ] ) ; } $ headers = [ ] ; if ( isset ( $ _SERVER [ 'PHP_AUTH_USER' ] ) ) { $ headers [ 'Authorization' ] = 'Basic ' . base64_encode ( $ _SERVER [ 'PHP_AUTH_USER' ] . ':' . $ _SERVER [ 'PHP_AUTH_PW' ] ) ; } $ cookies = [ ] ; foreach ( $ _COOKIE as $ k => $ v ) { $ cookies [ ] = $ k . '=' . $ v ; } if ( count ( $ cookies ) > 0 ) { $ headers [ 'Cookie' ] = implode ( '; ' , $ cookies ) ; } $ req = new Request ( 'GET' , $ res -> getUri ( ) . '/fcr:metadata' , $ headers ) ; try { $ resp = self :: $ client -> send ( $ req ) ; return true ; } catch ( RequestException $ ex ) { if ( $ ex -> hasResponse ( ) ) { $ resp = $ ex -> getResponse ( ) ; if ( in_array ( $ resp -> getStatusCode ( ) , [ 401 , 403 ] ) ) { return false ; } } throw $ ex ; } }
Checks if a given resource is accessible with same credentials as ones
provided in the current request.
@param FedoraResource $res
@return bool
@throws RequestException
Checks if a given resource is accessible with same credentials as ones provided in the current request .