11<?php
22
3- namespace Troopers \AlertifyBundle \Twig \ Extension ;
3+ namespace Troopers \AlertifyBundle \Handler ;
44
55use Symfony \Component \HttpFoundation \Session \Session ;
66
77/**
8- * AlertifyExtension .
8+ * AlertifySessionHandler .
99 */
10- class AlertifyExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
10+ class AlertifySessionHandler
1111{
12- protected $ environment ;
13- protected $ defaultParameters ;
14-
1512 /**
16- * {@inheritdoc}
13+ * @var \Twig_Environment
1714 */
18- public function __construct ($ defaultParameters )
19- {
20- $ this ->defaultParameters = $ defaultParameters ;
21- }
15+ protected $ twig ;
2216
2317 /**
24- * {@inheritdoc}
18+ * @var array
2519 */
26- public function initRuntime (\Twig_Environment $ environment )
27- {
28- $ this ->environment = $ environment ;
29- }
20+ private $ defaultParameters ;
3021
3122 /**
32- * {@inheritdoc}
33- */
34- public function getName ()
35- {
36- return 'alertify ' ;
37- }
38-
39- /**
40- * {@inheritdoc}
23+ * AlertifySessionHandler constructor.
24+ *
25+ * @param \Twig_Environment $twig
26+ * @param array $defaultParameters
4127 */
42- public function getFilters ( )
28+ public function __construct ( \ Twig_Environment $ twig , array $ defaultParameters )
4329 {
44- return [
45- new \Twig_SimpleFilter ('alertify ' , [$ this , 'alertifyFilter ' ], ['needs_environment ' => true , 'is_safe ' => ['html ' ]]),
46- ];
30+ $ this ->twig = $ twig ;
31+ $ this ->defaultParameters = $ defaultParameters ;
4732 }
4833
4934 /**
50- * Alertify filter .
35+ * Alertify .
5136 *
52- * @param \Twig_Environment $environment
37+ * @param \Twig_Environment $this-twig
5338 * @param Session $session
5439 *
5540 * @return string
5641 */
57- public function alertifyFilter ( $ environment , Session $ session )
42+ public function handle ( $ session )
5843 {
5944 $ flashes = $ session ->getFlashBag ()->all ();
6045
6146 $ renders = [];
6247 foreach ($ flashes as $ type => $ flash ) {
6348 if ($ type == 'callback ' ) {
6449 foreach ($ flash as $ key => $ currentFlash ) {
65- $ currentFlash ['body ' ] .= $ environment ->render ('TroopersAlertifyBundle::callback.html.twig ' , $ currentFlash );
50+ $ currentFlash ['body ' ] .= $ this -> twig ->render ('TroopersAlertifyBundle::callback.html.twig ' , $ currentFlash );
6651 $ session ->getFlashBag ()->add ($ currentFlash ['engine ' ], $ currentFlash );
67- $ renders [$ type .$ key ] = $ this ->alertifyFilter ( $ environment , $ session );
52+ $ renders [$ type .$ key ] = $ this ->handle ( $ session );
6853 }
6954 } else {
7055 foreach ($ flash as $ key => $ content ) {
@@ -78,7 +63,7 @@ public function alertifyFilter($environment, Session $session)
7863 }
7964
8065 $ parameters ['type ' ] = $ type ;
81- $ renders [$ type .$ key ] = $ environment ->render ('TroopersAlertifyBundle:: ' .$ parameters ['engine ' ].'.html.twig ' , $ parameters );
66+ $ renders [$ type .$ key ] = $ this -> twig ->render ('TroopersAlertifyBundle:: ' .$ parameters ['engine ' ].'.html.twig ' , $ parameters );
8267 }
8368 }
8469 }
0 commit comments