grocy/helpers/SlimBladeView.php
2026-03-04 20:29:03 +01:00

35 lines
756 B
PHP

<?php
namespace Grocy\Helpers;
use Jenssegers\Blade\Blade;
use Psr\Http\Message\ResponseInterface;
class SlimBladeView
{
public function __construct(string $viewPaths, string $cachePath)
{
$this->ViewPaths = $viewPaths;
$this->CachePath = $cachePath;
}
protected $ViewPaths;
protected $CachePath;
protected $ViewData = [];
public function render(ResponseInterface $response, string $template, array $data = [])
{
$data = array_merge($this->ViewData, $data);
$renderer = new Blade($this->ViewPaths, $this->CachePath, null);
$output = $renderer->make($template, $data)->render();
$response->getBody()->write($output);
return $response;
}
public function set(string $key, mixed $value)
{
$this->ViewData[$key] = $value;
}
}