diff --git a/.env b/.env index b8ee5f8807fb02975840f68f362cc3f2c5a0bb14..949ba7e3fd613bbc44a7e9ee1f44d6cf807918c9 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ -MYSQL_HOST=db-tubes-1 -MYSQL_DATABASE=tubes-wbd +MYSQL_HOST=host-wbd-1 +MYSQL_DATABASE=db-wbd-1 MYSQL_USER=root MYSQL_PASSWORD=katakunci MYSQL_PORT=3306 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ac9e46d52890ef0f836d6cb5b236933981f528b2..9805a6e36f88ac8f7b39a57fe7c35e3524d73eb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM php:8.0-apache WORKDIR /var/www/html -COPY index.php /var/www/html - +COPY public/index.php . +RUN docker-php-ext-install mysqli pdo pdo_mysql +RUN a2enmod rewrite EXPOSE 80 \ No newline at end of file diff --git a/app/controllers/NotFoundController.php b/app/controllers/NotFoundController.php new file mode 100644 index 0000000000000000000000000000000000000000..2a6d582f9d8418846b2ffbe94818bc7a9f3d5084 --- /dev/null +++ b/app/controllers/NotFoundController.php @@ -0,0 +1,10 @@ +<?php + +class NotFoundController extends Controller implements ControllerInterface +{ + public function index() + { + $notFoundView = $this->view('not-found', 'NotFoundView'); + $notFoundView->render(); + } +} \ No newline at end of file diff --git a/app/controllers/UserController.php b/app/controllers/UserController.php new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/core/Controller.php b/app/core/Controller.php new file mode 100644 index 0000000000000000000000000000000000000000..acdb1935ea5b5d97a7a68bcc3314a65194f11001 --- /dev/null +++ b/app/core/Controller.php @@ -0,0 +1,23 @@ +<?php + +class Controller +{ + public function view($folder, $view, $data = []) + { + require_once __DIR__ . '/../views/' . $folder . '/' . $view . '.php'; + return new $view($data); + } + + public function model($model) + { + echo "Model here"; + require_once __DIR__ . '/../models/' . $model . '.php'; + return new $model(); + } + + /* public function middleware($middleware) + { + require_once __DIR__ . '/../middlewares/' . $middleware . '.php'; + return new $middleware(); + } */ +} \ No newline at end of file diff --git a/app/core/Database.php b/app/core/Database.php index 8a8845dc010db2143b0550437abbc449cad4ddd1..1b1b99c1f0a0d409ab2fb5160b70468abb325753 100644 --- a/app/core/Database.php +++ b/app/core/Database.php @@ -19,6 +19,7 @@ class Database $this->db_connection = new PDO($dsn, $this->user, $this->password, $option); } catch (PDOException) { throw new LoggedException('Bad Gateway', 502); + echo "Bad Gateway"; } try { @@ -28,7 +29,9 @@ class Database $this->db_connection->exec(Tables::INVENTORY_TABLE); } catch (PDOException) { throw new LoggedException('Internal Server Error', 500); + echo "Internal Server Error"; } + echo "Thank you, next"; } public function query($query) @@ -97,4 +100,12 @@ class Database throw new LoggedException('Internal Server Error', 500); } } + public function lastInsertID() + { + try { + return $this->db_connection->lastInsertId(); + } catch (PDOException) { + throw new LoggedException('Internal Server Error', 500); + } + } } \ No newline at end of file diff --git a/app/exceptions/LoggedException.php b/app/exceptions/LoggedException.php new file mode 100644 index 0000000000000000000000000000000000000000..0622d245770cc6ba733c83c61a70582f48b7bdc1 --- /dev/null +++ b/app/exceptions/LoggedException.php @@ -0,0 +1,15 @@ +<?php + +class LoggedException extends Exception +{ + public function __construct($message = '', $code = 0) + { + parent::__construct($message, $code); + $this->logError($message, $code); + } + + private function logError($message, $code) + { + error_log('[ERROR] ' . $code . ': ' . $message); + } +} \ No newline at end of file diff --git a/app/interface/ControllerInterface.php b/app/interface/ControllerInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..1a711bb8c6669520ff5b4cbb9b9d80dfa8d39154 --- /dev/null +++ b/app/interface/ControllerInterface.php @@ -0,0 +1,6 @@ +<?php + +interface ControllerInterface +{ + public function index(); +} \ No newline at end of file diff --git a/app/interface/ViewInterface.php b/app/interface/ViewInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..3f2806ad5704d2741a5aaa1b00786d7ee385e0a1 --- /dev/null +++ b/app/interface/ViewInterface.php @@ -0,0 +1,6 @@ +<?php + +interface ViewInterface +{ + public function render(); +} \ No newline at end of file diff --git a/app/models/BookModel.php b/app/models/BookModel.php new file mode 100644 index 0000000000000000000000000000000000000000..5d695ef5e60c7fa75c2f741960ceffecf19b808f --- /dev/null +++ b/app/models/BookModel.php @@ -0,0 +1,11 @@ + +<?php +class BookModel +{ + private $database; + + public function __construct() + { + $this->database = new Database(); + } +} \ No newline at end of file diff --git a/app/models/UserModel.php b/app/models/UserModel.php new file mode 100644 index 0000000000000000000000000000000000000000..b1e4d416bd9f68e61c5c0062130f9d4707302a7e --- /dev/null +++ b/app/models/UserModel.php @@ -0,0 +1,11 @@ +<?php + +class UserModel +{ + private $database; + + public function __construct() + { + $this->database = new Database(); + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 87773b9bf0584b824103f355fd4fb576166ef9bf..96607e0fe9d6d9335f992aaea3bf041003c834b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,12 +4,18 @@ services: image: tubes-1:latest ports: - 8008:80 + hostname: web-wbd-1 + env_file: .env + volumes: + - ./src:/var/www/html mysql: image: mysql:latest ports: - 3307:3306 - hostname: db-tubes-1 + hostname: db-wbd-1 env_file: .env + volumes: + - ./mysql:/var/lib/mysql diff --git a/index.html b/index.html deleted file mode 100644 index 547041c8c0976bdb945fd13781f1e05a0284759d..0000000000000000000000000000000000000000 --- a/index.html +++ /dev/null @@ -1,42 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - -<head> - <meta charset="UTF-8"> - <meta http-equiv=""X-UA-Compatible" content="IE=edge"> - <meta name = "viewport" content="width=device-width, initial-scale=1.0"> - <title> Sign in</title> - <link rel ="stylesheet" href="style.css"> - <link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'> -</head> - -<body> - <div class="wrapper"> - <form action=""> - <h1>Login</h1> - <div class="input-box"> - <input type="text" placeholder="Username" required> - <i class='bx bxs-user'></i> - - </div> - <div class="input-box"> - <input type="password" placeholder="Password" required> - <i class='bx bxs-lock-alt'></i> - </div> - - <div class="remember-forgot"> - <label><input type="checkbox"> Remember me</label> - <a href="#">Forgot password?</a> - </div> - - <button type="submit" class="btn">Login</button> - - <div class="register-link"> - <p>Don't have an account? - <a href="#">Register</a> - </p> - </div> - </form> - </div> -</body> -</html> \ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index 906518725d58a4e572fc11ce40be4e7d418afda4..0000000000000000000000000000000000000000 --- a/index.php +++ /dev/null @@ -1,42 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - -<head> - <meta charset="UTF-8"> - <meta http-equiv=""X-UA-Compatible" content="IE=edge"> - <meta name = "viewport" content="width=device-width, initial-scale=1.0"> - <title> Sign in</title> - <link rel ="stylesheet" type="text/css" href="style.css"> - <link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'> -</head> - -<body> - <div class="wrapper"> - <form action=""> - <h1>Login</h1> - <div class="input-box"> - <input type="text" placeholder="Username" required> - <i class='bx bxs-user'></i> - - </div> - <div class="input-box"> - <input type="password" placeholder="Password" required> - <i class='bx bxs-lock-alt'></i> - </div> - - <div class="remember-forgot"> - <label><input type="checkbox"> Remember me</label> - <a href="#">Forgot password?</a> - </div> - - <button type="submit" class="btn">Login</button> - - <div class="register-link"> - <p>Don't have an account? - <a href="#">Register</a> - </p> - </div> - </form> - </div> -</body> -</html> \ No newline at end of file diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000000000000000000000000000000000000..90aa015daaebb85376957bd493d167e4aec379eb --- /dev/null +++ b/public/index.php @@ -0,0 +1,4 @@ +<?php +$app = new App(); +echo "Sawadikap"; +?> \ No newline at end of file