|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Bundle\TwigBundle\Extension; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
15 |
|
|
|
16 |
/** |
|
|
17 |
* |
|
|
18 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
19 |
*/ |
|
|
20 |
class CodeExtension extends \Twig_Extension |
|
|
21 |
{ |
|
|
22 |
private $container; |
|
|
23 |
|
|
|
24 |
/** |
|
|
25 |
* Constructor of Twig Extension to provide functions for code formatting |
|
|
26 |
* |
|
|
27 |
* @param Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper $helper Helper to use |
|
|
28 |
*/ |
|
|
29 |
public function __construct(ContainerInterface $container) |
|
|
30 |
{ |
|
|
31 |
$this->container = $container; |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
/** |
|
|
35 |
* {@inheritdoc} |
|
|
36 |
*/ |
|
|
37 |
public function getFilters() |
|
|
38 |
{ |
|
|
39 |
return array( |
|
|
40 |
'abbr_class' => new \Twig_Filter_Method($this, 'abbrClass', array('is_safe' => array('html'))), |
|
|
41 |
'abbr_method' => new \Twig_Filter_Method($this, 'abbrMethod', array('is_safe' => array('html'))), |
|
|
42 |
'format_args' => new \Twig_Filter_Method($this, 'formatArgs', array('is_safe' => array('html'))), |
|
|
43 |
'format_args_as_text' => new \Twig_Filter_Method($this, 'formatArgsAsText'), |
|
|
44 |
'file_excerpt' => new \Twig_Filter_Method($this, 'fileExcerpt', array('is_safe' => array('html'))), |
|
|
45 |
'format_file' => new \Twig_Filter_Method($this, 'formatFile', array('is_safe' => array('html'))), |
|
|
46 |
'format_file_from_text' => new \Twig_Filter_Method($this, 'formatFileFromText', array('is_safe' => array('html'))), |
|
|
47 |
'file_link' => new \Twig_Filter_Method($this, 'getFileLink', array('is_safe' => array('html'))), |
|
|
48 |
); |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
public function abbrClass($class) |
|
|
52 |
{ |
|
|
53 |
return $this->container->get('templating.helper.code')->abbrClass($class); |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
public function abbrMethod($method) |
|
|
57 |
{ |
|
|
58 |
return $this->container->get('templating.helper.code')->abbrMethod($method); |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
public function formatArgs($args) |
|
|
62 |
{ |
|
|
63 |
return $this->container->get('templating.helper.code')->formatArgs($args); |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
public function formatArgsAsText($args) |
|
|
67 |
{ |
|
|
68 |
return $this->container->get('templating.helper.code')->formatArgsAsText($args); |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
public function fileExcerpt($file, $line) |
|
|
72 |
{ |
|
|
73 |
return $this->container->get('templating.helper.code')->fileExcerpt($file, $line); |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
public function formatFile($file, $line, $text = null) |
|
|
77 |
{ |
|
|
78 |
return $this->container->get('templating.helper.code')->formatFile($file, $line, $text); |
|
|
79 |
} |
|
|
80 |
|
|
|
81 |
public function getFileLink($file, $line) |
|
|
82 |
{ |
|
|
83 |
return $this->container->get('templating.helper.code')->getFileLink($file, $line); |
|
|
84 |
} |
|
|
85 |
|
|
|
86 |
public function formatFileFromText($text) |
|
|
87 |
{ |
|
|
88 |
return $this->container->get('templating.helper.code')->formatFileFromText($text); |
|
|
89 |
} |
|
|
90 |
|
|
|
91 |
public function getName() |
|
|
92 |
{ |
|
|
93 |
return 'code'; |
|
|
94 |
} |
|
|
95 |
} |