aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2018-08-30 04:30:53 -0400
committerThedro Neely <thedroneely@gmail.com>2018-08-30 04:30:53 -0400
commit2bdcd9d9283b44e7c35822aa1317013928006fd8 (patch)
treeca2bf097e4dfcfdabba36a5cb2643560ab03b926 /bootstrap
downloadthedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.gz
thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.tar.bz2
thedroneely.com-2bdcd9d9283b44e7c35822aa1317013928006fd8.zip
Initialize Repo: First Commit
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/Bootstrap.php13
-rw-r--r--bootstrap/Request.php14
-rw-r--r--bootstrap/Router.php42
-rw-r--r--bootstrap/database/Connection.php18
-rw-r--r--bootstrap/database/QueryBuilder.php31
5 files changed, 118 insertions, 0 deletions
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 @@
+<?php
+
+/* composer autoloader */
+require '../vendor/autoload.php';
+
+/* app functions */
+require '../app/Functions.php';
+
+/* source config file */
+$config = include '../AppConfig.php';
+
+/* database query setup */
+$contact['database'] = new QueryBuilder(Connection::make($config['database']));
diff --git a/bootstrap/Request.php b/bootstrap/Request.php
new file mode 100644
index 0000000..cc8e687
--- /dev/null
+++ b/bootstrap/Request.php
@@ -0,0 +1,14 @@
+<?php
+
+class Request
+{
+ public static function uri()
+ {
+ return (string) trim($_SERVER['REQUEST_URI'], "/");
+ }
+
+ public static function method()
+ {
+ return $_SERVER['REQUEST_METHOD'];
+ }
+}
diff --git a/bootstrap/Router.php b/bootstrap/Router.php
new file mode 100644
index 0000000..9673c36
--- /dev/null
+++ b/bootstrap/Router.php
@@ -0,0 +1,42 @@
+<?php
+
+class Router
+{
+ protected $routes = [
+ 'GET' => [],
+ '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 @@
+<?php
+
+class Connection
+{
+ public static function make($config)
+ {
+ try {
+ return new PDO(
+ $config['connection'].';dbname='.$config['name'],
+ $config['username'],
+ $config['password'],
+ $config['options']
+ );
+ } catch (PDOException $e) {
+ error_log($e->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 @@
+<?php
+
+class QueryBuilder
+{
+ protected $pdo;
+
+ public function __construct($pdo)
+ {
+ $this->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);
+ }
+}