sarga/packages/Webkul/Theme/src/ViewRenderEventManager.php

68 lines
1.2 KiB
PHP
Raw Normal View History

2018-12-04 11:05:30 +00:00
<?php
namespace Webkul\Theme;
use Illuminate\Support\Facades\Event;
class ViewRenderEventManager
{
/**
* Contains all themes
*
* @var array
*/
protected $templates = [];
/**
* Paramters passed with event
*
* @var array
*/
protected $params;
/**
* Fires event for rendering template
*
* @param string $eventName
* @param array|null $params
* @return string
*/
public function handleRenderEvent($eventName, $params = null)
{
$this->params = $params ?? [];
Event::fire($eventName, $this->params);
2018-12-04 11:05:30 +00:00
return $this->templates;
}
/**
* Add templates for render
*
* @param string $template
* @return void
*/
public function addTemplate($template)
{
array_push($this->templates, $template);
}
/**
* Renders templates
*
* @return string
*/
public function render()
{
$string = "";
foreach ($this->templates as $template) {
if (view()->exists($template)) {
$string .= view($template, $this->params)->render();
}
}
return $string;
}
}