- 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:
VersusTune 2020-04-03 13:19:26 +02:00
commit 7ba4e3e0a6
8 changed files with 97 additions and 14 deletions

View file

@ -22,10 +22,18 @@ class Venom
{
// we need to load the current controller and the current start template.
// after this we can start the renderer
$this->renderer->init(null);
$this->renderer->init($this->findController());
$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
{
foreach ($modules as $key => $moduleClass) {
@ -50,9 +58,4 @@ class Venom
{
}
private function findController()
{
}
}

View file

@ -8,7 +8,7 @@ interface RenderController
{
public function register(): bool;
public function render(): string;
public function render(VenomRenderer $renderer): bool;
public function getTemplate(): string;
}

View file

@ -12,6 +12,7 @@ class VenomRenderer
private Venom $venom;
private ?RenderController $controller;
private string $templateData = '';
private array $vars = [];
private string $baseTemplate = '';
private string $templateDir = '';
private string $assetsDir = '';
@ -25,8 +26,8 @@ class VenomRenderer
{
if ($this->controller) {
ob_start();
$this->controller->render();
$this->templateData = ob_end_clean();
$this->controller->render($this);
$this->templateData = ob_get_clean();
}
$this->loadBasicTemplate();
}
@ -36,16 +37,45 @@ class VenomRenderer
if (file_exists($this->templateDir . $this->baseTemplate)) {
include_once $this->templateDir . $this->baseTemplate;
} else {
echo "Base Template not found...";
echo $this->templateData;
echo 'Base Template not found...';
}
}
/**
* 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
{
$this->controller = $controller;
$data = Config::getInstance()->getRenderer();
$this->baseTemplate = $data['baseFile'] ?? 'base.php';
$this->baseTemplate = $data['baseFile'] . '.php' ?? 'base.php';
$this->templateDir = __DIR__ . '/../../../tpl/' . $data['theme'] . '/';
$this->assetsDir = __DIR__ . '/../../../public/theme/' . $data['theme'] . '/';
}

View 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';
}
}