-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get back twig extension to continue to render alerts with {{ app.sess…
…ion|alertify|raw }}
- Loading branch information
Leny BERNARD
committed
Oct 19, 2016
1 parent
3fd5ebb
commit 7fe9eef
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Troopers\AlertifyBundle\Twig\Extension; | ||
|
||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Troopers\AlertifyBundle\Handler\AlertifySessionHandler; | ||
|
||
/** | ||
* AlertifyExtension. | ||
*/ | ||
class AlertifyExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface | ||
{ | ||
/** | ||
* @var AlertifySessionHandler | ||
*/ | ||
private $alertifySessionHandler; | ||
|
||
/** | ||
* AlertifyExtension constructor. | ||
* | ||
* @param AlertifySessionHandler $alertifySessionHandler | ||
*/ | ||
public function __construct(AlertifySessionHandler $alertifySessionHandler) | ||
{ | ||
$this->alertifySessionHandler = $alertifySessionHandler; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function initRuntime(\Twig_Environment $environment) | ||
{ | ||
$this->environment = $environment; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName() | ||
{ | ||
return 'alertify'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFilters() | ||
{ | ||
return [ | ||
new \Twig_SimpleFilter('alertify', [$this, 'alertifyFilter'], ['needs_environment' => true, 'is_safe' => ['html']]), | ||
]; | ||
} | ||
|
||
/** | ||
* Alertify filter. | ||
* | ||
* @param \Twig_Environment $environment | ||
* @param Session $session | ||
* | ||
* @return string | ||
*/ | ||
public function alertifyFilter($environment, Session $session) | ||
{ | ||
return $this->alertifySessionHandler->handle($session); | ||
} | ||
} |