vendor/kriswallsmith/assetic/src/Assetic/Extension/Twig/AsseticExtension.php line 17

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Assetic package, an OpenSky project.
  4.  *
  5.  * (c) 2010-2014 OpenSky Project Inc
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Assetic\Extension\Twig;
  11. use Assetic\Factory\AssetFactory;
  12. use Assetic\ValueSupplierInterface;
  13. class AsseticExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
  14. {
  15.     protected $factory;
  16.     protected $functions;
  17.     protected $valueSupplier;
  18.     public function __construct(AssetFactory $factory$functions = array(), ValueSupplierInterface $valueSupplier null)
  19.     {
  20.         $this->factory $factory;
  21.         $this->functions = array();
  22.         $this->valueSupplier $valueSupplier;
  23.         foreach ($functions as $function => $options) {
  24.             if (is_integer($function) && is_string($options)) {
  25.                 $this->functions[$options] = array('filter' => $options);
  26.             } else {
  27.                 $this->functions[$function] = $options + array('filter' => $function);
  28.             }
  29.         }
  30.     }
  31.     public function getTokenParsers()
  32.     {
  33.         return array(
  34.             new AsseticTokenParser($this->factory'javascripts''js/*.js'),
  35.             new AsseticTokenParser($this->factory'stylesheets''css/*.css'),
  36.             new AsseticTokenParser($this->factory'image''images/*'true),
  37.         );
  38.     }
  39.     public function getFunctions()
  40.     {
  41.         $functions = array();
  42.         foreach ($this->functions as $function => $filter) {
  43.             $functions[] = new AsseticFilterFunction($function);
  44.         }
  45.         return $functions;
  46.     }
  47.     public function getGlobals()
  48.     {
  49.         return array(
  50.             'assetic' => array(
  51.                 'debug' => $this->factory->isDebug(),
  52.                 'vars'  => null !== $this->valueSupplier ? new ValueContainer($this->valueSupplier) : array(),
  53.             ),
  54.         );
  55.     }
  56.     public function getFilterInvoker($function)
  57.     {
  58.         return new AsseticFilterInvoker($this->factory$this->functions[$function]);
  59.     }
  60.     public function getName()
  61.     {
  62.         return 'assetic';
  63.     }
  64. }