Assets
- Full name:
\Qubus\Support\Assets
Properties
assetRegex
Regex to match against a filename/url to determine if it is an asset.
cssRegex
Regex to match against a filename/url to determine if it is a CSS asset.
jsRegex
Regex to match against a filename/url to determine if it is a JavaScript asset.
noMinificationRegex
Regex to match against a filename/url to determine if it should not be minified by pipeline.
publicDir
Absolute path to the public directory of your App (WEBROOT).
Required if you enable the pipeline. No trailing slash!.
cssDir
Directory for local CSS assets.
Relative to your public directory ('public_dir'). No trailing slash!.
jsDir
Directory for local JavaScript assets.
Relative to your public directory ('public_dir'). No trailing slash!.
packagesDir
Directory for local package assets.
Relative to your public directory ('public_dir'). No trailing slash!.
pipeline
Enable assets pipeline (concatenation and minification).
Use a string that evaluates to true
to provide the salt of the pipeline hash. Use 'auto' to automatically calculated the salt from your assets last modification time.
pipelineDir
Directory for storing pipelined assets.
Relative to your assets directories ('css_dir' and 'js_dir'). No trailing slash!.
pipelineGzip
Enable pipelined assets compression with Gzip. Do not enable unless you know what you are doing!.
Useful only if your webserver supports Gzip HTTP_ACCEPT_ENCODING. Set to true to use the default compression level. Set an integer between 0 (no compression) and 9 (maximum compression) to choose compression level.
fetchCommand
Closure used by the pipeline to fetch assets.
Useful when file_get_contents() function is not available in your PHP installation or when you want to apply any kind of preprocessing to your assets before they get pipelined.
The closure will receive as the only parameter a string with the path/URL of the asset, and it should return the content of the asset file as a string.
notifyCommand
Closure invoked by the pipeline whenever new assets are pipelined for the first time.
Useful if you need to hook to the pipeline event for things such syncing your pipelined assets with an external server or CDN.
The closure will receive five parameters: - String containing the name of the file that has been created. - String containing the relative URL of the file. - String containing the absolute path (filesystem) of the file. - Array containing the assets included in the file. - Boolean indicating whether a gzipped version of the file was also created.
cssMinifier
Closure used by the pipeline to minify CSS assets.
jsMinifier
Closure used by the pipeline to minify JavaScript assets.
collections
Available collections.
Each collection is an array of assets. Collections may also contain other collections.
css
CSS files already added.
Not accepted as an option of config() method.
js
JavaScript files already added.
Not accepted as an option of config() method.
Methods
__construct
Parameters:
Parameter | Type | Description |
---|---|---|
$options | array | See config() method for details. |
config
Set up configuration options.
All the class properties except 'js' and 'css' are accepted here. Also, an extra option 'autoload' may be passed containing an array of assets and/or collections that will be automatically added on startup.
Parameters:
Parameter | Type | Description |
---|---|---|
$config | array | Configurable options. |
add
Add an asset or a collection of assets.
It automatically detects the asset type (JavaScript, CSS or collection). You may add more than one asset passing an array as argument.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | mixed |
prepend
Add an asset or a collection of assets to the beginning of the queue.
It automatically detects the asset type (JavaScript, CSS or collection). You may prepend more than one asset passing an array as argument.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | mixed |
addCss
Add a CSS asset.
It checks for duplicates. You may add more than one asset passing an array as argument.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | mixed |
prependCss
Add a CSS asset to the beginning of the queue.
It checks for duplicates. You may prepend more than one asset passing an array as argument.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | mixed |
addJs
Add a JavaScript asset.
It checks for duplicates. You may add more than one asset passing an array as argument.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | mixed |
prependJs
Add a JavaScript asset to the beginning of the queue.
It checks for duplicates. You may prepend more than one asset passing an array as argument.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | mixed |
css
Build the CSS <link>
tags.
Accepts an array of $attributes for the HTML tag. You can take control of the tag rendering by providing a closure that will receive an array of assets.
Parameters:
Parameter | Type | Description |
---|---|---|
$attributes | array|\Closure|null |
js
Build the JavaScript <script>
tags.
Accepts an array of $attributes for the HTML tag. You can take control of the tag rendering by providing a closure that will receive an array of assets.
Parameters:
Parameter | Type | Description |
---|---|---|
$attributes | array|\Closure|null |
registerCollection
Add/replace collection.
Parameters:
Parameter | Type | Description |
---|---|---|
$collectionName | string | |
$assets | array |
reset
Reset all assets.
resetCss
Reset CSS assets.
resetJs
Reset JavaScript assets.
cssPipeline
Minify and concatenate CSS files.
jsPipeline
Minify and concatenate JavaScript files.
pipeline
Minify and concatenate files.
protected pipeline(array $assets, string $extension, string $subdirectory, \Closure $minifier): string
Parameters:
Parameter | Type | Description |
---|---|---|
$assets | array | |
$extension | string | |
$subdirectory | string | |
$minifier | \Closure |
calculatePipelineHash
Calculate the pipeline hash.
Parameters:
Parameter | Type | Description |
---|---|---|
$assets | array |
packLinks
Download, concatenate and minify the content of several links.
Parameters:
Parameter | Type | Description |
---|---|---|
$links | array | |
$minifier | \Closure |
buildLocalLink
Build link to local asset.
Detect packages links.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | string | |
$dir | string |
Return Value:
the link
buildTagAttributes
Build an HTML attribute string from an array.
Parameters:
Parameter | Type | Description |
---|---|---|
$attributes | array |
assetIsFromPackage
Determine whether an asset is normal or from a package.
Parameters:
Parameter | Type | Description |
---|---|---|
$asset | string |
isRemoteLink
Determine whether a link is local or remote.
Understands both "http://" and "https://" as well as protocol agnostic links "//"
Parameters:
Parameter | Type | Description |
---|---|---|
$link | string |
getCss
Get all CSS assets already added.
getJs
Get all JavaScript assets already added.
addDir
Add all assets matching $pattern within $directory.
Parameters:
Parameter | Type | Description |
---|---|---|
$directory | string | Relative to $this->publicDir |
$pattern | string|null | (regex) |
addDirCss
Add all CSS assets within $directory (relative to public dir).
Parameters:
Parameter | Type | Description |
---|---|---|
$directory | string | Relative to $this->publicDir |
addDirJs
Add all JavaScript assets within $directory (relative to public dir).
Parameters:
Parameter | Type | Description |
---|---|---|
$directory | string | Relative to $this->publicDir |
rglob
Recursively get files matching $pattern within $directory.
Parameters:
Parameter | Type | Description |
---|---|---|
$directory | string | |
$pattern | string | (regex) |
$ltrim | string|null | Will be trimmed from the left of the file path |
Automatically generated on 2025-10-13