annotate src/Kachkaev/JstmplBundle/Twig/JstmplExtension.php @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
rev   line source
Daniel@0 1 <?php
Daniel@0 2 namespace Kachkaev\JstmplBundle\Twig;
Daniel@0 3
Daniel@0 4 use Symfony\Component\DependencyInjection\ContainerInterface;
Daniel@0 5 use Twig_Extension;
Daniel@0 6 use Twig_Function_Method;
Daniel@0 7
Daniel@0 8 class JstmplExtension extends Twig_Extension
Daniel@0 9 {
Daniel@0 10 protected $container;
Daniel@0 11
Daniel@0 12 public function __construct(ContainerInterface $container)
Daniel@0 13 {
Daniel@0 14 $this->container = $container;
Daniel@0 15 }
Daniel@0 16
Daniel@0 17 /**
Daniel@0 18 * @inheritdoc
Daniel@0 19 */
Daniel@0 20 public function getFunctions()
Daniel@0 21 {
Daniel@0 22 $functions = array();
Daniel@0 23
Daniel@0 24 $mappings = array(
Daniel@0 25 'tmpl_path' => 'getTmplPath',
Daniel@0 26 );
Daniel@0 27
Daniel@0 28 foreach($mappings as $twigFunction => $method) {
Daniel@0 29 $functions[$twigFunction] = new Twig_Function_Method($this, $method);
Daniel@0 30 }
Daniel@0 31
Daniel@0 32 $safeMappings = array(
Daniel@0 33 );
Daniel@0 34
Daniel@0 35 foreach($safeMappings as $twigFunction => $method) {
Daniel@0 36 $functions[$twigFunction] = new Twig_Function_Method($this, $method, array ('is_safe' => array('html')));
Daniel@0 37 }
Daniel@0 38
Daniel@0 39 return $functions;
Daniel@0 40 }
Daniel@0 41
Daniel@0 42 public function getTokenParsers()
Daniel@0 43 {
Daniel@0 44 return array(
Daniel@0 45 new JstmplTokenParser()
Daniel@0 46 );
Daniel@0 47 }
Daniel@0 48
Daniel@0 49 public function getName()
Daniel@0 50 {
Daniel@0 51 return 'TmplExtension';
Daniel@0 52 }
Daniel@0 53
Daniel@0 54 public function getTmplPath($name)
Daniel@0 55 {
Daniel@0 56 return "/js/tmpl/$name.js";
Daniel@0 57 }
Daniel@0 58 }