2011-05-19 13:32:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Bundle\TwigBundle\Extension;
|
|
|
|
|
2011-05-24 17:08:42 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
2011-05-19 13:32:24 +01:00
|
|
|
|
|
|
|
/**
|
2011-12-13 07:50:54 +00:00
|
|
|
* Twig extension for Symfony code helper
|
|
|
|
*
|
2011-05-19 13:32:24 +01:00
|
|
|
*
|
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
|
|
|
*/
|
|
|
|
class CodeExtension extends \Twig_Extension
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
private $container;
|
2011-05-19 13:32:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor of Twig Extension to provide functions for code formatting
|
|
|
|
*
|
2011-12-13 07:50:54 +00:00
|
|
|
* @param ContainerInterface $container A ContainerInterface instance
|
2011-05-19 13:32:24 +01:00
|
|
|
*/
|
2011-05-24 17:08:42 +01:00
|
|
|
public function __construct(ContainerInterface $container)
|
2011-05-19 13:32:24 +01:00
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
$this->container = $container;
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getFilters()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'abbr_class' => new \Twig_Filter_Method($this, 'abbrClass', array('is_safe' => array('html'))),
|
|
|
|
'abbr_method' => new \Twig_Filter_Method($this, 'abbrMethod', array('is_safe' => array('html'))),
|
|
|
|
'format_args' => new \Twig_Filter_Method($this, 'formatArgs', array('is_safe' => array('html'))),
|
|
|
|
'format_args_as_text' => new \Twig_Filter_Method($this, 'formatArgsAsText'),
|
|
|
|
'file_excerpt' => new \Twig_Filter_Method($this, 'fileExcerpt', array('is_safe' => array('html'))),
|
|
|
|
'format_file' => new \Twig_Filter_Method($this, 'formatFile', array('is_safe' => array('html'))),
|
|
|
|
'format_file_from_text' => new \Twig_Filter_Method($this, 'formatFileFromText', array('is_safe' => array('html'))),
|
|
|
|
'file_link' => new \Twig_Filter_Method($this, 'getFileLink', array('is_safe' => array('html'))),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function abbrClass($class)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->abbrClass($class);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function abbrMethod($method)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->abbrMethod($method);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function formatArgs($args)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->formatArgs($args);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function formatArgsAsText($args)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->formatArgsAsText($args);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function fileExcerpt($file, $line)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->fileExcerpt($file, $line);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function formatFile($file, $line, $text = null)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->formatFile($file, $line, $text);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getFileLink($file, $line)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->getFileLink($file, $line);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function formatFileFromText($text)
|
|
|
|
{
|
2011-05-24 17:08:42 +01:00
|
|
|
return $this->container->get('templating.helper.code')->formatFileFromText($text);
|
2011-05-19 13:32:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'code';
|
|
|
|
}
|
|
|
|
}
|