AssetCollector implements SingletonInterface
The Asset Collector is responsible for keeping track of - everything within <script> tags: javascript files and inline javascript code - inline CSS and CSS files
The goal of the asset collector is to:
- utilize a single "runtime-based" store for adding assets of certain kinds that are added to the output
- allow to deal with assets from non-cacheable plugins and cacheable content in the Frontend
- reduce the "power" and flexibility (I'd say it's a burden) of the "god class" PageRenderer.
- reduce the burden of storing everything in PageRenderer
As a side effect this allows to:
- Add a single CSS snippet or CSS file per content block, but assure that the CSS is only added once to the output.
Note on the implementation:
- We use a Singleton to make use of the AssetCollector throughout Frontend process (similar to PageRenderer).
- Although this is not optimal, I don't see any other way to do so in the current code.
Table of Contents
Interfaces
- SingletonInterface
- "empty" interface for singletons (marker interface pattern)
Properties
- $inlineJavaScripts : array<string|int, mixed>
- $inlineStyleSheets : array<string|int, mixed>
- $javaScripts : array<string|int, mixed>
- $media : array<string|int, mixed>
- $styleSheets : array<string|int, mixed>
Methods
- addInlineJavaScript() : self
- addInlineStyleSheet() : self
- addJavaScript() : self
- addMedia() : self
- addStyleSheet() : self
- getInlineJavaScripts() : array<string|int, mixed>
- getInlineStyleSheets() : array<string|int, mixed>
- getJavaScripts() : array<string|int, mixed>
- getMedia() : array<string|int, mixed>
- getState() : array<string|int, mixed>
- getStyleSheets() : array<string|int, mixed>
- hasInlineJavaScript() : bool
- hasInlineStyleSheet() : bool
- hasJavaScript() : bool
- hasMedia() : bool
- hasStyleSheet() : bool
- removeInlineJavaScript() : self
- removeInlineStyleSheet() : self
- removeJavaScript() : self
- removeMedia() : self
- removeStyleSheet() : self
- updateState() : void
- filterAssetsPriority() : array<string|int, mixed>
Properties
$inlineJavaScripts
protected
array<string|int, mixed>
$inlineJavaScripts
= []
$inlineStyleSheets
protected
array<string|int, mixed>
$inlineStyleSheets
= []
$javaScripts
protected
array<string|int, mixed>
$javaScripts
= []
$media
protected
array<string|int, mixed>
$media
= []
$styleSheets
protected
array<string|int, mixed>
$styleSheets
= []
Methods
addInlineJavaScript()
public
addInlineJavaScript(string $identifier, string $source[, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
JavaScript code
- $attributes : array<string|int, mixed> = []
-
additional HTML <script> tag attributes
- $options : array<string|int, mixed> = []
-
['priority' => true] means rendering before other tags
Return values
selfaddInlineStyleSheet()
public
addInlineStyleSheet(string $identifier, string $source[, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
stylesheet code
- $attributes : array<string|int, mixed> = []
-
additional HTML tag attributes
- $options : array<string|int, mixed> = []
-
['priority' => true] means rendering before other tags
Return values
selfaddJavaScript()
public
addJavaScript(string $identifier, string $source[, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
URI to JavaScript file (allows EXT: syntax)
- $attributes : array<string|int, mixed> = []
-
additional HTML <script> tag attributes
- $options : array<string|int, mixed> = []
-
['priority' => true] means rendering before other tags
Return values
selfaddMedia()
public
addMedia(string $fileName, array<string|int, mixed> $additionalInformation) : self
Parameters
- $fileName : string
- $additionalInformation : array<string|int, mixed>
-
One dimensional hash map (array with non-numerical keys) with scalar values
Return values
selfaddStyleSheet()
public
addStyleSheet(string $identifier, string $source[, array<string|int, mixed> $attributes = [] ][, array<string|int, mixed> $options = [] ]) : self
Parameters
- $identifier : string
- $source : string
-
URI to stylesheet file (allows EXT: syntax)
- $attributes : array<string|int, mixed> = []
-
additional HTML tag attributes
- $options : array<string|int, mixed> = []
-
['priority' => true] means rendering before other tags
Return values
selfgetInlineJavaScripts()
public
getInlineJavaScripts([bool|null $priority = null ]) : array<string|int, mixed>
Parameters
- $priority : bool|null = null
Return values
array<string|int, mixed>getInlineStyleSheets()
public
getInlineStyleSheets([bool|null $priority = null ]) : array<string|int, mixed>
Parameters
- $priority : bool|null = null
Return values
array<string|int, mixed>getJavaScripts()
public
getJavaScripts([bool|null $priority = null ]) : array<string|int, mixed>
Parameters
- $priority : bool|null = null
Return values
array<string|int, mixed>getMedia()
public
getMedia() : array<string|int, mixed>
Return values
array<string|int, mixed>getState()
public
getState() : array<string|int, mixed>
Return values
array<string|int, mixed>getStyleSheets()
public
getStyleSheets([bool|null $priority = null ]) : array<string|int, mixed>
Parameters
- $priority : bool|null = null
Return values
array<string|int, mixed>hasInlineJavaScript()
public
hasInlineJavaScript(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolhasInlineStyleSheet()
public
hasInlineStyleSheet(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolhasJavaScript()
public
hasJavaScript(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolhasMedia()
public
hasMedia(string $fileName) : bool
Parameters
- $fileName : string
Return values
boolhasStyleSheet()
public
hasStyleSheet(string $identifier) : bool
Parameters
- $identifier : string
Return values
boolremoveInlineJavaScript()
public
removeInlineJavaScript(string $identifier) : self
Parameters
- $identifier : string
Return values
selfremoveInlineStyleSheet()
public
removeInlineStyleSheet(string $identifier) : self
Parameters
- $identifier : string
Return values
selfremoveJavaScript()
public
removeJavaScript(string $identifier) : self
Parameters
- $identifier : string
Return values
selfremoveMedia()
public
removeMedia(string $identifier) : self
Parameters
- $identifier : string
Return values
selfremoveStyleSheet()
public
removeStyleSheet(string $identifier) : self
Parameters
- $identifier : string
Return values
selfupdateState()
public
updateState(array<string|int, mixed> $newState) : void
Parameters
- $newState : array<string|int, mixed>
filterAssetsPriority()
protected
filterAssetsPriority(array<string|int, mixed> $assets, bool|null $priority) : array<string|int, mixed>
Parameters
- $assets : array<string|int, mixed>
-
The array to filter
- $priority : bool|null
-
null: no filter; else filters for the given priority