- added error_reporting if devMode
- added TestController.php - added temp function to load controllers (should load later via seo urls) - added baseTemplate for default look and feel - removed adding file extension -> always need to be .php!
This commit is contained in:
parent
9be884c8e4
commit
7ba4e3e0a6
8 changed files with 97 additions and 14 deletions
|
@ -40,7 +40,7 @@ $config->setMail([
|
||||||
// all themes are in __DIR__/public/theme/
|
// all themes are in __DIR__/public/theme/
|
||||||
$config->setRender([
|
$config->setRender([
|
||||||
'theme' => 'default', //very important! it will search for a folder with this name.
|
'theme' => 'default', //very important! it will search for a folder with this name.
|
||||||
'baseFile' => 'base.php', //this will called after all templates are rendered...
|
'baseFile' => 'base', //this will called after all templates are rendered...
|
||||||
'useCache' => false, //is only on big systems good
|
'useCache' => false, //is only on big systems good
|
||||||
'cacheName' => 'defaultCache', //this is for bigger systems, ignore it
|
'cacheName' => 'defaultCache', //this is for bigger systems, ignore it
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -4,4 +4,6 @@
|
||||||
$modules = [];
|
$modules = [];
|
||||||
|
|
||||||
// register controllers that can handle templates ;) need to have a render function for this
|
// register controllers that can handle templates ;) need to have a render function for this
|
||||||
$controllers = [];
|
$controllers = [
|
||||||
|
'test' => \Modules\TestController::class
|
||||||
|
];
|
|
@ -22,6 +22,11 @@ if ($config->isMaintenance()) {
|
||||||
echo 'Currently not available';
|
echo 'Currently not available';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
//if devMode is on show all errors!
|
||||||
|
if ($config->isDevMode()) {
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
ini_set('error_reporting', E_ALL);
|
||||||
|
}
|
||||||
$venom = new Venom();
|
$venom = new Venom();
|
||||||
$venom->initModules($modules);
|
$venom->initModules($modules);
|
||||||
$venom->initControllers($controllers);
|
$venom->initControllers($controllers);
|
||||||
|
|
|
@ -22,10 +22,18 @@ class Venom
|
||||||
{
|
{
|
||||||
// we need to load the current controller and the current start template.
|
// we need to load the current controller and the current start template.
|
||||||
// after this we can start the renderer
|
// after this we can start the renderer
|
||||||
$this->renderer->init(null);
|
$this->renderer->init($this->findController());
|
||||||
$this->renderer->render();
|
$this->renderer->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function findController(): ?RenderController
|
||||||
|
{
|
||||||
|
if (isset($_GET['cl'], $this->controllers[$_GET['cl']])) {
|
||||||
|
return $this->controllers[$_GET['cl']];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function initModules(array $modules): void
|
public function initModules(array $modules): void
|
||||||
{
|
{
|
||||||
foreach ($modules as $key => $moduleClass) {
|
foreach ($modules as $key => $moduleClass) {
|
||||||
|
@ -50,9 +58,4 @@ class Venom
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function findController()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -8,7 +8,7 @@ interface RenderController
|
||||||
{
|
{
|
||||||
public function register(): bool;
|
public function register(): bool;
|
||||||
|
|
||||||
public function render(): string;
|
public function render(VenomRenderer $renderer): bool;
|
||||||
|
|
||||||
public function getTemplate(): string;
|
public function getTemplate(): string;
|
||||||
}
|
}
|
|
@ -12,6 +12,7 @@ class VenomRenderer
|
||||||
private Venom $venom;
|
private Venom $venom;
|
||||||
private ?RenderController $controller;
|
private ?RenderController $controller;
|
||||||
private string $templateData = '';
|
private string $templateData = '';
|
||||||
|
private array $vars = [];
|
||||||
private string $baseTemplate = '';
|
private string $baseTemplate = '';
|
||||||
private string $templateDir = '';
|
private string $templateDir = '';
|
||||||
private string $assetsDir = '';
|
private string $assetsDir = '';
|
||||||
|
@ -25,8 +26,8 @@ class VenomRenderer
|
||||||
{
|
{
|
||||||
if ($this->controller) {
|
if ($this->controller) {
|
||||||
ob_start();
|
ob_start();
|
||||||
$this->controller->render();
|
$this->controller->render($this);
|
||||||
$this->templateData = ob_end_clean();
|
$this->templateData = ob_get_clean();
|
||||||
}
|
}
|
||||||
$this->loadBasicTemplate();
|
$this->loadBasicTemplate();
|
||||||
}
|
}
|
||||||
|
@ -36,16 +37,45 @@ class VenomRenderer
|
||||||
if (file_exists($this->templateDir . $this->baseTemplate)) {
|
if (file_exists($this->templateDir . $this->baseTemplate)) {
|
||||||
include_once $this->templateDir . $this->baseTemplate;
|
include_once $this->templateDir . $this->baseTemplate;
|
||||||
} else {
|
} else {
|
||||||
echo "Base Template not found...";
|
echo 'Base Template not found...';
|
||||||
echo $this->templateData;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function will load a template (without extension!) into a variable and return the content
|
||||||
|
* @param $template
|
||||||
|
* @param string $varName
|
||||||
|
* @return false|string
|
||||||
|
*/
|
||||||
|
public function includeTemplate($template, $varName = '')
|
||||||
|
{
|
||||||
|
$template .= '.php';
|
||||||
|
if (file_exists($this->templateDir . $template)) {
|
||||||
|
ob_start();
|
||||||
|
include_once $this->templateDir . $template;
|
||||||
|
$data = ob_get_clean();
|
||||||
|
$this->vars[$varName] = $data;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
$this->vars[$varName] = '';
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addVar($name, $value)
|
||||||
|
{
|
||||||
|
$this->vars[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVar($name)
|
||||||
|
{
|
||||||
|
return $this->vars[$name];
|
||||||
|
}
|
||||||
|
|
||||||
public function init(?RenderController $controller): void
|
public function init(?RenderController $controller): void
|
||||||
{
|
{
|
||||||
$this->controller = $controller;
|
$this->controller = $controller;
|
||||||
$data = Config::getInstance()->getRenderer();
|
$data = Config::getInstance()->getRenderer();
|
||||||
$this->baseTemplate = $data['baseFile'] ?? 'base.php';
|
$this->baseTemplate = $data['baseFile'] . '.php' ?? 'base.php';
|
||||||
$this->templateDir = __DIR__ . '/../../../tpl/' . $data['theme'] . '/';
|
$this->templateDir = __DIR__ . '/../../../tpl/' . $data['theme'] . '/';
|
||||||
$this->assetsDir = __DIR__ . '/../../../public/theme/' . $data['theme'] . '/';
|
$this->assetsDir = __DIR__ . '/../../../public/theme/' . $data['theme'] . '/';
|
||||||
}
|
}
|
||||||
|
|
27
src/modules/TestController.php
Normal file
27
src/modules/TestController.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace Modules;
|
||||||
|
|
||||||
|
|
||||||
|
use Venom\Views\RenderController;
|
||||||
|
use Venom\Views\VenomRenderer;
|
||||||
|
|
||||||
|
class TestController implements RenderController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function register(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render(VenomRenderer $renderer): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplate(): string
|
||||||
|
{
|
||||||
|
return 'base.php';
|
||||||
|
}
|
||||||
|
}
|
16
tpl/default/base.php
Normal file
16
tpl/default/base.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>VenomBase</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
VenomCMS
|
||||||
|
</header>
|
||||||
|
<?= $this->templateData ?>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue