HummingBirdAnimeClient/src/Ion/View/HtmlView.php

70 lines
1.6 KiB
PHP
Raw Normal View History

<?php declare(strict_types=1);
/**
2020-03-12 11:45:11 -04:00
* Hummingbird Anime List Client
*
2020-03-12 11:45:11 -04:00
* An API client for Kitsu to manage anime and manga watch lists
*
2021-02-04 11:57:01 -05:00
* PHP version 8
*
2022-03-04 15:50:35 -05:00
* @copyright 2015 - 2022 Timothy J. Warren <tim@timshome.page>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2022-03-04 15:50:35 -05:00
* @link https://git.timshome.page/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\Ion\View;
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
2020-07-31 16:22:32 -04:00
use Laminas\Diactoros\Response\HtmlResponse;
use Throwable;
2020-04-24 14:14:52 -04:00
use const EXTR_OVERWRITE;
/**
* View class for outputting HTML
*/
class HtmlView extends HttpView
{
2020-07-31 16:22:32 -04:00
use ContainerAware;
/**
* Response mime type
*/
2020-04-21 19:22:56 -04:00
protected string $contentType = 'text/html';
/**
* Create the Html View
*/
public function __construct()
{
2020-07-31 16:22:32 -04:00
parent::__construct();
$this->setContainer(func_get_arg(0));
2020-07-31 16:22:32 -04:00
$this->response = new HtmlResponse('');
}
/**
* Render a basic html Template
*
* @throws Throwable
*/
public function renderTemplate(string $path, array $data): string
{
$helper = $this->container->get('html-helper');
$data['component'] = $this->container->get('component-helper');
$data['helper'] = $helper;
$data['escape'] = $helper->escape();
$data['container'] = $this->container;
ob_start();
2020-04-24 14:14:52 -04:00
extract($data, EXTR_OVERWRITE);
include_once $path;
$rawBuffer = ob_get_clean();
$buffer = ($rawBuffer === FALSE) ? '' : $rawBuffer;
// Very basic html minify, that won't affect content between html tags
2021-02-12 17:52:58 -05:00
return preg_replace('/>\s+</', '> <', $buffer) ?? $buffer;
}
}
// End of HtmlView.php