HummingBirdAnimeClient/src/Ion/View/HtmlView.php

77 lines
1.8 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
*
2020-03-12 11:45:11 -04:00
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
2021-01-13 01:52:03 -05:00
* @copyright 2015 - 2021 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2020-03-12 11:45:11 -04:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\Ion\View;
2020-07-31 16:22:32 -04:00
use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Di\ContainerInterface;
2020-07-31 16:22:32 -04:00
use Laminas\Diactoros\Response\HtmlResponse;
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
*
* @var string
*/
2020-04-21 19:22:56 -04:00
protected string $contentType = 'text/html';
/**
* Create the Html View
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
2020-07-31 16:22:32 -04:00
parent::__construct();
$this->setContainer($container);
$this->response = new HtmlResponse('');
}
/**
* Render a basic html Template
*
* @param string $path
* @param array $data
* @return string
2021-02-11 19:54:22 -05:00
* @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