Connector
in package
implements
ConnectorInterface, LoggerAwareInterface
Uses
LoggerAwareTrait, ConnectorCacheTrait
Primo Central connector.
Tags
Interfaces, Classes, Traits and Enums
- ConnectorInterface
- Primo Central connector interface.
- LoggerAwareInterface
Table of Contents
- $client : Client
- HTTP client used for API transactions
- $cache : StorageInterface
- Request cache
- $emptyQueryResponse : array<string|int, mixed>
- Response for an empty search
- $highlightRegEx : string
- Regular expression to match highlighted terms
- $host : string
- Base URL for API
- $inst : string
- Institution code
- __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.
- getRecords() : array<string|int, mixed>
- Retrieves multiple documents 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() : object
- Small wrapper for sendRequest, process to simplify error handling.
- debug() : void
- Log a debug message.
- 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
- process() : array<string|int, mixed>
- Translate Primo's XML into array of arrays.
- processDescription() : string
- Fix the description field by removing tags etc.
- processHighlighting() : void
- Process highlighting tags of the record fields
- putCachedData() : void
- Cache response data.
Properties
$client
HTTP client used for API transactions
public
Client
$client
$cache
Request cache
protected
StorageInterface
$cache
= null
$emptyQueryResponse
Response for an empty search
protected
static array<string|int, mixed>
$emptyQueryResponse
= ['recordCount' => 0, 'documents' => [], 'facets' => [], 'error' => 'empty_search_disallowed']
$highlightRegEx
Regular expression to match highlighted terms
protected
string
$highlightRegEx
= '{<span[^>]*>([^<]*?)</span>}si'
$host
Base URL for API
protected
string
$host
$inst
Institution code
protected
string
$inst
Methods
__construct()
Constructor
public
__construct(string $url, string $inst, Client $client) : mixed
Sets up the Primo API Client
Parameters
- $url : string
-
Primo API URL (either a host name and port or a full path to the brief search including a trailing question mark)
- $inst : string
-
Institution code
- $client : Client
-
HTTP client
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
getRecords()
Retrieves multiple documents specified by the ID.
public
getRecords(array<string|int, mixed> $recordIds[, string|null $inst_code = null ][, bool $onCampus = false ]) : array<string|int, mixed>
Parameters
- $recordIds : array<string|int, mixed>
-
The documents 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[, array<string|int, mixed> $params = [] ][, string $method = 'GET' ][, bool $cacheable = true ]) : object
Parameters
- $qs : string
-
Query string
- $params : array<string|int, mixed> = []
-
Request parameters
- $method : string = 'GET'
-
HTTP method
- $cacheable : bool = true
-
Whether the request is cacheable
Tags
Return values
object —The parsed primo data
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 —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(string $institution, array<string|int, mixed> $terms, array<string|int, mixed> $args) : 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
- $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
process()
Translate Primo's XML into array of arrays.
protected
process(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
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) : void
Parameters
- $record : array<string|int, mixed>
-
Record data
- $params : array<string|int, mixed>
-
Request params
Return values
void —putCachedData()
Cache response data.
protected
putCachedData(string $key, mixed $response) : void
Parameters
- $key : string
-
Cache entry key
- $response : mixed
-
Response to be cached