2020-03-11 23:04:01 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
2020-03-12 11:45:11 -04:00
|
|
|
* Hummingbird Anime List Client
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-03-12 11:45:11 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-04-10 15:39:39 -04:00
|
|
|
* PHP version 7.4
|
2020-03-11 23:04:01 -04:00
|
|
|
*
|
2020-03-12 11:45:11 -04:00
|
|
|
* @package HummingbirdAnimeClient
|
2020-03-11 23:04:01 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2020-03-12 11:45:11 -04:00
|
|
|
* @copyright 2015 - 2020 Timothy J. Warren
|
2020-03-11 23:04:01 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-08-04 09:30:21 -04:00
|
|
|
* @version 5.1
|
2020-03-12 11:45:11 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2020-03-11 23:04:01 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\Ion\View;
|
|
|
|
|
|
|
|
use Aura\Html\HelperLocator;
|
2020-07-31 16:22:32 -04:00
|
|
|
use Aviat\Ion\Di\ContainerAware;
|
2020-03-11 23:04:01 -04:00
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
|
|
|
use Aviat\Ion\Di\Exception\ContainerException;
|
|
|
|
use Aviat\Ion\Di\Exception\NotFoundException;
|
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;
|
2020-03-11 23:04:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* View class for outputting HTML
|
|
|
|
*/
|
|
|
|
class HtmlView extends HttpView {
|
2020-07-31 16:22:32 -04:00
|
|
|
use ContainerAware;
|
2020-03-11 23:04:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HTML generator/escaper helper
|
|
|
|
*
|
|
|
|
* @var HelperLocator
|
|
|
|
*/
|
2020-04-21 19:22:56 -04:00
|
|
|
protected HelperLocator $helper;
|
2020-03-11 23:04:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Response mime type
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2020-04-21 19:22:56 -04:00
|
|
|
protected string $contentType = 'text/html';
|
2020-03-11 23:04:01 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the Html View
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container
|
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
|
|
|
*/
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
2020-07-31 16:22:32 -04:00
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->setContainer($container);
|
2020-03-11 23:04:01 -04:00
|
|
|
$this->helper = $container->get('html-helper');
|
2020-07-31 16:22:32 -04:00
|
|
|
$this->response = new HtmlResponse('');
|
2020-03-11 23:04:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a basic html Template
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param array $data
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function renderTemplate(string $path, array $data): string
|
|
|
|
{
|
|
|
|
$data['helper'] = $this->helper;
|
|
|
|
$data['escape'] = $this->helper->escape();
|
|
|
|
$data['container'] = $this->container;
|
|
|
|
|
|
|
|
ob_start();
|
2020-04-24 14:14:52 -04:00
|
|
|
extract($data, EXTR_OVERWRITE);
|
2020-03-11 23:04:01 -04:00
|
|
|
include_once $path;
|
|
|
|
$buffer = ob_get_clean();
|
|
|
|
|
|
|
|
|
|
|
|
// Very basic html minify, that won't affect content between html tags
|
2020-04-24 14:14:52 -04:00
|
|
|
$buffer = preg_replace('/>\s+</', '> <', $buffer);
|
2020-03-11 23:04:01 -04:00
|
|
|
|
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// End of HtmlView.php
|