Skip to content

Instantly share code, notes, and snippets.

@felixdorn
Created November 7, 2019 12:10
Show Gist options
  • Save felixdorn/c192d3b21a0ccc41d230655bd5def0e4 to your computer and use it in GitHub Desktop.
Save felixdorn/c192d3b21a0ccc41d230655bd5def0e4 to your computer and use it in GitHub Desktop.
<?php
namespace Felix\Framework\Renderer;
use Felix\Flash\Flasher;
use Tamtamchik\SimpleFlash\Flash;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class FlashExtension extends AbstractExtension
{
public function getFunctions()
{
$htmlSafe = [
'is_safe' => [
'html' => true
]
];
return [
new TwigFunction('getFlashed', [$this, 'getFlashed'], $htmlSafe),
new TwigFunction('getFlashedErrors', [$this, 'getFlashedErrors'],$htmlSafe),
new TwigFunction('getFlashedSuccess', [$this, 'getFlashedSuccess'], $htmlSafe),
new TwigFunction('getFlashedWarning', [$this, 'getFlashedWarning'], $htmlSafe),
new TwigFunction('getFlashedInfo', [$this, 'getFlashedInfo'], $htmlSafe),
] ;
}
public function getFlashed() {
return Flasher::getInstance()->display();
}
public function getFlashedErrors() {
return Flasher::getInstance()->display('error');
}
public function getFlashedSuccess()
{
return Flasher::getInstance()->display('success');
}
public function getFlashedWarning()
{
return Flasher::getInstance()->display('warning');
}
public function getFlashedInfo()
{
return Flash::display('info');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment