still wip
This commit is contained in:
parent
d21ca3e6ab
commit
9be884c8e4
12 changed files with 261 additions and 39 deletions
|
|
@ -27,16 +27,6 @@ class Config
|
|||
return self::$instance;
|
||||
}
|
||||
|
||||
public function setVersion(float $param): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
$this->version = $param;
|
||||
} else {
|
||||
trigger_error('try to write closed config!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function setDatabase(array $array): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
|
|
@ -55,15 +45,6 @@ class Config
|
|||
}
|
||||
}
|
||||
|
||||
public function setMail(array $array): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
$this->mail = $array;
|
||||
} else {
|
||||
trigger_error('try to write closed config!');
|
||||
}
|
||||
}
|
||||
|
||||
public function setRender(array $array): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
|
|
@ -82,18 +63,21 @@ class Config
|
|||
}
|
||||
}
|
||||
|
||||
public function setDevMode(bool $mode): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
$this->devMode = $mode;
|
||||
}
|
||||
}
|
||||
|
||||
public function getVersion(): float
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
public function setVersion(float $param): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
$this->version = $param;
|
||||
} else {
|
||||
trigger_error('try to write closed config!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getApi(): array
|
||||
{
|
||||
return $this->api;
|
||||
|
|
@ -104,6 +88,15 @@ class Config
|
|||
return $this->mail;
|
||||
}
|
||||
|
||||
public function setMail(array $array): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
$this->mail = $array;
|
||||
} else {
|
||||
trigger_error('try to write closed config!');
|
||||
}
|
||||
}
|
||||
|
||||
public function getRenderer(): array
|
||||
{
|
||||
return $this->renderer;
|
||||
|
|
@ -119,6 +112,15 @@ class Config
|
|||
return $this->devMode;
|
||||
}
|
||||
|
||||
public function setDevMode(bool $mode): void
|
||||
{
|
||||
if ($this->isWriteable) {
|
||||
$this->devMode = $mode;
|
||||
} else {
|
||||
trigger_error('try to write closed config!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* function to close the write mode... this make sure after the config is init no other tool can write to it!
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace Venom\Database;
|
|||
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
/**
|
||||
* Singleton DatabaseHandler... make sure we only have one connection to the database..
|
||||
|
|
@ -12,6 +13,14 @@ use PDO;
|
|||
*/
|
||||
class DatabaseHandler
|
||||
{
|
||||
// constants
|
||||
public const DB_TYPE = 'type';
|
||||
public const DB_HOST = 'host';
|
||||
public const DB_PORT = 'port';
|
||||
public const DB_USER = 'user';
|
||||
public const DB_PASSWORD = 'pw';
|
||||
public const DB_DB = 'db';
|
||||
public const DB_EXTRA = 'extra';
|
||||
private static ?self $instance = null;
|
||||
private ?PDO $db = null;
|
||||
|
||||
|
|
@ -30,7 +39,35 @@ class DatabaseHandler
|
|||
return;
|
||||
}
|
||||
$dsn = '%s:host=%s;dbname=%s;port=%s';
|
||||
|
||||
$connectString = sprintf($dsn, $data[self::DB_TYPE], $data[self::DB_HOST], $data[self::DB_DB], $data[self::DB_PORT] . $data[self::DB_EXTRA]);
|
||||
try {
|
||||
$this->db = new PDO($connectString, $data[self::DB_USER], $data[self::DB_PASSWORD]);
|
||||
} catch (PDOException $e) {
|
||||
trigger_error($e->getMessage());
|
||||
die($e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public function getOne(string $query, array $args): ?array
|
||||
{
|
||||
$data = $this->getAll($query, $args);
|
||||
if (count($data) > 0) {
|
||||
return $data[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getAll(string $query, array $args): array
|
||||
{
|
||||
$stmt = $this->db->prepare($query);
|
||||
$stmt->setFetchMode(PDO::FETCH_CLASS, DatabaseObject::class);
|
||||
$stmt->execute($args);
|
||||
return $stmt->fetchAll();
|
||||
}
|
||||
|
||||
public function execute(string $query, array $args): void
|
||||
{
|
||||
$stmt = $this->db->prepare($query);
|
||||
$stmt->execute($args);
|
||||
}
|
||||
}
|
||||
12
src/Venom/Module.php
Normal file
12
src/Venom/Module.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Venom;
|
||||
|
||||
|
||||
interface Module
|
||||
{
|
||||
public function register(): bool;
|
||||
|
||||
public function init(): void;
|
||||
}
|
||||
16
src/Venom/Registry.php
Normal file
16
src/Venom/Registry.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Venom;
|
||||
|
||||
|
||||
/**
|
||||
* Singleton Class... hold current URL => can
|
||||
* @package Venom
|
||||
*/
|
||||
class Registry
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,55 @@
|
|||
namespace Venom;
|
||||
|
||||
|
||||
use Venom\Views\RenderController;
|
||||
use Venom\Views\VenomRenderer;
|
||||
|
||||
class Venom
|
||||
{
|
||||
private VenomRenderer $renderer;
|
||||
private array $controllers = [];
|
||||
private array $modules = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->renderer = new VenomRenderer($this);
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
// 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->render();
|
||||
}
|
||||
|
||||
public function initModules(array $modules): void
|
||||
{
|
||||
foreach ($modules as $key => $moduleClass) {
|
||||
$module = new $moduleClass;
|
||||
if ($module instanceof Module && $module->register()) {
|
||||
$this->modules[$key] = $module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function initControllers(array $controllers): void
|
||||
{
|
||||
foreach ($controllers as $key => $controllerClass) {
|
||||
$controller = new $controllerClass;
|
||||
if ($controller instanceof RenderController && $controller->register()) {
|
||||
$this->controllers[$key] = $controller;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function prepare()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function findController()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
14
src/Venom/Views/RenderController.php
Normal file
14
src/Venom/Views/RenderController.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Venom\Views;
|
||||
|
||||
|
||||
interface RenderController
|
||||
{
|
||||
public function register(): bool;
|
||||
|
||||
public function render(): string;
|
||||
|
||||
public function getTemplate(): string;
|
||||
}
|
||||
52
src/Venom/Views/VenomRenderer.php
Normal file
52
src/Venom/Views/VenomRenderer.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Venom\Views;
|
||||
|
||||
|
||||
use Venom\Config;
|
||||
use Venom\Venom;
|
||||
|
||||
class VenomRenderer
|
||||
{
|
||||
private Venom $venom;
|
||||
private ?RenderController $controller;
|
||||
private string $templateData = '';
|
||||
private string $baseTemplate = '';
|
||||
private string $templateDir = '';
|
||||
private string $assetsDir = '';
|
||||
|
||||
public function __construct(Venom $venom)
|
||||
{
|
||||
$this->venom = $venom;
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
{
|
||||
if ($this->controller) {
|
||||
ob_start();
|
||||
$this->controller->render();
|
||||
$this->templateData = ob_end_clean();
|
||||
}
|
||||
$this->loadBasicTemplate();
|
||||
}
|
||||
|
||||
public function loadBasicTemplate(): void
|
||||
{
|
||||
if (file_exists($this->templateDir . $this->baseTemplate)) {
|
||||
include_once $this->templateDir . $this->baseTemplate;
|
||||
} else {
|
||||
echo "Base Template not found...";
|
||||
echo $this->templateData;
|
||||
}
|
||||
}
|
||||
|
||||
public function init(?RenderController $controller): void
|
||||
{
|
||||
$this->controller = $controller;
|
||||
$data = Config::getInstance()->getRenderer();
|
||||
$this->baseTemplate = $data['baseFile'] ?? 'base.php';
|
||||
$this->templateDir = __DIR__ . '/../../../tpl/' . $data['theme'] . '/';
|
||||
$this->assetsDir = __DIR__ . '/../../../public/theme/' . $data['theme'] . '/';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue