AsseticExtension.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This file is part of the Symfony framework.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\Bundle\AsseticBundle\Twig;
  11. use Assetic\ValueSupplierInterface;
  12. use Assetic\Extension\Twig\AsseticExtension as BaseAsseticExtension;
  13. use Assetic\Factory\AssetFactory;
  14. use Symfony\Component\Templating\TemplateNameParserInterface;
  15. /**
  16. * Assetic extension.
  17. *
  18. * @author Kris Wallsmith <kris@symfony.com>
  19. */
  20. class AsseticExtension extends BaseAsseticExtension
  21. {
  22. private $useController;
  23. private $templateNameParser;
  24. private $enabledBundles;
  25. public function __construct(AssetFactory $factory, TemplateNameParserInterface $templateNameParser, $useController = false, $functions = array(), $enabledBundles = array(), ValueSupplierInterface $valueSupplier = null)
  26. {
  27. parent::__construct($factory, $functions, $valueSupplier);
  28. $this->useController = $useController;
  29. $this->templateNameParser = $templateNameParser;
  30. $this->enabledBundles = $enabledBundles;
  31. }
  32. public function getTokenParsers()
  33. {
  34. return array(
  35. $this->createTokenParser('javascripts', 'js/*.js'),
  36. $this->createTokenParser('stylesheets', 'css/*.css'),
  37. $this->createTokenParser('image', 'images/*', true),
  38. );
  39. }
  40. public function getNodeVisitors()
  41. {
  42. return array(
  43. new AsseticNodeVisitor($this->templateNameParser, $this->enabledBundles),
  44. );
  45. }
  46. public function getGlobals()
  47. {
  48. $globals = parent::getGlobals();
  49. $globals['assetic']['use_controller'] = $this->useController;
  50. return $globals;
  51. }
  52. private function createTokenParser($tag, $output, $single = false)
  53. {
  54. $tokenParser = new AsseticTokenParser($this->factory, $tag, $output, $single, array('package'));
  55. $tokenParser->setTemplateNameParser($this->templateNameParser);
  56. $tokenParser->setEnabledBundles($this->enabledBundles);
  57. return $tokenParser;
  58. }
  59. }