Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Assetic

Daniel Gomes
December 06, 2012

Introduction to Assetic

Assetic is an asset management framework for PHP 5.3, on this talk will explain the concepts and show how can you use it and take advantage of it.

Presented at 1st phplx meetup.

Note: The video of this talk is now available but is in portuguese. You can watch it here: http://www.youtube.com/watch?v=Do9OaXYUB4I

Daniel Gomes

December 06, 2012
Tweet

More Decks by Daniel Gomes

Other Decks in Programming

Transcript

  1. Asset with filter use Assetic\Asset\FileAsset; use Assetic\Filter\Yui\JsCompressorFilter; $filter = new

    JsCompressorFilter('path/to/yui/compressor.jar'); $asset = new FileAsset('path/to/file.js', array($filter)); header('Content-Type: application/javascript'); echo $asset->dump();
  2. Asset with filter use Assetic\Asset\FileAsset; use Assetic\Filter\Yui\JsCompressorFilter; $filter = new

    JsCompressorFilter('path/to/yui/compressor.jar'); $asset = new FileAsset('path/to/file.js', array($filter)); header('Content-Type: application/js'); echo $asset->dump();
  3. Asset with filter use Assetic\Asset\FileAsset; use Assetic\Filter\Yui\JsCompressorFilter; $filter = new

    JsCompressorFilter('path/to/yui/compressor.jar'); $asset = new FileAsset('path/to/file.js', array($filter)); header('Content-Type: application/js'); echo $asset->dump();
  4. Asset with filter use Assetic\Asset\FileAsset; use Assetic\Filter\Yui\JsCompressorFilter; $filter = new

    JsCompressorFilter('path/to/yui/compressor.jar'); $asset = new FileAsset('path/to/file.js', array($filter)); header('Content-Type: application/js'); echo $asset->dump();
  5. Asset Collection use Assetic\Asset\FileAsset; use Assetic\Asset\GlobAsset; use Assetic\Filter\Yui\JsCompressorFilter; $filter =

    new JsCompressorFilter('path/to/yui/compressor.jar'); $collection = new AssetCollection(array( new FileAsset('/path/to/js/site.js'), new GlobAsset('/path/to/js/jquery/*.js') ), array($filter)); header('Content-Type: application/js'); echo $collection->dump();
  6. Nested Asset Collection use Assetic\Asset\GlobAsset; use Assetic\Filter\Yui\CssCompressorFilter; use Assetic\Filter\LessFilter; $filter

    = new CssCompressorFilter('path/to/yui/compressor.jar'); $collection = new AssetCollection(array( new AssetCollection( array(new FileAsset('path/to/less/file.less')), array(new LessFilter()) ), new GlobAsset('/path/to/css/*.css') ), array($filter)); header('Content-Type: text/css'); echo $collection->dump();
  7. Asset & Filter Manager use Assetic\Asset\FileAsset; use Assetic\AssetManager; use Assetic\FilterManager;

    use Assetic\Filter\Yui\JsCompressorFilter; // Simple usage of Filter Manager $filterManager = new FilterManager(); $filterManager->set('sass', new SassFilter('/path/to/sass/parser')); // Simple usage of Asset Manager $assetManager = new AssetManager(); $assetManager->set('jquery', new FileAsset('path/to/js/jquery.js')); header('Content-Type: application/js'); echo $assetManager->get('jquery')->dump();
  8. Asset & Filter Manager use Assetic\Asset\FileAsset; use Assetic\AssetManager; use Assetic\FilterManager;

    use Assetic\Filter\Yui\JsCompressorFilter; // Simple usage of Filter Manager $filterManager = new FilterManager(); $filterManager->set('sass', new SassFilter('/path/to/sass/parser')); // Simple usage of Asset Manager $assetManager = new AssetManager(); $assetManager->set('jquery', new FileAsset('path/to/js/jquery.js')); header('Content-Type: application/js'); echo $assetManager->get('jquery')->dump();
  9. Asset & Filter Manager use Assetic\Asset\FileAsset; use Assetic\AssetManager; use Assetic\FilterManager;

    use Assetic\Filter\Yui\JsCompressorFilter; // Simple usage of Filter Manager $filterManager = new FilterManager(); $filterManager->set('sass', new SassFilter('/path/to/sass/parser')); // Simple usage of Asset Manager $assetManager = new AssetManager(); $assetManager->set('jquery', new FileAsset('path/to/js/jquery.js')); header('Content-Type: application/js'); echo $assetManager->get('jquery')->dump();
  10. Asset Reference use Assetic\Asset\AssetReference; $assetManager->set('custom_plugin', new AssetCollection(array( new AssetReference($assetManager, 'jquery'),

    new FileAsset('path/to/js/jquery.plugin.js'), ), array( $filter ) ); header('Content-Type: application/js'); echo $js->dump();
  11. Asset Reference use Assetic\Asset\AssetReference; $assetManager->set('custom_plugin', new AssetCollection(array( new AssetReference($assetManager, 'jquery'),

    new FileAsset('path/to/js/jquery.plugin.js'), ), array( $filter ) ); header('Content-Type: application/js'); echo $js->dump();
  12. Asset Factory use Assetic\Factory\AssetFactory; $factory = new AssetFactory('/path/to/assets/directory/', true); $js

    = $factory->createAsset( array( '@jquery', // load the asset manager's "jquery" asset 'js/3rd-party/*.js', // load every js files from "/path/to/js/3rd-party/" ), array( '?yui_js', // will not be used in debug mode ) ); header('Content-Type: application/js'); echo $js->dump();
  13. Asset Factory use Assetic\Factory\AssetFactory; $factory = new AssetFactory('/path/to/assets/directory/', true); $js

    = $factory->createAsset( array( '@jquery', // load the asset manager's "jquery" asset 'js/3rd-party/*.js', // load every js files from "/path/to/js/3rd-party/" ), array( '?yui_js', // will not be used in debug mode ) ); header('Content-Type: application/js'); echo $js->dump();
  14. Asset Factory use Assetic\Factory\AssetFactory; $factory = new AssetFactory('/path/to/assets/directory/', true); $js

    = $factory->createAsset( array( '@jquery', // load the asset manager's "jquery" asset 'js/3rd-party/*.js', // load every js files from "/path/to/js/3rd-party/" ), array( '?yui_js', // will not be used in debug mode ) ); header('Content-Type: application/js'); echo $js->dump();