From 2bdcd9d9283b44e7c35822aa1317013928006fd8 Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Thu, 30 Aug 2018 04:30:53 -0400 Subject: Initialize Repo: First Commit --- bootstrap/Bootstrap.php | 13 ++++++++++++ bootstrap/Request.php | 14 +++++++++++++ bootstrap/Router.php | 42 +++++++++++++++++++++++++++++++++++++ bootstrap/database/Connection.php | 18 ++++++++++++++++ bootstrap/database/QueryBuilder.php | 31 +++++++++++++++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 bootstrap/Bootstrap.php create mode 100644 bootstrap/Request.php create mode 100644 bootstrap/Router.php create mode 100644 bootstrap/database/Connection.php create mode 100644 bootstrap/database/QueryBuilder.php (limited to 'bootstrap') diff --git a/bootstrap/Bootstrap.php b/bootstrap/Bootstrap.php new file mode 100644 index 0000000..c91edd8 --- /dev/null +++ b/bootstrap/Bootstrap.php @@ -0,0 +1,13 @@ + [], + 'POST' => [], + 'HEAD' => [] + ]; + + public function get($uri, $controller) + { + $this->routes['GET'][$uri] = $controller; + } + + public function post($uri, $controller) + { + $this->routes['POST'][$uri] = $controller; + } + + public function head($uri, $controller) + { + $this->routes['HEAD'][$uri] = $controller; + } + + public static function load($file) + { + $router = new static; + require $file; + return $router; + } + + public function direct($uri, $requestType) + { + if (is_array($this->routes[$requestType]) && array_key_exists($uri, $this->routes[$requestType])) { + return $this->routes[$requestType][$uri]; + } + // throw new Exception('No route defined for this URI: "'.$uri.'"'); + http_response_code(404); + die(require '../app/views/404.view.php'); + } +} diff --git a/bootstrap/database/Connection.php b/bootstrap/database/Connection.php new file mode 100644 index 0000000..deec2c6 --- /dev/null +++ b/bootstrap/database/Connection.php @@ -0,0 +1,18 @@ +getMessage()); + } + } +} diff --git a/bootstrap/database/QueryBuilder.php b/bootstrap/database/QueryBuilder.php new file mode 100644 index 0000000..a814ed3 --- /dev/null +++ b/bootstrap/database/QueryBuilder.php @@ -0,0 +1,31 @@ +pdo = $pdo; + } + + public function selectAll($table, $intoClass) + { + $statement = $this->pdo->prepare("select * from {$table}"); + $statement->execute(); + return $statement->fetchAll(PDO::FETCH_CLASS, $intoClass); + } + + public function insert($table, $data) + { + $sql = sprintf( + 'insert into %s (%s) values (%s)', + $table, + implode(', ', array_keys($data)), + ':' . implode(', :', array_keys($data)) + ); + + $statment = $this->pdo->prepare($sql); + $statment->execute($data); + } +} -- cgit v1.2.3