Loader
extends ImageLoader
in package
Book Cover Generator
Tags
Table of Contents
- $allowedFileExtensions : array<string|int, mixed>
- Array containing map of allowed file extensions to mimetypes (to be extended)
- $apiManager : PluginManager
- Plugin manager for API handlers
- $baseDir : string
- Directory to store downloaded images
- $config : Config
- VuFind configuration settings
- $configuredFailImage : string
- User-configured image to load from theme on error.
- $contentType : string
- Content type of data in $image property
- $defaultFailImage : string
- Default image to load from theme if user-configured option fails.
- $generator : Generator
- Class for rendering cover images dynamically if no API match found. Omit to disable functionality.
- $hasLoadedUnavailable : bool
- Flag denoting the last loaded image was a FailImage
- $httpService : HttpService
- HTTP client factory
- $image : string
- Property for storing raw image data; may be null if image is unavailable
- $isbns : array<string|int, ISBN>
- User ISBNs parameter
- $ismn : ISMN
- User ISMN parameter
- $issn : string
- User ISSN parameter
- $localFile : string
- Filename constructed from ISBN
- $nbn : array<string|int, mixed>
- User National bibliography number parameter
- $oclc : string
- User OCLC number parameter
- $recordid : string
- User record id number parameter
- $size : string
- User size parameter
- $source : string
- User record source parameter
- $themeTools : ThemeInfo
- Theme tools
- $type : string
- User type parameter
- $upc : string
- User UPC number parameter
- $uuid : string
- User UUID parameter
- $validSizes : array<string|int, mixed>
- Valid image sizes to request
- __construct() : mixed
- Constructor
- getContentType() : string
- Get the content type of the current image (not meant to be called until after contentType is populated)
- getHandlers() : Generator
- Return API handlers
- getIdentifiersForSettings() : array<string|int, mixed>
- Get identifiers for given settings
- getImage() : string
- Get the image data (not meant to be called until after image is populated)
- hasLoadedUnavailable() : bool
- Returns true if the last loaded image was the FailImage
- loadImage() : void
- Load an image given an ISBN and/or content type.
- loadUnavailable() : void
- {@inheritdoc} Adds @see self::$hasLoadedUnavailable flag
- setCoverGenerator() : void
- Set Cover Generator Object
- setThemeInfo() : void
- Setter for dependency
- convertNonJpeg() : bool
- Support method for validateAndMoveTempFile -- convert non-JPEG image data to a JPEG file.
- debug() : void
- Log a debug message.
- determineLocalFile() : string
- Support method for fetchFromAPI() -- set the localFile property.
- fetchFromAPI() : bool
- Load bookcover from cache or remote provider and display if possible.
- fetchFromContentType() : bool
- Load content type icon image from URL from theme images and display if possible.
- getCachePath() : string
- Return a path to the image cache for the given size and ID; ensure that directories are created as needed.
- getContentTypeFromExtension() : string
- Get the content-type for a file based on extension. Throw an exception if an illegal extension is provided.
- getCoverGeneratorSettings() : array<string|int, mixed>
- Get settings for the cover generator.
- getCoverUrls() : array<string|int, mixed>
- Get urls for defined provider, works as generator
- getDefaultSettings() : array<string|int, mixed>
- Get default settings for loadImage().
- getIdentifiers() : array<string|int, mixed>
- Get all valid identifiers as an associative array.
- getImageSettingsFromLegacyArgs() : array<string|int, mixed>
- Translate legacy function arguments into new-style array.
- loadDefaultFailImage() : void
- Display the default "cover unavailable" graphic.
- log() : void
- Send a message to the logger.
- logError() : void
- Log an error message.
- logWarning() : void
- Log a warning message.
- processImageURL() : bool
- Load image from URL, store in cache if requested, display if possible.
- processImageURLForSource() : bool
- Wrapper around processImageURL to determine cache setting based on image source.
- searchTheme() : string|bool
- Find a file in the themes (return false if no file exists).
- storeSanitizedSettings() : void
- Support method for loadImage() -- sanitize and store some key values.
- validateAndMoveTempFile() : bool
- This method either moves the temporary file to its final location (true) or detects an error and deletes it (false).
Properties
$allowedFileExtensions
Array containing map of allowed file extensions to mimetypes (to be extended)
protected
array<string|int, mixed>
$allowedFileExtensions
= ['gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff']
$apiManager
Plugin manager for API handlers
protected
PluginManager
$apiManager
$baseDir
Directory to store downloaded images
protected
string
$baseDir
$config
VuFind configuration settings
protected
Config
$config
$configuredFailImage
User-configured image to load from theme on error.
protected
string
$configuredFailImage
= null
$contentType
Content type of data in $image property
protected
string
$contentType
= null
$defaultFailImage
Default image to load from theme if user-configured option fails.
protected
string
$defaultFailImage
= 'images/noCover2.gif'
$generator
Class for rendering cover images dynamically if no API match found. Omit to disable functionality.
protected
Generator
$generator
= null
$hasLoadedUnavailable
Flag denoting the last loaded image was a FailImage
protected
bool
$hasLoadedUnavailable
= false
$httpService
HTTP client factory
protected
HttpService
$httpService
$image
Property for storing raw image data; may be null if image is unavailable
protected
string
$image
= null
$isbns
User ISBNs parameter
protected
array<string|int, ISBN>
$isbns
= null
$ismn
User ISMN parameter
protected
ISMN
$ismn
= null
$issn
User ISSN parameter
protected
string
$issn
= null
$localFile
Filename constructed from ISBN
protected
string
$localFile
= ''
$nbn
User National bibliography number parameter
protected
array<string|int, mixed>
$nbn
= null
$oclc
User OCLC number parameter
protected
string
$oclc
= null
$recordid
User record id number parameter
protected
string
$recordid
= null
$size
User size parameter
protected
string
$size
$source
User record source parameter
protected
string
$source
= null
$themeTools
Theme tools
protected
ThemeInfo
$themeTools
= null
$type
User type parameter
protected
string
$type
$upc
User UPC number parameter
protected
string
$upc
= null
$uuid
User UUID parameter
protected
string
$uuid
= null
$validSizes
Valid image sizes to request
protected
array<string|int, mixed>
$validSizes
= ['small', 'medium', 'large']
Methods
__construct()
Constructor
public
__construct(Config $config, PluginManager $manager, ThemeInfo $theme, HttpService $httpService[, string $baseDir = null ]) : mixed
Parameters
- $config : Config
-
VuFind configuration
- $manager : PluginManager
-
Plugin manager for API handlers
- $theme : ThemeInfo
-
VuFind theme tools
- $httpService : HttpService
-
HTTP client factory
- $baseDir : string = null
-
Directory to store downloaded images (set to system temp dir if not otherwise specified)
Return values
mixed —getContentType()
Get the content type of the current image (not meant to be called until after contentType is populated)
public
getContentType() : string
Return values
string —getHandlers()
Return API handlers
public
getHandlers() : Generator
Return values
Generator —Array with keys: key - API key, apiName - api name from configuration, handler - handler object
getIdentifiersForSettings()
Get identifiers for given settings
public
getIdentifiersForSettings(array<string|int, mixed> $settings) : array<string|int, mixed>
Parameters
- $settings : array<string|int, mixed>
-
Settings from loadImage
Return values
array<string|int, mixed> —getImage()
Get the image data (not meant to be called until after image is populated)
public
getImage() : string
Return values
string —hasLoadedUnavailable()
Returns true if the last loaded image was the FailImage
public
hasLoadedUnavailable() : bool
Return values
bool —loadImage()
Load an image given an ISBN and/or content type.
public
loadImage([array<string|int, mixed> $settings = [] ]) : void
Parameters
- $settings : array<string|int, mixed> = []
-
Array of settings used to calculate a cover; may contain any or all of these keys: 'isbns' (array of ISBNs), 'size' (requested size), 'type' (content type), 'title' (title of book, for dynamic covers), 'author' (author of book, for dynamic covers), 'callnumber' (unique ID, for dynamic covers), 'issn' (ISSN), 'oclc' (OCLC number), 'upc' (UPC number), 'nbn' (national bibliography number), 'ismn' (ISMN), 'uuid' (Universally unique identifier).
Return values
void —loadUnavailable()
{@inheritdoc} Adds @see self::$hasLoadedUnavailable flag
public
loadUnavailable() : void
Return values
void —setCoverGenerator()
Set Cover Generator Object
public
setCoverGenerator(Generator $generator) : void
Parameters
- $generator : Generator
-
Cover generator
Return values
void —setThemeInfo()
Setter for dependency
public
setThemeInfo(ThemeInfo $theme) : void
Parameters
- $theme : ThemeInfo
-
VuFind theme tools
Return values
void —convertNonJpeg()
Support method for validateAndMoveTempFile -- convert non-JPEG image data to a JPEG file.
protected
convertNonJpeg(string $imageData, string $jpeg) : bool
Parameters
- $imageData : string
-
Raw image data
- $jpeg : string
-
JPEG file (output)
Return values
bool —Did we succeed?
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 —determineLocalFile()
Support method for fetchFromAPI() -- set the localFile property.
protected
determineLocalFile(array<string|int, mixed> $ids) : string
Parameters
- $ids : array<string|int, mixed>
-
IDs returned by getIdentifiers() method
Return values
string —fetchFromAPI()
Load bookcover from cache or remote provider and display if possible.
protected
fetchFromAPI() : bool
Return values
bool —True if image loaded, false on failure.
fetchFromContentType()
Load content type icon image from URL from theme images and display if possible.
protected
fetchFromContentType() : bool
Return values
bool —True if image loaded, false on failure.
getCachePath()
Return a path to the image cache for the given size and ID; ensure that directories are created as needed.
protected
getCachePath(string $size, string $id[, string $extension = 'jpg' ]) : string
Parameters
- $size : string
-
Size category
- $id : string
-
Unique identifier (ISBN / ISSN)
- $extension : string = 'jpg'
-
File extension to use (default = jpg)
Return values
string —Cache path
getContentTypeFromExtension()
Get the content-type for a file based on extension. Throw an exception if an illegal extension is provided.
protected
getContentTypeFromExtension(string $filename) : string
Parameters
- $filename : string
-
Filename to analyze.
Tags
Return values
string —getCoverGeneratorSettings()
Get settings for the cover generator.
protected
getCoverGeneratorSettings() : array<string|int, mixed>
Return values
array<string|int, mixed> —getCoverUrls()
Get urls for defined provider, works as generator
protected
getCoverUrls() : array<string|int, mixed>
Return values
array<string|int, mixed> —getDefaultSettings()
Get default settings for loadImage().
protected
getDefaultSettings() : array<string|int, mixed>
Return values
array<string|int, mixed> —getIdentifiers()
Get all valid identifiers as an associative array.
protected
getIdentifiers() : array<string|int, mixed>
Return values
array<string|int, mixed> —getImageSettingsFromLegacyArgs()
Translate legacy function arguments into new-style array.
protected
getImageSettingsFromLegacyArgs(array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
- $args : array<string|int, mixed>
-
Function arguments
Return values
array<string|int, mixed> —loadDefaultFailImage()
Display the default "cover unavailable" graphic.
protected
loadDefaultFailImage() : void
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 —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 —processImageURL()
Load image from URL, store in cache if requested, display if possible.
protected
processImageURL(string $url[, string $cache = true ]) : bool
Parameters
- $url : string
-
URL to load image from
- $cache : string = true
-
Boolean -- should we store in local cache?
Return values
bool —True if image loaded, false on failure.
processImageURLForSource()
Wrapper around processImageURL to determine cache setting based on image source.
protected
processImageURLForSource(string $url, bool $allowCache, string $source) : bool
Parameters
- $url : string
-
URL to load image from
- $allowCache : bool
-
Is caching allowed by the service?
- $source : string
-
Service being used for image loading
Return values
bool —True if image loaded, false on failure.
searchTheme()
Find a file in the themes (return false if no file exists).
protected
searchTheme(string $path[, array<string|int, mixed> $formats = [''] ]) : string|bool
Parameters
- $path : string
-
Relative path of file to find.
- $formats : array<string|int, mixed> = ['']
-
Optional array of suffixes to add to $path while searching theme (used to check multiple extensions in each theme).
Return values
string|bool —storeSanitizedSettings()
Support method for loadImage() -- sanitize and store some key values.
protected
storeSanitizedSettings(array<string|int, mixed> $settings) : void
Parameters
- $settings : array<string|int, mixed>
-
Settings from loadImage
Return values
void —validateAndMoveTempFile()
This method either moves the temporary file to its final location (true) or detects an error and deletes it (false).
protected
validateAndMoveTempFile(string $image, string $tempFile, string $finalFile) : bool
Parameters
- $image : string
-
Raw image data
- $tempFile : string
-
Temporary file
- $finalFile : string
-
Final file location