From ff939865be902d0588d87f87bf37c52c4c506a99 Mon Sep 17 00:00:00 2001 From: bjoern Date: Fri, 27 Sep 2019 19:23:21 +0200 Subject: [PATCH] adding --- .env.example | 4 ++ .gitignore | 14 +++++ app/Controllers/PageController.php | 75 +++++++++++++++++++++++ app/Repositories/PageRepository.php | 48 +++++++++++++++ app/bootstrap.php | 31 ++++++++++ composer.json | 19 ++++++ public/index.php | 11 ++++ resources/views/layout.blade.php | 37 +++++++++++ resources/views/page/404.blade.php | 3 + resources/views/page/default.blade.php | 16 +++++ resources/views/partials/footer.blade.php | 47 ++++++++++++++ storage/cache/.gitkeep | 0 12 files changed, 305 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 app/Controllers/PageController.php create mode 100644 app/Repositories/PageRepository.php create mode 100644 app/bootstrap.php create mode 100644 composer.json create mode 100644 public/index.php create mode 100644 resources/views/layout.blade.php create mode 100644 resources/views/page/404.blade.php create mode 100644 resources/views/page/default.blade.php create mode 100644 resources/views/partials/footer.blade.php create mode 100644 storage/cache/.gitkeep diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9fbc817 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +APP_DEBUG=false + +DIRECTUS_API_URL= +DIRECTUS_API_TOKEN= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf6db01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +composer.phar + +/vendor/ +/storage/cache/* +!/storage/cache/.gitkeep + +/public/* +!/public/.htaccess +!/public/index.php + +node_modules +.env +*.log +rysnc_exclude diff --git a/app/Controllers/PageController.php b/app/Controllers/PageController.php new file mode 100644 index 0000000..df2c25c --- /dev/null +++ b/app/Controllers/PageController.php @@ -0,0 +1,75 @@ +findOneBySlug(self::HOME_SLUG); + + if ($this->notFound($page)) { + $this->app->redirect('404'); + } + + $this->render($page); + } + + /** + * get single page from slug + * + * + * @param string $slug + */ + public function getAction($slug) + { + $repository = Manager::get('Page'); + $page = $repository->findOneBySlug($slug); + + if ($this->notFound($page)) { + $this->app->redirect('404'); + } + + $this->render($page); + } + + /** + * if page not found + * + */ + public function notFoundAction() + { + $page = [ + 'data' => [ + 'view' => 'page/404' + ] + ]; + + $this->render($page); + } +} diff --git a/app/Repositories/PageRepository.php b/app/Repositories/PageRepository.php new file mode 100644 index 0000000..12dfe57 --- /dev/null +++ b/app/Repositories/PageRepository.php @@ -0,0 +1,48 @@ +itemCollection->findOne($this->name, [ + 'filter[slug][eq]' => $slug, + 'filter[status][eq]' => 'published' + ]); + } + + /** + * find single page with a slug, + * page must be published + * + * @param string $slug + * @return array + */ + public function findByView($view) + { + return $this->itemCollection->find($this->name, [ + 'filter[view][eq]' => $view, + 'filter[status][eq]' => 'published' + ]); + } +} diff --git a/app/bootstrap.php b/app/bootstrap.php new file mode 100644 index 0000000..7d3ff5c --- /dev/null +++ b/app/bootstrap.php @@ -0,0 +1,31 @@ +load(); + +// display all errors if debug is true +if (getenv('DEBUG') === true) { + error_reporting(E_ALL); + ini_set('display_errors', 1); +} + +// create app +$app = Flight::app(); + +// setting view path +$app->set('flight.views.path', __DIR__.'/../resources/views'); + +// adding blade for templates +Flight::register('view', 'Jenssegers\Blade\Blade', [ $app->get('flight.views.path'), __DIR__.'/../resources/cache']); +Flight::map('render', function($view, $data) { + echo Flight::view()->make($view, $data); +}); + +// setting path +$app->set('basePath', __DIR__.'/../'); +$app->set('publicPath', __DIR__.'/../public'); +$app->set('storagePath', __DIR__.'/../storage'); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..526cc01 --- /dev/null +++ b/composer.json @@ -0,0 +1,19 @@ +{ + "name": "super-gear/directus-boilerplate", + "version": "1.0.0", + "type": "boilerplate", + "license": "MIT", + "authors": [ + { "name": "Björn Hase", "email": "me@tentakelfabrik.de" } + ], + "require": { + "php": "^7.0", + "vlucas/phpdotenv": "^3.3", + "jenssegers/blade": "^1.2" + }, + "autoload": { + "psr-4": { + "App\\": "app/" + } + } +} diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000..a7d83d8 --- /dev/null +++ b/public/index.php @@ -0,0 +1,11 @@ +route('GET /', array(new App\Controllers\PageController, 'indexAction')); +$app->route('GET /@slug', array(new App\Controllers\PageController, 'getAction')); +$app->route('GET /404', array(new App\Controllers\PageController, 'notFoundAction')); + +$app->start(); diff --git a/resources/views/layout.blade.php b/resources/views/layout.blade.php new file mode 100644 index 0000000..cd7089c --- /dev/null +++ b/resources/views/layout.blade.php @@ -0,0 +1,37 @@ +@inject('pageRepository', 'App\Repositories\PagenRepository') + + + + + + + Super Gear - Directus Boilerplate | {{ $page['data']['title'] }} + + + + + + + + + + @section('content') + @show + + @include('partials.footer') + + + + diff --git a/resources/views/page/404.blade.php b/resources/views/page/404.blade.php new file mode 100644 index 0000000..185c538 --- /dev/null +++ b/resources/views/page/404.blade.php @@ -0,0 +1,3 @@ +@extends('layout') + +404 diff --git a/resources/views/page/default.blade.php b/resources/views/page/default.blade.php new file mode 100644 index 0000000..051f16b --- /dev/null +++ b/resources/views/page/default.blade.php @@ -0,0 +1,16 @@ +@extends('layout') + +@inject('markdownHelper', 'SuperGear\Helpers\MarkdownHelper') + +@section('content') +
+ +
+ {!! $markdownHelper->text($page['data']['content']) !!} +
+
+@endsection diff --git a/resources/views/partials/footer.blade.php b/resources/views/partials/footer.blade.php new file mode 100644 index 0000000..8d78111 --- /dev/null +++ b/resources/views/partials/footer.blade.php @@ -0,0 +1,47 @@ +@inject('pageRepository', 'App\Repositories\PageRepository') + +@php + $pages = $pageRepository->findByView('page/page'); +@endphp + + diff --git a/storage/cache/.gitkeep b/storage/cache/.gitkeep new file mode 100644 index 0000000..e69de29