diff --git a/.gitignore b/.gitignore index cc39ada..b51d797 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ var/cache/* !var/log/.gitkeep var/log/* .env -.vscode \ No newline at end of file +.vscode +cache/ +composer.lock \ No newline at end of file diff --git a/composer.json b/composer.json index 95ea72b..61ad7ce 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "symfony/http-kernel": "^6.3", "bramus/router": "~1.6", "filp/whoops": "^2.15", - "symfony/var-dumper": "^6.3" + "symfony/var-dumper": "^6.3", + "eftec/bladeone": "^4.9" }, "repositories": [ { diff --git a/composer.lock b/composer.lock index c7d692a..cf18f11 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3000634f1714c2829d26e8342521cded", + "content-hash": "08bcddce7c92998b46122aa9d64c7ad6", "packages": [ { "name": "bramus/router", @@ -57,6 +57,65 @@ }, "time": "2021-11-18T19:24:07+00:00" }, + { + "name": "eftec/bladeone", + "version": "4.9", + "source": { + "type": "git", + "url": "https://github.com/EFTEC/BladeOne.git", + "reference": "019036c226086fbe7591360d260067c5d82400ca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/EFTEC/BladeOne/zipball/019036c226086fbe7591360d260067c5d82400ca", + "reference": "019036c226086fbe7591360d260067c5d82400ca", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=7.2.5" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.23" + }, + "suggest": { + "eftec/bladeonehtml": "Extension to create forms", + "ext-mbstring": "This extension is used if it's active" + }, + "bin": [ + "lib/bladeonecli" + ], + "type": "library", + "autoload": { + "psr-4": { + "eftec\\bladeone\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jorge Patricio Castro Castillo", + "email": "jcastro@eftec.cl" + } + ], + "description": "The standalone version Blade Template Engine from Laravel in a single php file", + "homepage": "https://github.com/EFTEC/BladeOne", + "keywords": [ + "blade", + "php", + "template", + "templating", + "view" + ], + "support": { + "issues": "https://github.com/EFTEC/BladeOne/issues", + "source": "https://github.com/EFTEC/BladeOne/tree/4.9" + }, + "time": "2023-05-01T12:48:42+00:00" + }, { "name": "evenement/evenement", "version": "v3.0.2", diff --git a/src/Controllers/Home.php b/src/Controllers/Home.php index 2ab43da..4f70309 100644 --- a/src/Controllers/Home.php +++ b/src/Controllers/Home.php @@ -3,12 +3,14 @@ namespace App\Controllers; use App\Core\Controllers\Controller; +use DateTimeZone; class Home extends Controller { public function index() { - $html = $this->renderView("index", []); + $date = new \DateTime('now', new DateTimeZone("Europe/Paris")); + $html = $this->renderView("index", ["date" => $date->format("d/m/Y H:i:s")]); $this->render($html); } } diff --git a/src/Core/Controllers/Controller.php b/src/Core/Controllers/Controller.php index 145189d..9296e83 100644 --- a/src/Core/Controllers/Controller.php +++ b/src/Core/Controllers/Controller.php @@ -2,6 +2,7 @@ namespace App\Core\Controllers; +use App\Core\Kernel\Templating; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -58,15 +59,7 @@ abstract class Controller */ public function renderView($view, $params = []): string { - extract($params); - $path = ROOT . DS . "views" . DS . str_replace(".", DS, $view) . ".php"; - ob_start(); - try { - include $path; - } catch (\Exception $e) { - } - $buffer = ltrim(ob_get_clean()); - return $buffer; + return Templating::getInstance()->render($view, $params); } /** diff --git a/src/Core/Kernel/Application.php b/src/Core/Kernel/Application.php index 5ea80f7..9d48058 100644 --- a/src/Core/Kernel/Application.php +++ b/src/Core/Kernel/Application.php @@ -88,7 +88,6 @@ class Application public function handle() { - ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE); try { $this->router->run(); } catch (\Exception $ex) { diff --git a/src/Core/Kernel/Templating.php b/src/Core/Kernel/Templating.php new file mode 100644 index 0000000..b278a2a --- /dev/null +++ b/src/Core/Kernel/Templating.php @@ -0,0 +1,33 @@ +_views = ROOT . DS . "views"; + $this->_cache = ROOT . DS . "cache"; + $this->_blade = new BladeOne($this->_views, $this->_cache, BladeOne::MODE_AUTO); + } + + public static function getInstance() + { + if (self::$_instance == null) { + self::$_instance = new Templating(); + } + return self::$_instance; + } + + public function render(string $template, array $params = []): string + { + return $this->_blade->run($template, $params); + } +} diff --git a/views/index.php b/views/index.blade.php similarity index 97% rename from views/index.php rename to views/index.blade.php index 7d1037a..47e2f44 100644 --- a/views/index.php +++ b/views/index.blade.php @@ -30,6 +30,7 @@

"It works!"

+

{{ $date }}