diff --git a/src/Laravel/Component/FlasherComponent.php b/src/Laravel/Component/FlasherComponent.php new file mode 100644 index 00000000..2872f21f --- /dev/null +++ b/src/Laravel/Component/FlasherComponent.php @@ -0,0 +1,51 @@ + + */ + +namespace Flasher\Laravel\Component; + +use Flasher\Prime\FlasherInterface; +use Illuminate\View\Component; + +class FlasherComponent extends Component +{ + /** + * @var array + */ + public $criteria; + + /** + * @var array + */ + public $context; + + /** + * @var FlasherInterface + */ + private $flasher; + + /** + * @param array $criteria + * @param array $context + */ + public function __construct(FlasherInterface $flasher, $criteria = null, $context = null) + { + $this->flasher = $flasher; + $this->criteria = $criteria; + $this->context = $context; + } + + /** + * {@inheritdoc} + */ + public function render() + { + $criteria = json_decode($this->criteria, true) ?: array(); + $context = json_decode($this->context, true) ?: array(); + + return $this->flasher->render($criteria, 'html', $context); + } +}