RestConnector
in package
implements
ConnectorInterface, LoggerAwareInterface
Uses
LoggerAwareTrait, ConnectorCacheTrait
Primo Central connector (REST API).
Tags
Interfaces, Classes, Traits and Enums
- ConnectorInterface
- Primo Central connector interface.
- LoggerAwareInterface
Table of Contents
- $cache : StorageInterface
- Request cache
- $clientFactory : callable
- HTTP client factory
- $emptyQueryResponse : array<string|int, mixed>
- Response for an empty search
- $indexMappings : array<string|int, mixed>
- Mappings from VuFind index names to Primo
- $inst : string
- Institution code
- $jwtUrl : string
- Primo JWT API URL
- $searchUrl : string
- Primo REST API search URL
- $session : Container
- Session container
- $sortMappings : array<string|int, mixed>
- Legacy sort mappings
- __construct() : mixed
- Constructor
- getCachedData() : mixed
- Get a request from cache if available
- getCacheKey() : string
- Create a cache key from client's request state
- getInstitutionCode() : string
- Get the institution code based on user IP. If user is coming from off campus return
- getRecord() : array<string|int, mixed>
- Retrieves a document specified by the ID.
- query() : array<string|int, mixed>
- Execute a search. Adds all the querystring parameters into $this->client and returns the parsed response
- setCache() : void
- Set the cache storage
- call() : string
- Small wrapper for sendRequest, process to simplify error handling.
- debug() : void
- Log a debug message.
- getJWT() : string
- Get a JWT token for the session
- getUrl() : string
- Build a URL from a configured one
- log() : void
- Send a message to the logger.
- logCacheDebug() : void
- Log a debug message
- logCacheWarning() : void
- Log a warning message
- logError() : void
- Log an error message.
- logWarning() : void
- Log a warning message.
- performSearch() : array<string|int, mixed>
- Support method for query() -- perform inner search logic
- processDescription() : string
- Fix the description field by removing tags etc.
- processHighlighting() : void
- Process highlighting tags of the record fields
- processResponse() : array<string|int, mixed>
- Translate Primo's JSON into array of arrays.
- putCachedData() : void
- Cache response data.
Properties
$cache
Request cache
protected
StorageInterface
$cache
= null
$clientFactory
HTTP client factory
protected
callable
$clientFactory
$emptyQueryResponse
Response for an empty search
protected
static array<string|int, mixed>
$emptyQueryResponse
= ['recordCount' => 0, 'documents' => [], 'facets' => [], 'error' => 'empty_search_disallowed']
$indexMappings
Mappings from VuFind index names to Primo
protected
array<string|int, mixed>
$indexMappings
= ['AllFields' => 'any', 'Title' => 'title', 'Author' => 'creator', 'Subject' => 'sub', 'Abstract' => 'desc', 'ISSN' => 'issn']
$inst
Institution code
protected
string
$inst
$jwtUrl
Primo JWT API URL
protected
string
$jwtUrl
$searchUrl
Primo REST API search URL
protected
string
$searchUrl
$session
Session container
protected
Container
$session
$sortMappings
Legacy sort mappings
protected
array<string|int, mixed>
$sortMappings
= ['scdate' => 'date', 'screator' => 'author', 'stitle' => 'title']
Methods
__construct()
Constructor
public
__construct(string $jwtUrl, string $searchUrl, string $instCode, callable $clientFactory, Container $session) : mixed
Sets up the Primo API Client
Parameters
- $jwtUrl : string
-
Primo JWT API URL
- $searchUrl : string
-
Primo REST API search URL
- $instCode : string
-
Institution code (used as view ID, i.e. the vid parameter unless specified in the URL)
- $clientFactory : callable
-
HTTP client factory
- $session : Container
-
Session container
Return values
mixed —getCachedData()
Get a request from cache if available
public
getCachedData(string $key) : mixed
Parameters
- $key : string
-
Cache key
Return values
mixed —getCacheKey()
Create a cache key from client's request state
public
getCacheKey(Client $client) : string
Parameters
- $client : Client
-
HTTP Client
Return values
string —getInstitutionCode()
Get the institution code based on user IP. If user is coming from off campus return
public
getInstitutionCode() : string
Return values
string —getRecord()
Retrieves a document specified by the ID.
public
getRecord(string $recordId[, string|null $inst_code = null ][, bool $onCampus = false ]) : array<string|int, mixed>
Parameters
- $recordId : string
-
The document to retrieve from the Primo API
- $inst_code : string|null = null
-
Institution code (optional)
- $onCampus : bool = false
-
Whether the user is on campus
Tags
Return values
array<string|int, mixed> —An array of query results
query()
Execute a search. Adds all the querystring parameters into $this->client and returns the parsed response
public
query(string $institution, array<string|int, mixed> $terms[, array<string|int, mixed> $params = null ]) : array<string|int, mixed>
Parameters
- $institution : string
-
Institution
- $terms : array<string|int, mixed>
-
Associative array: index string: primo index to search (default "any") lookfor string: actual search terms
- $params : array<string|int, mixed> = null
-
Associative array of optional arguments: phrase bool: true if it's a quoted phrase (default false) onCampus bool: (default true) didyoumean bool: (default false) filterList array: (field, value) pairs to filter results (def null) pageNumber string: index of first record (default 1) limit string: number of records to return (default 20) sort string: value to be used by for sorting (default null) highlight bool: whether to highlight search term matches in records highlightStart string: Prefix for a highlighted term highlightEnd string: Suffix for a Highlighted term Anything in $params not listed here will be ignored.
Note: some input parameters accepted by Primo are not implemented here:
- dym (did you mean)
- more (get more)
- lang (specify input language so engine can do lang. recognition)
- displayField (has to do with highlighting somehow)
Tags
Return values
array<string|int, mixed> —An array of query results
setCache()
Set the cache storage
public
setCache(StorageInterface $cache) : void
Parameters
- $cache : StorageInterface
-
Cache
Return values
void —call()
Small wrapper for sendRequest, process to simplify error handling.
protected
call(string $qs) : string
Parameters
- $qs : string
-
Query string
Tags
Return values
string —Result body
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 —getJWT()
Get a JWT token for the session
protected
getJWT([bool $renew = false ]) : string
Parameters
- $renew : bool = false
-
Whether to renew the token
Return values
string —getUrl()
Build a URL from a configured one
protected
getUrl(string $url) : string
Parameters
- $url : string
-
URL
Return values
string —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 —logCacheDebug()
Log a debug message
protected
logCacheDebug(string $msg) : void
Parameters
- $msg : string
-
Message
Return values
void —logCacheWarning()
Log a warning message
protected
logCacheWarning(string $msg) : void
Parameters
- $msg : string
-
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 —performSearch()
Support method for query() -- perform inner search logic
protected
performSearch(array<string|int, mixed> $terms, array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
- $terms : array<string|int, mixed>
-
Associative array: index string: primo index to search (default "any") lookfor string: actual search terms
- $args : array<string|int, mixed>
-
Associative array of optional arguments (see query method for more information)
Tags
Return values
array<string|int, mixed> —An array of query results
processDescription()
Fix the description field by removing tags etc.
protected
processDescription(string $description) : string
Parameters
- $description : string
-
Description
Return values
string —processHighlighting()
Process highlighting tags of the record fields
protected
processHighlighting(array<string|int, mixed> &$record, array<string|int, mixed> $params, StdClass $highlight) : void
Parameters
- $record : array<string|int, mixed>
-
Record data
- $params : array<string|int, mixed>
-
Request params
- $highlight : StdClass
-
Highlighting data
Return values
void —processResponse()
Translate Primo's JSON into array of arrays.
protected
processResponse(string $data[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>
Parameters
- $data : string
-
The raw xml from Primo
- $params : array<string|int, mixed> = []
-
Request parameters
Return values
array<string|int, mixed> —The processed response from Primo
putCachedData()
Cache response data.
protected
putCachedData(string $key, mixed $response) : void
Parameters
- $key : string
-
Cache entry key
- $response : mixed
-
Response to be cached