assetic.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. $app = new Silex\Application();
  3. $app->register(new Silex\Extension\TwigExtension());
  4. $app['twig.path'] = __DIR__ . '/twig';
  5. $app->register(new SilexAssetic\AsseticServiceProvider());
  6. $app['assetic.path_to_web'] = __DIR__ . '/assetic/output';
  7. $app['assetic.options'] = array(
  8. 'formulae_cache_dir' => __DIR__ . '/assetic/cache',
  9. 'debug' => false
  10. );
  11. $app['assetic.filter_manager'] = $app['assetic.filter_manager'] = $app->share(
  12. $app->extend('assetic.filter_manager', function($fm, $app) {
  13. $fm->set('yui_css', new Assetic\Filter\Yui\CssCompressorFilter(
  14. '/usr/share/yui-compressor/yui-compressor.jar'
  15. ));
  16. $fm->set('yui_js', new Assetic\Filter\Yui\JsCompressorFilter(
  17. '/usr/share/yui-compressor/yui-compressor.jar'
  18. ));
  19. return $fm;
  20. })
  21. );
  22. $app['assetic.asset_manager'] = $app->share(
  23. $app->extend('assetic.asset_manager', function($am, $app) {
  24. $am->set('styles', new Assetic\Asset\AssetCache(
  25. new Assetic\Asset\GlobAsset(
  26. __DIR__ . '/assetic/resources/css/*.css',
  27. array($fm->get('yui_css'))
  28. ),
  29. new Assetic\Cache\FilesystemCache(__DIR__ . '/assetic/cache')
  30. ));
  31. $am->get('styles')->setTargetPath('css/styles');
  32. return $am;
  33. })
  34. );
  35. $app->get('/', function () use ($app) {
  36. return 'Hello!';
  37. });
  38. $app->run();