From c8593b7414d1d8d42e3b9909b8ff753661cbf9d1 Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 3 Jan 2018 16:49:37 +0100 Subject: [PATCH] Hook up the templating system and router better. --- composer.json | 2 +- composer.lock | 10 +++++----- misuzu.php | 4 +++- routes.php | 7 +++++++ server.php | 13 +++++++++++++ src/Application.php | 6 ------ src/Controllers/Controller.php | 8 ++++++++ src/Controllers/HomeController.php | 17 +++++++++++++++++ src/TemplateEngine.php | 8 ++++++-- views/nova/home/landing.twig | 2 +- views/nova/home/master.twig | 1 + 11 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 routes.php create mode 100644 server.php create mode 100644 src/Controllers/Controller.php create mode 100644 src/Controllers/HomeController.php create mode 100644 views/nova/home/master.twig diff --git a/composer.json b/composer.json index 50047350..e6a943f8 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ }, "require": { "php": ">=7.2", - "flashwave/aitemu": "dev-master#3ddb8147ed809cfba59c46f6e3d3af9fb2a86ace", + "flashwave/aitemu": "dev-master#7997543717d996b56938d5050ea497d62eb71f2e", "twig/twig": "~2.4", "nesbot/carbon": "~1.22", "illuminate/database": "~5.5", diff --git a/composer.lock b/composer.lock index 00e8c856..d514c57e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "4c9cc87ad91ef38f4333d4e9e80a0f39", + "content-hash": "fd3ae2504a3c120f29942565ef7cd403", "packages": [ { "name": "doctrine/annotations", @@ -590,12 +590,12 @@ "source": { "type": "git", "url": "https://github.com/flashwave/aitemu.git", - "reference": "3ddb8147ed809cfba59c46f6e3d3af9fb2a86ace" + "reference": "7997543717d996b56938d5050ea497d62eb71f2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/flashwave/aitemu/zipball/3ddb8147ed809cfba59c46f6e3d3af9fb2a86ace", - "reference": "3ddb8147ed809cfba59c46f6e3d3af9fb2a86ace", + "url": "https://api.github.com/repos/flashwave/aitemu/zipball/7997543717d996b56938d5050ea497d62eb71f2e", + "reference": "7997543717d996b56938d5050ea497d62eb71f2e", "shasum": "" }, "require": { @@ -616,7 +616,7 @@ ], "description": "PHP router library, mainly for personal use.", "homepage": "https://github.com/flashwave/aitemu", - "time": "2018-01-01T22:36:19+00:00" + "time": "2018-01-03T15:36:23+00:00" }, { "name": "illuminate/container", diff --git a/misuzu.php b/misuzu.php index 287dcdf3..3bc00b0b 100644 --- a/misuzu.php +++ b/misuzu.php @@ -3,4 +3,6 @@ namespace Misuzu; require_once 'vendor/autoload.php'; -Application::start()->debug(IO\Directory::exists(__DIR__ . '/vendor/phpunit/phpunit')); +$app = Application::start(); +$app->debug(IO\Directory::exists(__DIR__ . '/vendor/phpunit/phpunit')); +$app->router->add(include_once __DIR__ . '/routes.php'); diff --git a/routes.php b/routes.php new file mode 100644 index 00000000..c9bfbb25 --- /dev/null +++ b/routes.php @@ -0,0 +1,7 @@ +addModule('templating', new TemplateEngine); $this->addModule('config', new ConfigManager($config)); - $this->debug(true); - $this->templating->addFilter('json_decode'); $this->templating->addFilter('byte_symbol'); $this->templating->addFunction('byte_symbol'); $this->templating->addFunction('session_id'); $this->templating->addFunction('config', [$this->config, 'get']); $this->templating->addFunction('route', [$this->router, 'url']); - $this->templating->addFunction('git_hash', [Application::class, 'gitCommitHash']); - $this->templating->addFunction('git_branch', [Application::class, 'gitBranch']); $this->templating->addPath('nova', __DIR__ . '/../views/nova'); - - echo $this->templating->render('home.landing'); } public function __destruct() diff --git a/src/Controllers/Controller.php b/src/Controllers/Controller.php new file mode 100644 index 00000000..0ba9b89b --- /dev/null +++ b/src/Controllers/Controller.php @@ -0,0 +1,8 @@ +templating; + + $twig->addFunction('git_hash', [Application::class, 'gitCommitHash']); + $twig->addFunction('git_branch', [Application::class, 'gitBranch']); + + return $twig->render('home.landing'); + } +} diff --git a/src/TemplateEngine.php b/src/TemplateEngine.php index d025f9a5..79cb5b0b 100644 --- a/src/TemplateEngine.php +++ b/src/TemplateEngine.php @@ -19,11 +19,15 @@ class TemplateEngine private const FILE_EXTENSION = '.twig'; /** - * Container for twig. + * Instance of the Twig Environment. * @var Twig_Environment */ private $twig; + /** + * Instance a Twig loader, probably only compatible with the Filesystem type. + * @var Twig_Loader_Filesystem + */ private $loader; /** @@ -135,7 +139,7 @@ class TemplateEngine * @param array $vars * @return string */ - public function render(string $path, array $vars = null): string + public function render(string $path, ?array $vars = null): string { $path = self::fixPath($path); diff --git a/views/nova/home/landing.twig b/views/nova/home/landing.twig index b9d26fd2..29d7c389 100644 --- a/views/nova/home/landing.twig +++ b/views/nova/home/landing.twig @@ -1,4 +1,4 @@ -{% extends '@nova/master.twig' %} +{% extends '@nova/home/master.twig' %} {% block content %} test diff --git a/views/nova/home/master.twig b/views/nova/home/master.twig new file mode 100644 index 00000000..e4f20e20 --- /dev/null +++ b/views/nova/home/master.twig @@ -0,0 +1 @@ +{% extends '@nova/master.twig' %}