- Class name: Manager
- Namespace: Stolz\Assets
protected string $asset_regex = '/.\.(css|js)$/i'
Regex to match against a filename/url to determine if it is an asset.
- Visibility: protected
protected string $css_regex = '/.\.css$/i'
Regex to match against a filename/url to determine if it is a CSS asset.
- Visibility: protected
protected string $js_regex = '/.\.js$/i'
Regex to match against a filename/url to determine if it is a JavaScript asset.
- Visibility: protected
protected string $no_minification_regex = '/.[-.]min\.(css|js)$/i'
Regex to match against a filename/url to determine if it should not be minified by pipeline.
- Visibility: protected
protected string $public_dir
Absolute path to the public directory of your App (WEBROOT).
Required if you enable the pipeline. No trailing slash!.
- Visibility: protected
protected string $css_dir = 'css'
Directory for local CSS assets.
Relative to your public directory ('public_dir'). No trailing slash!.
- Visibility: protected
protected string $js_dir = 'js'
Directory for local JavaScript assets.
Relative to your public directory ('public_dir'). No trailing slash!.
- Visibility: protected
protected string $packages_dir = 'packages'
Directory for local package assets.
Relative to your public directory ('public_dir'). No trailing slash!.
- Visibility: protected
protected boolean $pipeline = false
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.
- Visibility: protected
protected string $pipeline_dir = 'min'
Directory for storing pipelined assets.
Relative to your assets directories ('css_dir' and 'js_dir'). No trailing slash!.
- Visibility: protected
protected boolean $pipeline_gzip = false
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.
- Visibility: protected
protected \Closure $fetch_command
Closure used by the pipeline to fetch assets.
Useful when file_get_contents() function is not available in your PHP instalation 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.
- Visibility: protected
protected \Closure $notify_command
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 or not a gziped version of the file was also created.
- Visibility: protected
protected \Closure $css_minifier
Closure used by the pipeline to minify CSS assets.
- Visibility: protected
protected \Closure $js_minifier
Closure used by the pipeline to minify JavaScript assets.
- Visibility: protected
protected array $collections = array()
Available collections.
Each collection is an array of assets. Collections may also contain other collections.
- Visibility: protected
protected array $css = array()
CSS files already added.
Not accepted as an option of config() method.
- Visibility: protected
protected array $js = array()
JavaScript files already added.
Not accepted as an option of config() method.
- Visibility: protected
void __construct(array $options)
Class constructor.
- Visibility: public
- $options array - <p>See config() method for details.</p>
Assets config(array $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.
- Visibility: public
- $config array - <p>Configurable options.</p>
Assets add(mixed $asset)
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.
- Visibility: public
- $asset mixed
Assets prepend(mixed $asset)
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.
- Visibility: public
- $asset mixed
Assets addCss(mixed $asset)
Add a CSS asset.
It checks for duplicates. You may add more than one asset passing an array as argument.
- Visibility: public
- $asset mixed
Assets prependCss(mixed $asset)
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.
- Visibility: public
- $asset mixed
Assets addJs(mixed $asset)
Add a JavaScript asset.
It checks for duplicates. You may add more than one asset passing an array as argument.
- Visibility: public
- $asset mixed
Assets prependJs(mixed $asset)
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.
- Visibility: public
- $asset mixed
string css(array|\Closure $attributes)
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.
- Visibility: public
- $attributes array|Closure
string js(array|\Closure $attributes)
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.
- Visibility: public
- $attributes array|Closure
Assets registerCollection(string $collectionName, array $assets)
Add/replace collection.
- Visibility: public
- $collectionName string
- $assets array
Assets reset()
Reset all assets.
- Visibility: public
Assets resetCss()
Reset CSS assets.
- Visibility: public
Assets resetJs()
Reset JavaScript assets.
- Visibility: public
string cssPipeline()
Minifiy and concatenate CSS files.
- Visibility: protected
string jsPipeline()
Minifiy and concatenate JavaScript files.
- Visibility: protected
string pipeline(array $assets, string $extension, string $subdirectory, \Closure $minifier)
Minifiy and concatenate files.
- Visibility: protected
- $assets array
- $extension string
- $subdirectory string
- $minifier Closure
string calculatePipelineHash(array $assets)
Calculate the pipeline hash.
- Visibility: protected
- $assets array
string packLinks(array $links, \Closure $minifier)
Download, concatenate and minifiy the content of several links.
- Visibility: protected
- $links array
- $minifier Closure
string buildLocalLink(string $asset, string $dir)
Build link to local asset.
Detects packages links.
- Visibility: protected
- $asset string
- $dir string
string buildTagAttributes(array $attributes)
Build an HTML attribute string from an array.
- Visibility: public
- $attributes array
boolean|array assetIsFromPackage(string $asset)
Determine whether an asset is normal or from a package.
- Visibility: protected
- $asset string
boolean isRemoteLink(string $link)
Determine whether a link is local or remote.
Undestands both "http://" and "https://" as well as protocol agnostic links "//"
- Visibility: protected
- $link string
array getCss()
Get all CSS assets already added.
- Visibility: public
array getJs()
Get all JavaScript assets already added.
- Visibility: public
Assets addDir(string $directory, string $pattern)
Add all assets matching $pattern within $directory.
- Visibility: public
- $directory string - <p>Relative to $this->public_dir</p>
- $pattern string - <p>(regex)</p>
Assets addDirCss(string $directory)
Add all CSS assets within $directory (relative to public dir).
- Visibility: public
- $directory string - <p>Relative to $this->public_dir</p>
Assets addDirJs(string $directory)
Add all JavaScript assets within $directory (relative to public dir).
- Visibility: public
- $directory string - <p>Relative to $this->public_dir</p>
array rglob(string $directory, string $pattern, string $ltrim)
Recursively get files matching $pattern within $directory.
- Visibility: protected
- $directory string
- $pattern string - <p>(regex)</p>
- $ltrim string - <p>Will be trimed from the left of the file path</p>