Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
all: glue stuff together so we can have basic routing capabilities
app/controllers/HelloController.php | 7 +++++++ bootstrap.php | 12 ++++++++++++ config/database.php | 8 ++++++++ config/routes.php | 15 +++++++++++++++ public/index.php | 3 +++
diff --git a/app/controllers/HelloController.php b/app/controllers/HelloController.php new file mode 100644 index 0000000000000000000000000000000000000000..d71cfc4b87b4fcedc6a532aecea513ca58f8abc4 --- /dev/null +++ b/app/controllers/HelloController.php @@ -0,0 +1,7 @@ +<?php + +class HelloController { + public function index() { + return 'Hello, World!'; + } +} diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..3b36292fb11d952d5dfdbce49f896a1bcdd23ca2 --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,12 @@ +<?php + +ini_set('display_errors', 1); +ini_set('display_startup_errors', 1); +error_reporting(E_ALL); + +session_start(); + +require_once 'config/database.php'; +$app = require_once 'config/routes.php'; + +echo $app(); diff --git a/config/database.php b/config/database.php new file mode 100644 index 0000000000000000000000000000000000000000..c4485df86155ee9b5e1e88dd9fb8fd4eefae791a --- /dev/null +++ b/config/database.php @@ -0,0 +1,8 @@ +<?php + +function getDatabaseConnection() { + $pdo = new PDO('sqlite:storage/database.sqlite'); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + return $pdo; +} diff --git a/config/routes.php b/config/routes.php new file mode 100644 index 0000000000000000000000000000000000000000..47abe429136e98b75b7c4848f56859356c3caa4b --- /dev/null +++ b/config/routes.php @@ -0,0 +1,15 @@ +<?php + +// TODO: Usar um autoload aqui +require_once '../app/controllers/HelloController.php'; + +return function() { + $uri = trim($_SERVER['REQUEST_URI'], '/'); + + if ($uri === '') { + return (new HelloController())->index(); + } + + http_response_code(404); + return '404 Not Found'; +}; diff --git a/public/index.php b/public/index.php new file mode 100644 index 0000000000000000000000000000000000000000..424c89b677c7a7f008f19c0fef8d3ae72cd5268e --- /dev/null +++ b/public/index.php @@ -0,0 +1,3 @@ +<?php + +require_once '../bootstrap.php';