2020-06-16 08:22:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Benzine\Controllers;
|
|
|
|
|
|
2020-06-19 07:53:59 +00:00
|
|
|
use Slim\Psr7\Request;
|
|
|
|
|
use Slim\Psr7\Response;
|
2020-06-16 08:22:47 +00:00
|
|
|
use Slim\Views\Twig;
|
|
|
|
|
|
|
|
|
|
abstract class HtmlController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/** @var Twig */
|
|
|
|
|
protected $twig;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
Twig $twig
|
|
|
|
|
) {
|
|
|
|
|
$this->twig = $twig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function renderInlineCss(array $files)
|
|
|
|
|
{
|
|
|
|
|
$css = '';
|
|
|
|
|
foreach ($files as $file) {
|
|
|
|
|
$css .= file_get_contents($file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "<style>{$css}</style>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function renderHtml(Request $request, Response $response, string $template, array $parameters = []): Response
|
|
|
|
|
{
|
|
|
|
|
// If the path ends in .json, return the parameters
|
|
|
|
|
if ('.json' == substr($request->getUri()->getPath(), -5, 5)) {
|
|
|
|
|
return $this->jsonResponse($parameters, $request, $response);
|
|
|
|
|
}
|
2020-06-18 17:24:31 +00:00
|
|
|
|
2020-06-16 08:22:47 +00:00
|
|
|
return $this->twig->render(
|
|
|
|
|
$response,
|
|
|
|
|
$template,
|
|
|
|
|
$parameters
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|