From db625b00343edc4fcbae893f584c142d8066130f Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Thu, 12 Aug 2021 19:56:48 +0200 Subject: [PATCH 01/14] removing duplicate .txt LICENSE file --- LICENSE.txt | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index ea745df..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) Custom Php Mvc - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. From 62c44fdfa762c693c18ce8c8bb2a148e1d69e499 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Thu, 12 Aug 2021 20:14:56 +0200 Subject: [PATCH 02/14] hard reset --- .gitattributes | 6 - .gitignore | 1 - src/Controllers/AdminController.php | 19 --- src/Controllers/Controller.php | 35 ------ src/Controllers/ErrorController.php | 18 --- src/Controllers/GlobalController.php | 18 --- src/Controllers/UserController.php | 18 --- src/Core/Router.php | 92 -------------- src/Core/Singleton.php | 17 --- src/Public/.htaccess | 13 -- src/Public/css/main.css | 175 --------------------------- src/Public/index.php | 13 -- src/Public/svg/github_icon.svg | 4 - src/Views/Error/403.html | 5 - src/Views/Error/404.html | 6 - src/Views/Global/about.html | 47 ------- src/Views/Global/index.html | 12 -- src/Views/User/login.php | 30 ----- src/Views/template.phtml | 43 ------- 19 files changed, 572 deletions(-) delete mode 100644 .gitattributes delete mode 100644 src/Controllers/AdminController.php delete mode 100644 src/Controllers/Controller.php delete mode 100644 src/Controllers/ErrorController.php delete mode 100644 src/Controllers/GlobalController.php delete mode 100644 src/Controllers/UserController.php delete mode 100644 src/Core/Router.php delete mode 100644 src/Core/Singleton.php delete mode 100644 src/Public/.htaccess delete mode 100644 src/Public/css/main.css delete mode 100644 src/Public/index.php delete mode 100644 src/Public/svg/github_icon.svg delete mode 100644 src/Views/Error/403.html delete mode 100644 src/Views/Error/404.html delete mode 100644 src/Views/Global/about.html delete mode 100644 src/Views/Global/index.html delete mode 100644 src/Views/User/login.php delete mode 100644 src/Views/template.phtml diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 35963f8..0000000 --- a/.gitattributes +++ /dev/null @@ -1,6 +0,0 @@ -*.html linguist-language=html -*.css linguist-language=css -*.php linguist-language=php - -*.sql linguist-detectable=true -*.sql linguist-language=sql diff --git a/.gitignore b/.gitignore index 9ae2976..485dee6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ .idea -src/Core/db.ini diff --git a/src/Controllers/AdminController.php b/src/Controllers/AdminController.php deleted file mode 100644 index 947666b..0000000 --- a/src/Controllers/AdminController.php +++ /dev/null @@ -1,19 +0,0 @@ -[^\S ]+/s', // strip whitespaces after tags, except space - '/[^\S ]+\/' // Remove HTML comments - ); - - $replace = array('>', '<', '\\1', ''); - return preg_replace($search, $replace, $buffer); -} \ No newline at end of file diff --git a/src/Controllers/ErrorController.php b/src/Controllers/ErrorController.php deleted file mode 100644 index 7cd75d3..0000000 --- a/src/Controllers/ErrorController.php +++ /dev/null @@ -1,18 +0,0 @@ -render('404'); - } - - public function forbidden() - { - $this->render('403'); - } -} diff --git a/src/Controllers/GlobalController.php b/src/Controllers/GlobalController.php deleted file mode 100644 index ebb9b46..0000000 --- a/src/Controllers/GlobalController.php +++ /dev/null @@ -1,18 +0,0 @@ -render('index'); - } - - public function about() - { - $this->render('about'); - } -} diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php deleted file mode 100644 index f7b2daa..0000000 --- a/src/Controllers/UserController.php +++ /dev/null @@ -1,18 +0,0 @@ -render('login', ['error' => $error]); - } - -} diff --git a/src/Core/Router.php b/src/Core/Router.php deleted file mode 100644 index 8d34a8e..0000000 --- a/src/Core/Router.php +++ /dev/null @@ -1,92 +0,0 @@ -$action(); - return; - } - - $this->set_404(); - return; - } - - require_once ROOT . '/Controllers/' . $controller . '.php'; - $controller = new $controller(); - - $action = (isset($params[0])) ? array_shift($params) : $controller->default_action; - $action = method_exists($controller, $action) ? $action : $controller->default_action; - - if ($action === '404') { - self::set_404(); - return; - } - - empty($params) ? $controller->$action() : $controller->$action($params); - } - - public function prettify(): string - { - $uri = $_SERVER['REQUEST_URI']; - - if ($uri === '/') - return $this::_index; - - $uri = substr($uri, 1); - - if ($uri === $this::_index) { - $this->redirect(SITE); - return $uri; - } - - if (substr($uri, 0, strlen($this::_global)) === $this::_global) { - $this->redirect(SITE . substr($uri, strlen($this::_global))); - } - - if ($uri[-1] !== '/') - return $uri; - - $new_uri = substr($uri, 0, -1); - $this->redirect(SITE . '/' . $new_uri); - return $new_uri; - - } - - public static function redirect($url, $code = 301) - { - http_response_code($code); - header('Location: ' . $url); - } - - public static function set_404() - { - $controller = 'ErrorController'; - - require_once ROOT . '/Controllers/' . $controller . '.php'; - $controller = new $controller(); - - $controller->not_found(); - } -} diff --git a/src/Core/Singleton.php b/src/Core/Singleton.php deleted file mode 100644 index cde3de3..0000000 --- a/src/Core/Singleton.php +++ /dev/null @@ -1,17 +0,0 @@ - - Header set Cache-Control "max-age=604800, public" - - - - Header set Cache-Control "max-age=2678400, public" - diff --git a/src/Public/css/main.css b/src/Public/css/main.css deleted file mode 100644 index 331df33..0000000 --- a/src/Public/css/main.css +++ /dev/null @@ -1,175 +0,0 @@ -:root { - --primary-color-400: #FCFCFC; - --primary-color-500: #EEEEEE; - --primary-color-600: #434343; - - --secondary-color-400: #DD6A3A; - --secondary-color-500: #AA512C; - - --transition: cubic-bezier(0.5, 0, 0.25, 1.5); -} - -::-webkit-scrollbar { - width: 8px; - height: 8px; -} - -::-webkit-scrollbar-track { - background: var(--primary-color-500) -} - -::-webkit-scrollbar-thumb { - background: var(--primary-color-600) -} - -body { - margin: 0; - color: var(--primary-color-600); - background-color: var(--primary-color-400); - font-family: 'Poppins', sans-serif; - padding-bottom: 100px; -} - -header, footer { - box-shadow: 0 0 0 6px; - background-color: var(--primary-color-500); - width: 100%; -} - - -.navbar { - gap: 20px -} - -.grid { - display: grid; - place-items: center; -} - -.flex { - display: flex; - justify-content: space-between; - align-items: flex-end; - flex-flow: row wrap; -} - -a { - transition: all 0.3s ease-in-out; - color: var(--secondary-color-400); - text-decoration: none; -} - -a:hover { - font-weight: bold; - color: var(--secondary-color-500); -} - -h1.title { - font-size: 3em; - font-family: 'Pattaya', sans-serif; - text-align: center; -} - -.card { - margin: 20px 0; - width: clamp(240px, calc(100% - 40px), 1200px); - background-color: var(--primary-color-500); - border-radius: 5px; - padding: 10px 20px; -} - -main { - min-height: calc(100vh - 130px); -} - -main > * { - animation: slide-up 1s var(--transition) -} - -main > h1 { - animation: slide-up 0.8s var(--transition) -} - -main > .card { - animation: slide-up 1.2s var(--transition) -} - -@keyframes slide-up { - from { - opacity: 0; - transform: translateY(100px); - } - to { - opacity: 1; - transform: translateY(0); - } -} - -.container { - padding: 20px 0; - width: 90%; - max-width: 1520px; -} - -.long-container { - padding: 20px 0; - width: 100%; -} - -.flat { - padding: 0 -} - -footer { - height: 65px; -} - -.github-icon { - fill: var(--primary-color-600); -} - -.form { - border-radius: 5px; - background-color: var(--primary-color-500); - width: clamp(25%, 320px, 80%); - margin-bottom: 50px; -} - -label { - width: 80%; - padding: 20px 0; -} - -input { - padding: 10px 20px; - outline: none; - border: 0; -} - -input[type="text"], input[type="password"] { - height: 24px; - width: calc(100% - 40px); -} - -label[for="actions"] { - display: flex; - justify-content: space-around; -} - -.splash { - text-align: center; - font-size: 1em; - width: 80%; -} - -.button { - color: white; - border-radius: 5px; - text-align: center; - background-color: var(--secondary-color-400); - min-width: 30%; -} - -.button:hover { - background-color: var(--secondary-color-500); -} \ No newline at end of file diff --git a/src/Public/index.php b/src/Public/index.php deleted file mode 100644 index 2fe2679..0000000 --- a/src/Public/index.php +++ /dev/null @@ -1,13 +0,0 @@ -route(); diff --git a/src/Public/svg/github_icon.svg b/src/Public/svg/github_icon.svg deleted file mode 100644 index 085bde4..0000000 --- a/src/Public/svg/github_icon.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/src/Views/Error/403.html b/src/Views/Error/403.html deleted file mode 100644 index 01755a5..0000000 --- a/src/Views/Error/403.html +++ /dev/null @@ -1,5 +0,0 @@ -

UnAuthorized

-
-

Code 403

-

You dont have the permission to access the ressource at this location

-
\ No newline at end of file diff --git a/src/Views/Error/404.html b/src/Views/Error/404.html deleted file mode 100644 index e9c699a..0000000 --- a/src/Views/Error/404.html +++ /dev/null @@ -1,6 +0,0 @@ -

Page Not Found !

-
-

Code 404

-

The resource you requested does not exist at this location...

-

Did you misspell anything ?

-
\ No newline at end of file diff --git a/src/Views/Global/about.html b/src/Views/Global/about.html deleted file mode 100644 index bacf911..0000000 --- a/src/Views/Global/about.html +++ /dev/null @@ -1,47 +0,0 @@ -

About

-

- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aspernatur, beatae, consequatur deleniti deserunt - doloremque dolores dolorum ea eius enim eum eveniet ex facilis fugiat ipsam iste itaque laboriosam laudantium - maiores nesciunt nobis omnis optio perferendis perspiciatis porro provident quia quis quos reiciendis reprehenderit - sint tenetur totam ut velit veritatis? -

- -
-

Lorem ipsum dolor sit amet.

-

- Ad aliquam blanditiis debitis eligendi est iste minima molestiae, nisi - odit placeat quae sapiente sed suscipit, tempore vel. A adipisci at blanditiis culpa deserunt dolorum eveniet - exercitationem facere, illum in, ipsum libero magnam mollitia nulla officiis placeat praesentium rem voluptas - voluptate voluptatum? Atque dolor excepturi ipsam, sapiente soluta vero voluptatum? -

-

- Accusamus assumenda - dolores esse minima quae, vero. Cupiditate itaque, sapiente! Accusantium aliquam autem dolorum eius esse - excepturi - exercitationem, facilis minima officia placeat possimus, quaerat qui quod reiciendis rem temporibus tenetur unde - velit voluptatem voluptates. Accusamus asperiores dicta numquam optio quo! Ab at delectus ipsum minus, nostrum - porro - quasi sit voluptas? -

-
-

- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aspernatur, beatae, consequatur deleniti deserunt - doloremque dolores dolorum ea eius enim eum eveniet ex facilis fugiat ipsam iste itaque laboriosam laudantium - maiores nesciunt nobis omnis optio perferendis perspiciatis porro provident quia quis quos reiciendis reprehenderit - sint tenetur totam ut velit veritatis? -

-

- Ad aliquam blanditiis debitis eligendi est iste minima molestiae, nisi - odit placeat quae sapiente sed suscipit, tempore vel. A adipisci at blanditiis culpa deserunt dolorum eveniet - exercitationem facere, illum in, ipsum libero magnam mollitia nulla officiis placeat praesentium rem voluptas - voluptate voluptatum? Atque dolor excepturi ipsam, sapiente soluta vero voluptatum? -

-

- Accusamus assumenda - dolores esse minima quae, vero. Cupiditate itaque, sapiente! Accusantium aliquam autem dolorum eius esse - excepturi - exercitationem, facilis minima officia placeat possimus, quaerat qui quod reiciendis rem temporibus tenetur unde - velit voluptatem voluptates. Accusamus asperiores dicta numquam optio quo! Ab at delectus ipsum minus, nostrum - porro - quasi sit voluptas? -

\ No newline at end of file diff --git a/src/Views/Global/index.html b/src/Views/Global/index.html deleted file mode 100644 index de83acb..0000000 --- a/src/Views/Global/index.html +++ /dev/null @@ -1,12 +0,0 @@ -

Welcome

- -
-

Lorem Ipsum

-

- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aspernatur, beatae, consequatur deleniti deserunt - doloremque dolores dolorum ea eius enim eum eveniet ex facilis fugiat ipsam iste itaque laboriosam laudantium - maiores nesciunt nobis omnis optio perferendis perspiciatis porro provident quia quis quos reiciendis - reprehenderit - sint tenetur totam ut velit veritatis? -

-
diff --git a/src/Views/User/login.php b/src/Views/User/login.php deleted file mode 100644 index f54c737..0000000 --- a/src/Views/User/login.php +++ /dev/null @@ -1,30 +0,0 @@ - - -

Connexion

-
- - - - -

- -

- - - - -
\ No newline at end of file diff --git a/src/Views/template.phtml b/src/Views/template.phtml deleted file mode 100644 index 83c7077..0000000 --- a/src/Views/template.phtml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - Custom Php MVC - - - - - - - -
-
- Home - -
-
-
-
- -
-
-
-
-

Made By Boniface Yohann

- - Github - -
-
- - \ No newline at end of file From 49aced3d493f90fbac4692d0c6ac8b0ebb447fde Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 13:37:05 +0200 Subject: [PATCH 03/14] updated .gitignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 485dee6..83c64de 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ +# PhpStorm configuration .idea + +# Composer venders +vendor/ + +# Application configuration and secrets +.env From 925e3d6c26ceb66ee04009c3f6e32bc7fd74983b Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 13:37:23 +0200 Subject: [PATCH 04/14] adding composer.json --- composer.json | 15 +++++++++++++++ composer.lock | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 composer.json create mode 100644 composer.lock diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b1897b6 --- /dev/null +++ b/composer.json @@ -0,0 +1,15 @@ +{ + "name": "sigmanificient/custom_php_mvc", + "autoload": { + "psr-4": { + "mvc\\": "src/" + } + }, + "authors": [ + { + "name": "Yohann Boniface", + "email": "edhyjox@gmail.com" + } + ], + "require": {} +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..dad229e --- /dev/null +++ b/composer.lock @@ -0,0 +1,18 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "f681c065ef586e5134758d1fbbc1dce3", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.1.0" +} From 9bcefb8defdee924b98877d2a4fd5d4a24c974b8 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 13:57:17 +0200 Subject: [PATCH 05/14] adding basic .htaccess config --- src/public/.htaccess | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/public/.htaccess diff --git a/src/public/.htaccess b/src/public/.htaccess new file mode 100644 index 0000000..dcfe74b --- /dev/null +++ b/src/public/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine On +RewriteRule ^([A-z0-9_/-]*)$ index.php?p=$1 +RewriteBase / From 6b06cad38ce122009a5a23f1270e69a9b961b1a9 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 14:20:42 +0200 Subject: [PATCH 06/14] basic routing with get registration --- src/core/Application.php | 20 ++++++++++++++++++++ src/core/Request.php | 25 +++++++++++++++++++++++++ src/core/Router.php | 34 ++++++++++++++++++++++++++++++++++ src/public/index.php | 16 ++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 src/core/Application.php create mode 100644 src/core/Request.php create mode 100644 src/core/Router.php create mode 100644 src/public/index.php diff --git a/src/core/Application.php b/src/core/Application.php new file mode 100644 index 0000000..e140794 --- /dev/null +++ b/src/core/Application.php @@ -0,0 +1,20 @@ +request = new Request(); + $this->router = new Router($this->request); + } + + public function run() + { + $this->router->resolve(); + } +} diff --git a/src/core/Request.php b/src/core/Request.php new file mode 100644 index 0000000..fa16a6d --- /dev/null +++ b/src/core/Request.php @@ -0,0 +1,25 @@ +request = $request; + } + + public function get($uri, $callback) + { + $this->routes['get'][$uri] = $callback; + } + + public function resolve() + { + $path = $this->request->getPath(); + $method = $this->request->getMethod(); + $callback = $this->routes[$method][$path] ?? false; + + if ($callback === false) { + echo '404 Not Found'; + return; + } + + echo call_user_func($callback); + } +} \ No newline at end of file diff --git a/src/public/index.php b/src/public/index.php new file mode 100644 index 0000000..9b9b2b4 --- /dev/null +++ b/src/public/index.php @@ -0,0 +1,16 @@ +router->get( + '/', + function () { + return 'index page'; + } +); + +$app->run(); \ No newline at end of file From 19e053ff195f32761010bd301f5da36970103bdd Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 14:25:40 +0200 Subject: [PATCH 07/14] adding runtime .gitignore --- src/runtime/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/runtime/.gitignore diff --git a/src/runtime/.gitignore b/src/runtime/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/src/runtime/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From 8966f0c7bd25b9abe4ff0f7040c9745121f5d06d Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 14:46:44 +0200 Subject: [PATCH 08/14] implementing basic views --- src/app/views/layouts/base.php | 13 +++++++++++++ src/app/views/pages/index.php | 1 + src/core/Application.php | 2 +- src/core/Request.php | 2 +- src/core/Router.php | 30 ++++++++++++++++++++++++++---- src/public/index.php | 12 ++++-------- 6 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 src/app/views/layouts/base.php create mode 100644 src/app/views/pages/index.php diff --git a/src/app/views/layouts/base.php b/src/app/views/layouts/base.php new file mode 100644 index 0000000..0e0ced5 --- /dev/null +++ b/src/app/views/layouts/base.php @@ -0,0 +1,13 @@ + + + + + + + + + + {{content}} + + \ No newline at end of file diff --git a/src/app/views/pages/index.php b/src/app/views/pages/index.php new file mode 100644 index 0000000..1a92de7 --- /dev/null +++ b/src/app/views/pages/index.php @@ -0,0 +1 @@ +

This is an index page.

\ No newline at end of file diff --git a/src/core/Application.php b/src/core/Application.php index e140794..86a28b1 100644 --- a/src/core/Application.php +++ b/src/core/Application.php @@ -15,6 +15,6 @@ public function __construct() public function run() { - $this->router->resolve(); + echo $this->router->resolve(); } } diff --git a/src/core/Request.php b/src/core/Request.php index fa16a6d..44f2979 100644 --- a/src/core/Request.php +++ b/src/core/Request.php @@ -22,4 +22,4 @@ public function getMethod(): string { return strtolower($_SERVER['REQUEST_METHOD']); } -} \ No newline at end of file +} diff --git a/src/core/Router.php b/src/core/Router.php index 237e93c..b1436f8 100644 --- a/src/core/Router.php +++ b/src/core/Router.php @@ -25,10 +25,32 @@ public function resolve() $callback = $this->routes[$method][$path] ?? false; if ($callback === false) { - echo '404 Not Found'; - return; + return '404 Not Found'; } - echo call_user_func($callback); + if (is_string($callback)) { + return $this->renderView($callback); + } + + return call_user_func($callback); + } + + public function renderView($view) + { + $layoutContent = $this->layoutContent(); + $viewContent = $this->renderOnlyView($view); + return str_replace('{{content}}', $viewContent, $layoutContent); + } + + public function layoutContent() { + ob_start(); + include_once ROOT_DIR."/app/views/layouts/base.php"; + return ob_get_clean(); + } + + protected function renderOnlyView($view) { + ob_start(); + include_once ROOT_DIR."/app/views/pages/$view.php"; + return ob_get_clean(); } -} \ No newline at end of file +} diff --git a/src/public/index.php b/src/public/index.php index 9b9b2b4..cd97163 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -1,16 +1,12 @@ router->get( - '/', - function () { - return 'index page'; - } -); +$app->router->get('/', 'index'); -$app->run(); \ No newline at end of file +$app->run(); From 3acc82f7aeef41d71d2361e19e6b8cf7351f01b9 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 16:00:00 +0200 Subject: [PATCH 09/14] adding post and improving 404 --- src/app/views/pages/_404.php | 1 + src/core/Application.php | 5 ++++- src/core/Response.php | 10 ++++++++++ src/core/Router.php | 13 +++++++++++-- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/app/views/pages/_404.php create mode 100644 src/core/Response.php diff --git a/src/app/views/pages/_404.php b/src/app/views/pages/_404.php new file mode 100644 index 0000000..9bc20ca --- /dev/null +++ b/src/app/views/pages/_404.php @@ -0,0 +1 @@ +

Not Found

\ No newline at end of file diff --git a/src/core/Application.php b/src/core/Application.php index 86a28b1..46c340d 100644 --- a/src/core/Application.php +++ b/src/core/Application.php @@ -6,11 +6,14 @@ class Application { public Router $router; public Request $request; + public Response $response; public function __construct() { $this->request = new Request(); - $this->router = new Router($this->request); + $this->response = new Response(); + + $this->router = new Router($this->request, $this->response); } public function run() diff --git a/src/core/Response.php b/src/core/Response.php new file mode 100644 index 0000000..9e1c1ea --- /dev/null +++ b/src/core/Response.php @@ -0,0 +1,10 @@ +request = $request; + $this->response = $response; } public function get($uri, $callback) @@ -18,6 +21,11 @@ public function get($uri, $callback) $this->routes['get'][$uri] = $callback; } + public function post($uri, $callback) + { + $this->routes['post'][$uri] = $callback; + } + public function resolve() { $path = $this->request->getPath(); @@ -25,7 +33,8 @@ public function resolve() $callback = $this->routes[$method][$path] ?? false; if ($callback === false) { - return '404 Not Found'; + $this->response->setStatusCode(404); + return $this->renderView('_404'); } if (is_string($callback)) { From 0c686651fefffda1022190244c5d3a9553f0e91b Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 18:18:26 +0200 Subject: [PATCH 10/14] adding rules caching for future public files --- src/public/.htaccess | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/public/.htaccess b/src/public/.htaccess index dcfe74b..b4b4a20 100644 --- a/src/public/.htaccess +++ b/src/public/.htaccess @@ -1,3 +1,11 @@ RewriteEngine On RewriteRule ^([A-z0-9_/-]*)$ index.php?p=$1 RewriteBase / + + + Header set Cache-Control "max-age=604800, public" + + + + Header set Cache-Control "max-age=2678400, public" + From 8d9a655090f26c82f8ae7a3d695831577c8ee5cd Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 18:27:29 +0200 Subject: [PATCH 11/14] integrating ui from master --- src/app/views/layouts/base.php | 38 ++++++- src/public/css/main.css | 175 +++++++++++++++++++++++++++++++++ src/public/svg/github_icon.svg | 4 + 3 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 src/public/css/main.css create mode 100644 src/public/svg/github_icon.svg diff --git a/src/app/views/layouts/base.php b/src/app/views/layouts/base.php index 0e0ced5..3d87f83 100644 --- a/src/app/views/layouts/base.php +++ b/src/app/views/layouts/base.php @@ -1,3 +1,6 @@ + @@ -5,9 +8,36 @@ - + Custom Php MVC + + + + + - - {{content}} + +
+
+ Home + +
+
+
+
+ {{content}} +
+
+
+
+

Made By Boniface Yohann

+ + Github + +
+
- \ No newline at end of file + diff --git a/src/public/css/main.css b/src/public/css/main.css new file mode 100644 index 0000000..55cb40b --- /dev/null +++ b/src/public/css/main.css @@ -0,0 +1,175 @@ +:root { + --primary-color-400: #FCFCFC; + --primary-color-500: #EEEEEE; + --primary-color-600: #434343; + + --secondary-color-400: #DD6A3A; + --secondary-color-500: #AA512C; + + --transition: cubic-bezier(0.5, 0, 0.25, 1.5); +} + +::-webkit-scrollbar { + width: 8px; + height: 8px; +} + +::-webkit-scrollbar-track { + background: var(--primary-color-500) +} + +::-webkit-scrollbar-thumb { + background: var(--primary-color-600) +} + +body { + margin: 0; + color: var(--primary-color-600); + background-color: var(--primary-color-400); + font-family: 'Poppins', sans-serif; + padding-bottom: 100px; +} + +header, footer { + box-shadow: 0 0 0 6px; + background-color: var(--primary-color-500); + width: 100%; +} + + +.navbar { + gap: 20px +} + +.grid { + display: grid; + place-items: center; +} + +.flex { + display: flex; + justify-content: space-between; + align-items: flex-end; + flex-flow: row wrap; +} + +a { + transition: all 0.3s ease-in-out; + color: var(--secondary-color-400); + text-decoration: none; +} + +a:hover { + font-weight: bold; + color: var(--secondary-color-500); +} + +h1.title { + font-size: 3em; + font-family: 'Pattaya', sans-serif; + text-align: center; +} + +.card { + margin: 20px 0; + width: clamp(240px, calc(100% - 40px), 1200px); + background-color: var(--primary-color-500); + border-radius: 5px; + padding: 10px 20px; +} + +main { + min-height: calc(100vh - 130px); +} + +main > * { + animation: slide-up 1s var(--transition) +} + +main > h1 { + animation: slide-up 0.8s var(--transition) +} + +main > .card { + animation: slide-up 1.2s var(--transition) +} + +@keyframes slide-up { + from { + opacity: 0; + transform: translateY(100px); + } + to { + opacity: 1; + transform: translateY(0); + } +} + +.container { + padding: 20px 0; + width: 90%; + max-width: 1520px; +} + +.long-container { + padding: 20px 0; + width: 100%; +} + +.flat { + padding: 0 +} + +footer { + height: 65px; +} + +.github-icon { + fill: var(--primary-color-600); +} + +.form { + border-radius: 5px; + background-color: var(--primary-color-500); + width: clamp(25%, 320px, 80%); + margin-bottom: 50px; +} + +label { + width: 80%; + padding: 20px 0; +} + +input { + padding: 10px 20px; + outline: none; + border: 0; +} + +input[type="text"], input[type="password"] { + height: 24px; + width: calc(100% - 40px); +} + +label[for="actions"] { + display: flex; + justify-content: space-around; +} + +.splash { + text-align: center; + font-size: 1em; + width: 80%; +} + +.button { + color: white; + border-radius: 5px; + text-align: center; + background-color: var(--secondary-color-400); + min-width: 30%; +} + +.button:hover { + background-color: var(--secondary-color-500); +} diff --git a/src/public/svg/github_icon.svg b/src/public/svg/github_icon.svg new file mode 100644 index 0000000..085bde4 --- /dev/null +++ b/src/public/svg/github_icon.svg @@ -0,0 +1,4 @@ + + + + From 4e5fb62c0a0d043026f5da69d31b03931a7fb7f3 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 20:27:18 +0200 Subject: [PATCH 12/14] Implementing controllers --- src/app/controllers/ErrorController.php | 11 +++++++ src/app/controllers/SiteController.php | 11 +++++++ src/app/views/layouts/base.php | 3 -- src/core/Router.php | 38 +++++++------------------ src/core/abc/Controller.php | 27 ++++++++++++++++++ src/public/index.php | 3 +- 6 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 src/app/controllers/ErrorController.php create mode 100644 src/app/controllers/SiteController.php create mode 100644 src/core/abc/Controller.php diff --git a/src/app/controllers/ErrorController.php b/src/app/controllers/ErrorController.php new file mode 100644 index 0000000..9fa5e84 --- /dev/null +++ b/src/app/controllers/ErrorController.php @@ -0,0 +1,11 @@ +render('_404'); + } +} diff --git a/src/app/controllers/SiteController.php b/src/app/controllers/SiteController.php new file mode 100644 index 0000000..c1db88d --- /dev/null +++ b/src/app/controllers/SiteController.php @@ -0,0 +1,11 @@ +render('index'); + } +} diff --git a/src/app/views/layouts/base.php b/src/app/views/layouts/base.php index 3d87f83..c530f6c 100644 --- a/src/app/views/layouts/base.php +++ b/src/app/views/layouts/base.php @@ -1,6 +1,3 @@ - diff --git a/src/core/Router.php b/src/core/Router.php index 9fe1419..b812675 100644 --- a/src/core/Router.php +++ b/src/core/Router.php @@ -16,50 +16,34 @@ public function __construct(Request $request, Response $response) $this->response = $response; } - public function get($uri, $callback) + public function get($uri, $controller, $method) { - $this->routes['get'][$uri] = $callback; + $this->routes['get'][$uri] = [$controller, $method]; } - public function post($uri, $callback) + public function post($uri, $controller, $method) { - $this->routes['post'][$uri] = $callback; + $this->routes['post'][$uri] = [$controller, $method]; } public function resolve() { $path = $this->request->getPath(); $method = $this->request->getMethod(); + $callback = $this->routes[$method][$path] ?? false; if ($callback === false) { $this->response->setStatusCode(404); - return $this->renderView('_404'); - } - - if (is_string($callback)) { - return $this->renderView($callback); + $callback = ['Error', 'notFound']; } - return call_user_func($callback); - } - - public function renderView($view) - { - $layoutContent = $this->layoutContent(); - $viewContent = $this->renderOnlyView($view); - return str_replace('{{content}}', $viewContent, $layoutContent); - } + $controllerName = ucfirst(array_shift($callback)) . 'Controller'; + include ROOT_DIR."/app/controllers/$controllerName.php"; + $controller = new $controllerName; - public function layoutContent() { - ob_start(); - include_once ROOT_DIR."/app/views/layouts/base.php"; - return ob_get_clean(); - } + $method = array_shift($callback); - protected function renderOnlyView($view) { - ob_start(); - include_once ROOT_DIR."/app/views/pages/$view.php"; - return ob_get_clean(); + echo $controller->$method(); } } diff --git a/src/core/abc/Controller.php b/src/core/abc/Controller.php new file mode 100644 index 0000000..0a975e3 --- /dev/null +++ b/src/core/abc/Controller.php @@ -0,0 +1,27 @@ +layoutContent(); + $viewContent = $this->renderOnlyView($view); + return str_replace('{{content}}', $viewContent, $layoutContent); + } + + public function layoutContent() + { + ob_start(); + include_once ROOT_DIR . "/app/views/layouts/base.php"; + return ob_get_clean(); + } + + protected function renderOnlyView($view) + { + ob_start(); + include_once ROOT_DIR . "/app/views/pages/$view.php"; + return ob_get_clean(); + } +} \ No newline at end of file diff --git a/src/public/index.php b/src/public/index.php index cd97163..7889b65 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -7,6 +7,5 @@ $app = new Application(); -$app->router->get('/', 'index'); - +$app->router->get('/', 'site', 'index'); $app->run(); From 34d95ad91d8884a3df782b3a68e378bef996b799 Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 20:51:56 +0200 Subject: [PATCH 13/14] Adding about page and cleaning up code. --- src/app/controllers/SiteController.php | 5 +++ src/app/views/layouts/base.php | 6 ++-- src/app/views/pages/about.php | 42 ++++++++++++++++++++++++++ src/core/Response.php | 3 +- src/core/Router.php | 10 ++++-- src/core/abc/Controller.php | 2 +- src/public/index.php | 4 ++- 7 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 src/app/views/pages/about.php diff --git a/src/app/controllers/SiteController.php b/src/app/controllers/SiteController.php index c1db88d..da1fb09 100644 --- a/src/app/controllers/SiteController.php +++ b/src/app/controllers/SiteController.php @@ -8,4 +8,9 @@ public function index(): string { return $this->render('index'); } + + public function about(): string + { + return $this->render('about'); + } } diff --git a/src/app/views/layouts/base.php b/src/app/views/layouts/base.php index c530f6c..ebf472e 100644 --- a/src/app/views/layouts/base.php +++ b/src/app/views/layouts/base.php @@ -17,9 +17,9 @@ diff --git a/src/app/views/pages/about.php b/src/app/views/pages/about.php new file mode 100644 index 0000000..d00685c --- /dev/null +++ b/src/app/views/pages/about.php @@ -0,0 +1,42 @@ +

About

+

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aspernatur, beatae, consequatur deleniti deserunt + doloremque dolores dolorum ea eius enim eum eveniet ex facilis fugiat ipsam iste itaque laboriosam laudantium + maiores nesciunt nobis omnis optio perferendis perspiciatis porro provident quia quis quos reiciendis reprehenderit + sint tenetur totam ut velit veritatis? +

+ +
+

Lorem ipsum dolor sit amet.

+

+ Ad aliquam blanditiis debitis eligendi est iste minima molestiae, nisi odit placeat quae sapiente sed suscipit, + tempore vel. A adipisci at blanditiis culpa deserunt dolorum eveniet exercitationem facere, illum in, ipsum + libero magnam mollitia nulla officiis placeat praesentium rem voluptas voluptate voluptatum? Atque dolor + excepturi ipsam, sapiente soluta vero voluptatum? +

+

+ Accusamus assumenda dolores esse minima quae, vero. Cupiditate itaque, sapiente! Accusantium aliquam autem + dolorum eius esse excepturi exercitationem, facilis minima officia placeat possimus, quaerat qui quod reiciendis + rem temporibus tenetur unde velit voluptatem voluptates. Accusamus asperiores dicta numquam optio quo! Ab at + delectus ipsum minus, nostrum porro quasi sit voluptas? +

+
+ +

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ad aspernatur, beatae, consequatur deleniti deserunt + doloremque dolores dolorum ea eius enim eum eveniet ex facilis fugiat ipsam iste itaque laboriosam laudantium + maiores nesciunt nobis omnis optio perferendis perspiciatis porro provident quia quis quos reiciendis reprehenderit + sint tenetur totam ut velit veritatis? +

+

+ Ad aliquam blanditiis debitis eligendi est iste minima molestiae, nisi odit placeat quae sapiente sed suscipit, + tempore vel. A adipisci at blanditiis culpa deserunt dolorum eveniet exercitationem facere, illum in, ipsum libero + magnam mollitia nulla officiis placeat praesentium rem voluptas voluptate voluptatum? Atque dolor excepturi ipsam, + sapiente soluta vero voluptatum? +

+

+ Accusamus assumenda dolores esse minima quae, vero. Cupiditate itaque, sapiente! Accusantium aliquam autem dolorum + eius esse excepturi exercitationem, facilis minima officia placeat possimus, quaerat qui quod reiciendis rem + temporibus tenetur unde velit voluptatem voluptates. Accusamus asperiores dicta numquam optio quo! Ab at delectus + ipsum minus, nostrum porro quasi sit voluptas? +

diff --git a/src/core/Response.php b/src/core/Response.php index 9e1c1ea..e44ce05 100644 --- a/src/core/Response.php +++ b/src/core/Response.php @@ -4,7 +4,8 @@ class Response { - public function setStatusCode(int $code) { + public function setStatusCode(int $code) + { http_response_code($code); } } diff --git a/src/core/Router.php b/src/core/Router.php index b812675..795b8dc 100644 --- a/src/core/Router.php +++ b/src/core/Router.php @@ -35,15 +35,19 @@ public function resolve() if ($callback === false) { $this->response->setStatusCode(404); - $callback = ['Error', 'notFound']; + $callback = $this->routes['get']['404'] ?? '404 Not Found'; + } + + if (is_string($callback)) { + return $callback; } $controllerName = ucfirst(array_shift($callback)) . 'Controller'; - include ROOT_DIR."/app/controllers/$controllerName.php"; + include ROOT_DIR . "/app/controllers/$controllerName.php"; $controller = new $controllerName; $method = array_shift($callback); - echo $controller->$method(); + return $controller->$method(); } } diff --git a/src/core/abc/Controller.php b/src/core/abc/Controller.php index 0a975e3..d91b473 100644 --- a/src/core/abc/Controller.php +++ b/src/core/abc/Controller.php @@ -24,4 +24,4 @@ protected function renderOnlyView($view) include_once ROOT_DIR . "/app/views/pages/$view.php"; return ob_get_clean(); } -} \ No newline at end of file +} diff --git a/src/public/index.php b/src/public/index.php index 7889b65..d67a793 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -1,11 +1,13 @@ router->get('/', 'site', 'index'); +$app->router->get('/about', 'site', 'about'); +$app->router->get('404', 'error', 'notFound'); $app->run(); From d27a4bc7a7edcd69a9991da1798926db46967bbd Mon Sep 17 00:00:00 2001 From: Yohann Boniface Date: Mon, 16 Aug 2021 21:51:56 +0200 Subject: [PATCH 14/14] Adding login from, session and singleton --- src/app/controllers/AuthController.php | 15 +++++++++++ src/app/controllers/SiteController.php | 2 +- src/app/views/pages/user/login.php | 26 +++++++++++++++++++ src/core/Session.php | 36 ++++++++++++++++++++++++++ src/core/abc/Controller.php | 6 ++--- src/core/abc/Singleton.php | 19 ++++++++++++++ src/public/index.php | 2 ++ 7 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/app/controllers/AuthController.php create mode 100644 src/app/views/pages/user/login.php create mode 100644 src/core/Session.php create mode 100644 src/core/abc/Singleton.php diff --git a/src/app/controllers/AuthController.php b/src/app/controllers/AuthController.php new file mode 100644 index 0000000..fe63412 --- /dev/null +++ b/src/app/controllers/AuthController.php @@ -0,0 +1,15 @@ +render( + 'user/login', + ['error' => Session::getInstance()->flash] + ); + } +} diff --git a/src/app/controllers/SiteController.php b/src/app/controllers/SiteController.php index da1fb09..40ec146 100644 --- a/src/app/controllers/SiteController.php +++ b/src/app/controllers/SiteController.php @@ -2,7 +2,7 @@ use mvc\core\abc\Controller; -class siteController extends Controller +class SiteController extends Controller { public function index(): string { diff --git a/src/app/views/pages/user/login.php b/src/app/views/pages/user/login.php new file mode 100644 index 0000000..e5a1934 --- /dev/null +++ b/src/app/views/pages/user/login.php @@ -0,0 +1,26 @@ +

Connexion

+
+ + + + +

+ +

+ + + + +
diff --git a/src/core/Session.php b/src/core/Session.php new file mode 100644 index 0000000..35e5d09 --- /dev/null +++ b/src/core/Session.php @@ -0,0 +1,36 @@ +flash = $_SESSION['flash']; + $this->pop('flash'); + } + } + + public function add($key, $val) + { + $_SESSION[$key] = $val; + } + + public function get($key) + { + return $_SESSION[$key] ?? []; + } + + public function pop($key) + { + unset($_SESSION[$key]); + } +} diff --git a/src/core/abc/Controller.php b/src/core/abc/Controller.php index d91b473..1234c2b 100644 --- a/src/core/abc/Controller.php +++ b/src/core/abc/Controller.php @@ -4,10 +4,10 @@ abstract class Controller { - public function render($view) + public function render($view, $params = []) { $layoutContent = $this->layoutContent(); - $viewContent = $this->renderOnlyView($view); + $viewContent = $this->renderOnlyView($view, $params); return str_replace('{{content}}', $viewContent, $layoutContent); } @@ -18,7 +18,7 @@ public function layoutContent() return ob_get_clean(); } - protected function renderOnlyView($view) + protected function renderOnlyView($view, $data) { ob_start(); include_once ROOT_DIR . "/app/views/pages/$view.php"; diff --git a/src/core/abc/Singleton.php b/src/core/abc/Singleton.php new file mode 100644 index 0000000..060639e --- /dev/null +++ b/src/core/abc/Singleton.php @@ -0,0 +1,19 @@ +router->get('/', 'site', 'index'); $app->router->get('/about', 'site', 'about'); +$app->router->get('/login', 'auth', 'login'); $app->router->get('404', 'error', 'notFound'); + $app->run();