AbstractAPI
extends AbstractBase
in package
implements
HttpServiceAwareInterface, LoggerAwareInterface
Uses
LoggerAwareTrait, HttpServiceAwareTrait
Abstract Driver for API-based ILS drivers
Tags
Interfaces, Classes, Traits and Enums
- HttpServiceAwareInterface
- LoggerAwareInterface
Table of Contents
- $config : array<string|int, mixed>
- Driver configuration
- makeRequest() : Response
- Make requests
- setConfig() : void
- Set the configuration for the driver.
- debug() : void
- Log a debug message.
- debugRequest() : void
- Function that obscures and logs debug data
- failureCodeIsAllowed() : bool
- Does $code match the setting for allowed failure codes?
- log() : void
- Send a message to the logger.
- logError() : void
- Log an error message.
- logWarning() : void
- Log a warning message.
- preRequest() : array<string|int, mixed>
- Allow default corrections to all requests
- shouldRetryAfterUnexpectedStatusCode() : bool
- Support method for makeRequest to process an unexpected status code. Can return true to trigger a retry of the API call or false to throw an exception.
- throwAsIlsException() : never
- Rethrow the provided exception as an ILS exception.
Properties
$config
Driver configuration
protected
array<string|int, mixed>
$config
= []
Methods
makeRequest()
Make requests
public
makeRequest([string $method = 'GET' ][, string $path = '/' ][, string|array<string|int, mixed> $params = [] ][, array<string|int, mixed> $headers = [] ][, true|array<string|int, int>|string $allowedFailureCodes = [] ][, string|array<string|int, mixed> $debugParams = null ][, int $attemptNumber = 1 ]) : Response
Parameters
- $method : string = 'GET'
-
GET/POST/PUT/DELETE/etc
- $path : string = '/'
-
API path (with a leading /)
- $params : string|array<string|int, mixed> = []
-
Query parameters
- $headers : array<string|int, mixed> = []
-
Additional headers
- $allowedFailureCodes : true|array<string|int, int>|string = []
-
HTTP failure codes that should NOT cause an ILSException to be thrown. May be an array of integers, a regular expression, or boolean true to allow all codes.
- $debugParams : string|array<string|int, mixed> = null
-
Value to use in place of $params in debug messages (useful for concealing sensitive data, etc.)
- $attemptNumber : int = 1
-
Counter to keep track of attempts (starts at 1 for the first attempt)
Tags
Return values
Response —setConfig()
Set the configuration for the driver.
public
setConfig(array<string|int, mixed> $config) : void
Parameters
- $config : array<string|int, mixed>
-
Configuration array (usually loaded from a VuFind .ini file whose name corresponds with the driver class name).
Tags
Return values
void —debug()
Log a debug message.
protected
debug(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
- $msg : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = true
-
Prepend class name to message?
Return values
void —debugRequest()
Function that obscures and logs debug data
protected
debugRequest(string $method, string $path, array<string|int, mixed> $params, Headers $req_headers) : void
Parameters
- $method : string
-
Request method (GET/POST/PUT/DELETE/etc.)
- $path : string
-
Request URL
- $params : array<string|int, mixed>
-
Request parameters
- $req_headers : Headers
-
Headers object
Return values
void —failureCodeIsAllowed()
Does $code match the setting for allowed failure codes?
protected
failureCodeIsAllowed(int $code, true|array<string|int, int>|string $allowedFailureCodes) : bool
Parameters
- $code : int
-
Code to check.
- $allowedFailureCodes : true|array<string|int, int>|string
-
HTTP failure codes that should NOT cause an ILSException to be thrown. May be an array of integers, a regular expression, or boolean true to allow all codes.
Return values
bool —log()
Send a message to the logger.
protected
log(string $level, string $message[, array<string|int, mixed> $context = [] ][, bool $prependClass = false ]) : void
Parameters
- $level : string
-
Log level
- $message : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = false
-
Prepend class name to message?
Return values
void —logError()
Log an error message.
protected
logError(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
- $msg : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = true
-
Prepend class name to message?
Return values
void —logWarning()
Log a warning message.
protected
logWarning(string $msg[, array<string|int, mixed> $context = [] ][, bool $prependClass = true ]) : void
Parameters
- $msg : string
-
Log message
- $context : array<string|int, mixed> = []
-
Log context
- $prependClass : bool = true
-
Prepend class name to message?
Return values
void —preRequest()
Allow default corrections to all requests
protected
preRequest(Headers $headers, array<string|int, mixed> $params) : array<string|int, mixed>
Parameters
- $headers : Headers
-
the request headers
- $params : array<string|int, mixed>
-
the parameters object
Return values
array<string|int, mixed> —shouldRetryAfterUnexpectedStatusCode()
Support method for makeRequest to process an unexpected status code. Can return true to trigger a retry of the API call or false to throw an exception.
protected
shouldRetryAfterUnexpectedStatusCode(Response $response, int $attemptNumber) : bool
Parameters
- $response : Response
-
HTTP response
- $attemptNumber : int
-
Counter to keep track of attempts (starts at 1 for the first attempt)
Tags
Return values
bool —throwAsIlsException()
Rethrow the provided exception as an ILS exception.
protected
throwAsIlsException(Throwable $exception[, string $msg = null ]) : never
Parameters
- $exception : Throwable
-
Exception to rethrow
- $msg : string = null
-
Override exception message (optional)