22
33namespace FM \BbcodeBundle \Templating ;
44
5+ use FM \BbcodeBundle \Decoda \DecodaManager ;
56use Symfony \Component \DependencyInjection \ContainerInterface ;
6- use FM \BbcodeBundle \Decoda \DecodaManager as DecodaManager ;
7+ use Twig \Error \RuntimeError ;
8+ use Twig \Extension \AbstractExtension ;
9+ use Twig \TwigFilter ;
710
811/**
9- * @author Al Ganiev <helios.ag@gmail.com>
12+ * @author Al Ganiev <helios.ag@gmail.com>
1013 * @copyright 2012-2015 Al Ganiev
11- * @license http://www.opensource.org/licenses/mit-license.php MIT License
14+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
1215 */
13- class BbcodeExtension extends \Twig_Extension
16+ class BbcodeExtension extends AbstractExtension
1417{
1518 /**
1619 * @var DecodaManager
@@ -26,20 +29,22 @@ public function __construct(DecodaManager $decodaManager)
2629 }
2730
2831 /**
29- * (non-PHPdoc) .
32+ * Strip tags .
3033 *
31- * @see Twig_Extension::getFilters()
34+ * @param $value
35+ * @param $filterSet
3236 *
33- * @return array
37+ * @return string
38+ *
39+ * @throws RuntimeError
3440 */
35- public function getFilters ( )
41+ public function clean ( $ value , $ filterSet = DecodaManager:: DECODA_DEFAULT )
3642 {
37- $ options = array ('is_safe ' => array ('html ' ));
43+ if (!is_string ($ value )) {
44+ throw new RuntimeError ('The filter can be applied to strings only. ' );
45+ }
3846
39- return array (
40- new \Twig_SimpleFilter ('bbcode_filter ' , array ($ this , 'filter ' ), $ options ),
41- new \Twig_SimpleFilter ('bbcode_clean ' , array ($ this , 'clean ' ), $ options ),
42- );
47+ return $ this ->decodaManager ->get ($ value , $ filterSet )->strip (true );
4348 }
4449
4550 /**
@@ -49,40 +54,38 @@ public function getFilters()
4954 * @return string
5055 * @return \FM\BbcodeBundle\Decoda\Decoda
5156 *
52- * @throws \Twig_Error_Runtime
57+ * @throws RuntimeError
5358 */
5459 public function filter ($ value , $ filterSet = DecodaManager::DECODA_DEFAULT )
5560 {
5661 if (!is_string ($ value )) {
57- throw new \ Twig_Error_Runtime ('The filter can be applied to strings only. ' );
62+ throw new RuntimeError ('The filter can be applied to strings only. ' );
5863 }
5964
6065 return $ this ->decodaManager ->get ($ value , $ filterSet )->parse ();
6166 }
6267
6368 /**
64- * Strip tags.
65- *
66- * @param $value
67- * @param $filterSet
69+ * (non-PHPdoc).
6870 *
69- * @return string
71+ * @return array
72+ * @see AbstractExtension::getFilters()
7073 *
71- * @throws \Twig_Error_Runtime
7274 */
73- public function clean ( $ value , $ filterSet = DecodaManager:: DECODA_DEFAULT )
75+ public function getFilters ( )
7476 {
75- if (!is_string ($ value )) {
76- throw new \Twig_Error_Runtime ('The filter can be applied to strings only. ' );
77- }
77+ $ options = ['is_safe ' => ['html ' ]];
7878
79- return $ this ->decodaManager ->get ($ value , $ filterSet )->strip (true );
79+ return [
80+ new TwigFilter ('bbcode_filter ' , [$ this , 'filter ' ], $ options ),
81+ new TwigFilter ('bbcode_clean ' , [$ this , 'clean ' ], $ options ),
82+ ];
8083 }
8184
8285 /**
8386 * (non-PHPdoc).
8487 *
85- * @see Twig_ExtensionInterface ::getName()
88+ * @see AbstractExtension ::getName()
8689 */
8790 public function getName ()
8891 {
0 commit comments