-
-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
The default configuration is setup to work with Zend Skeleton Application
-
bool
production
: Define the application environment (development => false). Defaulttrue
. -
mixed
lastModifiedTime
: (optionnal) Allows you to define an arbitrary asset's last modified time in production. Defaultnull
: last modified time is calculated for each asset. -
string
cachePath
: cache directory absolute path, you can use the@zfRootPath
constant corresponding to current working directory. Default@zfRootPath/public/cache
. -
string
assetsPath
: (optionnal) assets directory absolute path, allows you to define relative path for assets config. You can use the constant@zfRootPath
corresponding to current working directory. Default@zfRootPath/public
. -
string
tmpDirPath
: (optionnal) tmp directory absolute path, allows you to define relative path for assets config. You can use the constant@zfRootPath
corresponding to current working directory. Defaultsys_get_temp_dir()
. -
string
processedDirPath
: (optionnal) processed files directory absolute path, allows you to define relative path for assets config. You can use the constant@zfRootPath
corresponding to current working directory. Default@zfRootPath/data/AssetsBundle/processed
. -
string
baseUrl
: (optionnal) Base URL of the application. Ifnull
, the base url is guessed. Defaultnull
. -
string
cacheUrl
: cache directory base url, you can use the constant@zfBaseUrl
corresponding to application base url . Default@zfBaseUrl/assets/cache/
. -
array
mediaExt
: Put here all medias extensions to be cached. Defaultarray('jpeg', 'jpg', 'png', 'gif', 'cur', 'ttf', 'eot', 'svg', 'woff', 'otf', 'woff2',)
. -
bool
recursiveSearch
: If you define a folder as required asset, it will search for matching assets in that folder and its subfolders. Defaultfalse
. -
int
filesPermissions
: Permissions for created files. Default0664
-
int
directoriesPermissions
: Permissions for created directories0775
-
array
filters
: configure asset file filter by extensions
You can define assets for modules / controllers / action
Exemple :
return [
// ...
'assets_bundle' => [
// ...
'assets' => [
// Common assets included in every pages
'css' => [], // Declare css files to include
'js' => [], // Declare js files to include
'less' => [], // Declare less files to include
'scss' => [], // Declare scss files to include
'media' => [], // Declare images to manage
// Modules dedicated assets
'Test' => => [ // "Test" is the name of the module
'css' => [],
'js' => [],
'less' => [],
'scss' => [],
'media' => [],
// Controller dedicated assets
'Test\Controller\Name' => [
'css' => [],
'js' => [],
'less' => [],
'scss' => [],
'media' => [],
// Action specific assets
'ActionName'=> [
'css' => [],
'js' => [],
'less' => [],
'scss' => [],
'media' => [],
],
],
],
],
],
];
- For each asset, you can declare files or directories. All these elements are related to the asset path by default, but you can specify an absolute path or use the constants "@zfAssetsPath" and "@zfRootPath".
If you declare a directory, all files matching the asset type (css, less, js, media) will be included.
-
You can use
.php
file as asset, it will be interpret. -
You can use url for asset file, it will be downloaded:
return [
// ...
'assets_bundle' => [
// ...
'assets' => [
'js' => [
'https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js',
],
// ...
],
// ...
],
//...
];
This example includes Boostrap
javascript from Bootstrap CDN
- You can define an inclusion order like this :
return [
// ...
'assets_bundle' => [
// ...
'assets' => [
'js' => [
'js/firstFile.js',
'js',
],
// ...
],
],
// ...
);
This example includes the file "firstFile.js" first, and all other javascript files in the folder "js"
A filter is a service that parse an asset file content, each supported extensions (css
, js
, less
, scss
, png
, jpg
, jpeg
, gif
) has a default dedicated filter.
- scss: ScssAssetFileFilter
- less: LessphpAssetFileFilter
- css: CssAssetFileFilter
- js: JShrinkAssetFileFilter
- png: PngAssetFileFilter
- jpg: JpegAssetFileFilter
- jpeg: JpegAssetFileFilter
- gif: GifAssetFileFilter
-
ScssAssetFileFilter
: SCSS compiler, it uses leafo/scssphp -
LesscAssetFileFilter
: Lessphp compiler, it uses neilime/lessphp (compliant fork of leafo/lessphp) -
LessphpAssetFileFilter
: Less parser, it uses oyejorge/less.php -
CssAssetFileFilter
: Css compressor, it uses tubalmartin/cssmin (PHP port of the YUI CSS compressor) -
JsMinAssetFileFilter
: Javascript Minifier, it uses mrclay/jsmin-php (Port of Douglas Crockford's jsmin.c) -
JShrinkAssetFileFilter
: Javascript Minifier, it uses tedivm/jshrink -
PngAssetFileFilter
: Png optimizer, it uses gd2 -
JpegAssetFileFilter
: Jpeg optimizer, it uses gd2 -
GifAssetFileFilter
: Gif optimizer, it uses gd2
In the assets_bundle configuration, you can define which filter you want to use.
Example, change the Javascript minifier filter:
'filters' => [
\AssetsBundle\AssetFile\AssetFile::ASSET_JS => 'JsMinAssetFileFilter',
],
In the assets_bundle configuration, you can disable default filters.
Example, disable filters for image:
'filters' => [
'png' => new \Zend\Stdlib\ArrayUtils\MergeRemoveKey(),
'jpg' => new \Zend\Stdlib\ArrayUtils\MergeRemoveKey(),
'jpeg' => new \Zend\Stdlib\ArrayUtils\MergeRemoveKey(),
'gif' => new \Zend\Stdlib\ArrayUtils\MergeRemoveKey(),
],