dev-master
9999999-dev https://github.com/shadowfax/zf2-asset-managerAsset Manager for ZF2
GPLv2
The Requires
- php >=5.3.3
- zendframework/zendframework 2.2.*
asset
Wallogit.com
2017 © Pedro Peláez
Asset Manager for ZF2
Yet another Zend Framework 2 asset manager., (*1)
If you are looking for a really simple and flexible asset manager for your application this could be it; but probably you are looking for another project., (*2)
Add this project in your composer.json:, (*3)
"require": {
"shadowfax/zf2-asset-manager": "dev-master"
}
Now tell composer to download ThemeManager by running the command:, (*4)
$ php composer.phar update
./vendor/ directory.Enabling it in your application.config.phpfile., (*5)
<?php
return array(
'modules' => array(
'ThemeManager',
// ...
),
// ...
);
This asset manager was written in order to support my ThemeManager. I just needed something simple and flexible enough so I could change the assets on the fly. In my case, if I change a theme, the AssetManager should be told to change the assets it is using., (*6)
This changes are done through the service AssetPathStack where we can add new paths for
asset files, clear all paths, set new paths, etc... Lets look at an example inside a module
(Module.php file):, (*7)
public function onBootstrap(MvcEvent $e)
{
$serviceManager = $e->getApplication()->getServiceManager();
$assetPathStack = $serviceManager->get('AssetPathStack');
$assetPathStack->addPath( __DIR__ . '/assets');
}
With this code we are telling the AssetPathStack to add a new path to the assets folder
contained in our module. Now the assets inside our module will be accessed through the
assets route., (*8)
This can also be done through the module.config.php file:, (*9)
return array(
// ...
'asset_manager' => array(
'paths' => array(
__DIR__ . '/../assets'
)
)
);
By default the assets route is /assets, but this can be changed through the configuration
files., (*10)
return array(
// ...
'asset_manager' => array(
'routes' => array(
'files' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/files',
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Wildcard'
)
)
)
),
)
);
In this example we have changed the route for assets from assets to /files. We suggest this
changes are made in a global configuration file such as config/autoload/assetmanager.global.php
as doing this on a module.config.php could bring errors due to route collisions and the
AssetManager does NOT consider modules independantly., (*11)
Multiple routes may be created. For example:, (*12)
return array(
// ...
'asset_manager' => array(
'routes' => array(
'css' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/css',
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Wildcard'
)
)
),
'js' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/js',
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Wildcard'
)
)
),
'images' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/images',
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Wildcard'
)
)
)
),
)
);
This allows us to set a transparent configuration of the asset manager., (*13)
You don't have to worry about route name collisions as the AssetManager will prepend
asset_manager to the route name. In the example above the route name css will be converted
to asset_manager/css before it gets added to the router., (*14)
Asset Manager for ZF2
GPLv2
asset