StaticNode.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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\Extension\Twig\AsseticNode;
  12. /**
  13. * The "static" node references a file in the web directory.
  14. *
  15. * @author Kris Wallsmith <kris.wallsmith@symfony.com>
  16. */
  17. class StaticNode extends AsseticNode
  18. {
  19. /**
  20. * Renders the asset URL using Symfony's asset() function.
  21. */
  22. protected function getAssetUrlNode(\Twig_NodeInterface $body)
  23. {
  24. return new \Twig_Node_Expression_Function(
  25. new \Twig_Node_Expression_Name('asset', $body->getLine()),
  26. new \Twig_Node(array(
  27. new \Twig_Node_Expression_Constant($this->getAttribute('output'), $body->getLine()),
  28. new \Twig_Node_Expression_Constant($this->hasAttribute('package') ? $this->getAttribute('package') : null, $body->getLine()),
  29. )),
  30. $body->getLine()
  31. );
  32. }
  33. }