43 if ( empty(
$params[
'url'] ) ) {
44 throw new InvalidArgumentException(
'URL parameter is required' );
47 if ( empty(
$params[
'client'] ) ) {
50 $this->client =
$params[
'client'];
53 $this->url = rtrim(
$params[
'url'],
'/' ) .
'/';
66 'url' => $this->url . rawurlencode( $key ),
69 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run(
$req );
70 if ( $rcode === 200 ) {
71 if ( is_string( $rbody ) ) {
76 if ( $rcode === 0 || ( $rcode >= 400 && $rcode != 404 ) ) {
77 return $this->
handleError(
"Failed to fetch $key", $rcode, $rerr );
90 $this->logger->error(
"$msg : ({code}) {error}", [
94 $this->
setLastError( $rcode === 0 ? self::ERR_UNREACHABLE : self::ERR_UNEXPECTED );
110 'url' => $this->url . rawurlencode( $key ),
113 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run(
$req );
114 if ( $rcode === 200 || $rcode === 201 ) {
117 return $this->
handleError(
"Failed to store $key", $rcode, $rerr );
126 public function delete( $key ) {
128 'method' =>
'DELETE',
129 'url' => $this->url . rawurlencode( $key ),
131 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run(
$req );
132 if ( $rcode === 200 || $rcode === 204 || $rcode === 205 ) {
135 return $this->
handleError(
"Failed to delete $key", $rcode, $rerr );