From b146e3b55465e4e0cbd9e594c42e03ffdb6eaaa7 Mon Sep 17 00:00:00 2001 From: Kr1PtunZ Date: Wed, 15 May 2024 14:00:13 +0500 Subject: [PATCH] 1st commit --- .env | 4 ++ .env.example | 0 .gitignore | 2 + app/Controllers/Controller.php | 14 ++++++ app/Controllers/LoginController.php | 14 ++++++ app/Controllers/PostsController.php | 11 +++++ bootstrap/db.php | 19 +++++++++ index.php | 66 +++++++++++++++++++++++++++++ routes.php | 3 ++ simple-template-engine/STEView.php | 56 ++++++++++++++++++++++++ views/login.php | 2 + 11 files changed, 191 insertions(+) create mode 100644 .env create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 app/Controllers/Controller.php create mode 100644 app/Controllers/LoginController.php create mode 100644 app/Controllers/PostsController.php create mode 100644 bootstrap/db.php create mode 100644 index.php create mode 100644 routes.php create mode 100644 simple-template-engine/STEView.php create mode 100644 views/login.php diff --git a/.env b/.env new file mode 100644 index 0000000..540fe36 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +DB_HOST=localhost +DB_USER=root +DB_PASSWORD= +DB_NAME=php-task1 \ No newline at end of file diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..451fb35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +.idea \ No newline at end of file diff --git a/app/Controllers/Controller.php b/app/Controllers/Controller.php new file mode 100644 index 0000000..e11d68e --- /dev/null +++ b/app/Controllers/Controller.php @@ -0,0 +1,14 @@ +viewPath = 'views/'; + $view->render(''.$filename.'.php'); + } +} \ No newline at end of file diff --git a/app/Controllers/LoginController.php b/app/Controllers/LoginController.php new file mode 100644 index 0000000..a3400e8 --- /dev/null +++ b/app/Controllers/LoginController.php @@ -0,0 +1,14 @@ +filename); + + } +} \ No newline at end of file diff --git a/app/Controllers/PostsController.php b/app/Controllers/PostsController.php new file mode 100644 index 0000000..9768573 --- /dev/null +++ b/app/Controllers/PostsController.php @@ -0,0 +1,11 @@ +load(); + +$capsule = new Capsule; +$capsule->addConnection([ + "driver" => "mysql", + "host" => $_ENV['DB_HOST'], + "database" => $_ENV['DB_NAME'], + "username" => $_ENV['DB_USER'], + "password" => $_ENV['DB_PASSWORD'] +]); +$capsule->setAsGlobal(); +$capsule->bootEloquent(); \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..f981835 --- /dev/null +++ b/index.php @@ -0,0 +1,66 @@ +get('/', function(){ + return 'Like at Home!'; +}); + +$router->get('posts', function(){ + echo Posts::all(); +}); + +$router->get('login', [\ps\app\Controllers\LoginController::class, 'actionGetLoginForm']); + +$dispatcher = new Dispatcher($router->getData()); + +try { + + $response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], processInput($_SERVER['REQUEST_URI'])); + +} catch (Phroute\Exception\HttpRouteNotFoundException $e) { + + var_dump($e); + die(); + +} catch (Phroute\Exception\HttpMethodNotAllowedException $e) { + + var_dump($e); + die(); + +} + +processOutput($response); + diff --git a/routes.php b/routes.php new file mode 100644 index 0000000..fdabb4d --- /dev/null +++ b/routes.php @@ -0,0 +1,3 @@ +createContent($view, $data); + + echo $content; + } + + public function fetch(string $view, array $data = []): false|string + { + $content = $this->createContent($view, $data); + + return $content; + } + + private function createContent(string $view, array $data = []): false|string + { + ob_start(); + + foreach ($data as $key => $datum){ + ${"$key"} = $datum; + } + + include ($this->viewPath . $view); + + $content = ob_get_contents(); + ob_end_clean (); + + ob_start(); + $file_content = $content; + + if ($this->layout){ + if (file_exists($this->viewPath . $this->layout)){ + include ($this->viewPath . $this->layout); + $file_content = ob_get_contents(); + } + } + ob_end_clean (); + + return $file_content; + } + +} \ No newline at end of file diff --git a/views/login.php b/views/login.php new file mode 100644 index 0000000..f6f6205 --- /dev/null +++ b/views/login.php @@ -0,0 +1,2 @@ +