3use Psr\Log\LoggerInterface;
56 if ( empty(
$params[
'url'] ) ) {
57 throw new InvalidArgumentException(
'URL parameter is required' );
59 if ( empty(
$params[
'client'] ) ) {
65 foreach ( [
'caBundlePath',
'proxy' ] as $key ) {
67 $clientParams[$key] =
$params[$key];
72 $this->client =
$params[
'client'];
77 $this->url = rtrim(
$params[
'url'],
'/' ) .
'/';
84 $this->client->setLogger(
$logger );
92 protected function doGet( $key, $flags = 0 ) {
95 'url' => $this->url . rawurlencode( $key ),
98 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run(
$req );
99 if ( $rcode === 200 ) {
100 if ( is_string( $rbody ) ) {
105 if ( $rcode === 0 || ( $rcode >= 400 && $rcode != 404 ) ) {
106 return $this->
handleError(
"Failed to fetch $key", $rcode, $rerr );
119 $this->logger->error(
"$msg : ({code}) {error}", [
136 public function set( $key,
$value, $exptime = 0, $flags = 0 ) {
139 'url' => $this->url . rawurlencode( $key ),
142 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run(
$req );
143 if ( $rcode === 200 || $rcode === 201 || $rcode === 204 ) {
146 return $this->
handleError(
"Failed to store $key", $rcode, $rerr );
155 public function delete( $key ) {
157 'method' =>
'DELETE',
158 'url' => $this->url . rawurlencode( $key ),
160 list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->client->run(
$req );
161 if ( in_array( $rcode, [ 200, 204, 205, 404, 410 ] ) ) {
164 return $this->
handleError(
"Failed to delete $key", $rcode, $rerr );
unserialize( $serialized)
Class representing a cache/ephemeral data store.
setLastError( $err)
Set the "last error" registry.
Class to handle multiple HTTP requests.
Interface to key-value storage behind an HTTP server.
setLogger(LoggerInterface $logger)
const DEFAULT_CONN_TIMEOUT
Default connection timeout in seconds.
const DEFAULT_REQ_TIMEOUT
Default request timeout.
handleError( $msg, $rcode, $rerr)
Handle storage error.
string $url
REST URL to use for storage.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
this hook is for auditing only $req