InlineScript
extends HeadScript
in package
Inline script view helper (extended for VuFind's theme system)
Tags
Table of Contents
- $concatIndex : number
- Future order of the concatenated file
- $cspNonce : string
- CSP nonce
- $groups : array<string|int, mixed>
- Array of resource items by type, contains key as well
- $themeInfo : ThemeInfo
- Theme information service
- $usePipeline : bool
- Should we use the asset pipeline to join files together and minify them?
- __construct() : mixed
- Constructor
- __invoke() : InlineScript
- Return InlineScript object
- forcePrependFile() : void
- Forcibly prepend a file removing it from any existing position
- getIndent() : void
- getSeparator() : void
- getType() : string
- Set the file path of the link object
- getWhitespace() : void
- itemToString() : string
- Create script HTML
- toString() : string
- Render link elements as string Customized to minify and concatenate
- addNonce() : void
- Add a content security policy nonce to the item
- createConcatenatedFile() : void
- Create a concatenated file from the given group of files
- debug() : void
- Log a debug message.
- enabledInConfig() : bool
- Check if config is enabled for this file type
- filterItems() : bool
- Initialize class properties related to concatenation of resources.
- getConcatenatedFilePath() : string
- Using the concatKey, return the path of the concatenated file.
- getFileType() : string
- Get the folder name and file extension
- getMinifiedData() : string
- Get minified data for a file
- getMinifier() : minifying
- Get the minifier that can handle these file types
- getResourceCacheDir() : string
- Get the path to the directory where we can cache files generated by this trait. The directory will be created if it does not already exist.
- getResourceFilePath() : string
- Get the file path from the element object
- isExcludedFromConcat() : bool
- Returns true if file should not be included in the compressed concat file
- isMinifiable() : bool
- Check if a file is minifiable i.e. does not have a pattern that denotes it's already minified
- isPipelineActive() : bool
- Can we use the asset pipeline?
- isRelativePath() : bool
- Is the provided src value a relative path? Returns true if this should be searched within the local theme, or false if it is an absolute path or full URL.
- log() : void
- Send a message to the logger.
- logError() : void
- Log an error message.
- logWarning() : void
- Log a warning message.
- outputInOrder() : string
- Process and return items in index order
- setResourceFilePath() : stdClass
- Set the file path of the element object
Properties
$concatIndex
Future order of the concatenated file
protected
number
$concatIndex
= null
$cspNonce
CSP nonce
protected
string
$cspNonce
$groups
Array of resource items by type, contains key as well
protected
array<string|int, mixed>
$groups
= []
$themeInfo
Theme information service
protected
ThemeInfo
$themeInfo
$usePipeline
Should we use the asset pipeline to join files together and minify them?
protected
bool
$usePipeline
= false
Methods
__construct()
Constructor
public
__construct(ThemeInfo $themeInfo[, string|bool $plconfig = false ][, string $nonce = '' ]) : mixed
Parameters
- $themeInfo : ThemeInfo
-
Theme information service
- $plconfig : string|bool = false
-
Config for current application environment
- $nonce : string = ''
-
Nonce from nonce generator
Return values
mixed —__invoke()
Return InlineScript object
public
__invoke([string $mode = HeadScript::FILE ][, string $spec = null ][, string $placement = 'APPEND' ][, array<string|int, mixed> $attrs = [] ][, string $type = 'text/javascript' ]) : InlineScript
Returns InlineScript helper object; optionally, allows specifying a script or script file to include.
Parameters
- $mode : string = HeadScript::FILE
-
Script or file
- $spec : string = null
-
Script/url
- $placement : string = 'APPEND'
-
Append, prepend, or set
- $attrs : array<string|int, mixed> = []
-
Array of script attributes
- $type : string = 'text/javascript'
-
Script type and/or array of script attributes
Return values
InlineScript —forcePrependFile()
Forcibly prepend a file removing it from any existing position
public
forcePrependFile([string $src = null ][, string $type = 'text/javascript' ][, array<string|int, mixed> $attrs = [] ]) : void
Parameters
- $src : string = null
-
Script src
- $type : string = 'text/javascript'
-
Script type
- $attrs : array<string|int, mixed> = []
-
Array of script attributes
Return values
void —getIndent()
public
getIndent() : void
Return values
void —getSeparator()
public
getSeparator() : void
Return values
void —getType()
Set the file path of the link object
public
getType(stdClass $item) : string
Parameters
- $item : stdClass
-
Link element object
Tags
Return values
string —getWhitespace()
public
getWhitespace(string|int $indent) : void
Parameters
- $indent : string|int
Return values
void —itemToString()
Create script HTML
public
itemToString(mixed $item, string $indent, string $escapeStart, string $escapeEnd) : string
Parameters
- $item : mixed
-
Item to convert
- $indent : string
-
String to add before the item
- $escapeStart : string
-
Starting sequence
- $escapeEnd : string
-
Ending sequence
Return values
string —toString()
Render link elements as string Customized to minify and concatenate
public
toString([string|int $indent = null ]) : string
Parameters
- $indent : string|int = null
-
Amount of whitespace or string to use for indentation
Return values
string —addNonce()
Add a content security policy nonce to the item
protected
addNonce(stdClass $item) : void
Parameters
- $item : stdClass
-
Item
Tags
Return values
void —createConcatenatedFile()
Create a concatenated file from the given group of files
protected
createConcatenatedFile(string $concatPath, array<string|int, mixed> $group) : void
Parameters
- $concatPath : string
-
Resulting file path
- $group : array<string|int, mixed>
-
Object containing 'key' and stdobj file 'items'
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 —enabledInConfig()
Check if config is enabled for this file type
protected
enabledInConfig(string|bool $config) : bool
Parameters
- $config : string|bool
-
Config for current application environment
Return values
bool —filterItems()
Initialize class properties related to concatenation of resources.
protected
filterItems() : bool
All of the elements to be concatenated into groups and and those that need to remain on their own special group 'other'.
Return values
bool —True if there are items
getConcatenatedFilePath()
Using the concatKey, return the path of the concatenated file.
protected
getConcatenatedFilePath(array<string|int, mixed> $group) : string
Generate if it does not yet exist.
Parameters
- $group : array<string|int, mixed>
-
Object containing 'key' and stdobj file 'items'
Return values
string —getFileType()
Get the folder name and file extension
protected
abstract getFileType() : string
Return values
string —getMinifiedData()
Get minified data for a file
protected
getMinifiedData(array<string|int, mixed> $details, string $concatPath) : string
Parameters
- $details : array<string|int, mixed>
-
File details
- $concatPath : string
-
Target path for the resulting file (used in minifier for path mapping)
Tags
Return values
string —getMinifier()
Get the minifier that can handle these file types
protected
abstract getMinifier() : minifying
Return values
minifying —object like \MatthiasMullie\Minify\JS
getResourceCacheDir()
Get the path to the directory where we can cache files generated by this trait. The directory will be created if it does not already exist.
protected
getResourceCacheDir() : string
Return values
string —getResourceFilePath()
Get the file path from the element object
protected
abstract getResourceFilePath(stdClass $item) : string
Parameters
- $item : stdClass
-
Element object
Return values
string —isExcludedFromConcat()
Returns true if file should not be included in the compressed concat file
protected
abstract isExcludedFromConcat(stdClass $item) : bool
Parameters
- $item : stdClass
-
Element object
Return values
bool —isMinifiable()
Check if a file is minifiable i.e. does not have a pattern that denotes it's already minified
protected
isMinifiable(string $filename) : bool
Parameters
- $filename : string
-
File name
Return values
bool —isPipelineActive()
Can we use the asset pipeline?
protected
isPipelineActive() : bool
Return values
bool —isRelativePath()
Is the provided src value a relative path? Returns true if this should be searched within the local theme, or false if it is an absolute path or full URL.
protected
isRelativePath(string $src) : bool
Parameters
- $src : string
-
Value to check
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 —outputInOrder()
Process and return items in index order
protected
outputInOrder(string|int $indent) : string
Parameters
- $indent : string|int
-
Amount of whitespace/string to use for indentation
Return values
string —setResourceFilePath()
Set the file path of the element object
protected
abstract setResourceFilePath(stdClass $item, string $path) : stdClass
Parameters
- $item : stdClass
-
Element object
- $path : string
-
New path string