From 3f46f82ff64e0c2d6f66ee6373b1a5f533fd3599 Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Mon, 20 Jun 2016 22:30:19 -0300 Subject: [PATCH] refactoring: autload with composer keeping it simple to autoload new files with fantastic dependency manager --- .gitignore | 1 + composer.json | 21 +++++++++++++++++++++ lib/controllers/wishlist.php | 2 +- public/index.php | 7 +------ 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 composer.json diff --git a/.gitignore b/.gitignore index 720afbd..02352d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /data/* !/data/.gitkeep +/vendor \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f67b82d --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "tonicospinelli/developing-for-business", + "description": "A Quick Project to show how to is possible evolute application in Flat PHP to Object Oriented PHP", + "license": "MIT", + "authors": [ + { + "name": "Antonio Spinelli", + "email": "tonicospinelli85@gmail.com" + } + ], + "autoload": { + "files": [ + "./lib/dbconn.php", + "./lib/functions.php", + "./lib/controllers/product.php", + "./lib/controllers/wishlist.php", + "./lib/models/product.php", + "./lib/models/wishlist.php" + ] + } +} diff --git a/lib/controllers/wishlist.php b/lib/controllers/wishlist.php index 069e772..ca747e5 100644 --- a/lib/controllers/wishlist.php +++ b/lib/controllers/wishlist.php @@ -22,6 +22,6 @@ function wishlistRemoveAction($email, $id) if (!removeWishItem($id)) { $errormsg = 'Product could not be removed from wishlist! :('; } - header('Location: /wishlist?' . http_build_query(['email' => $_GET['email']])); + header('Location: /index.php/wishlist?' . http_build_query(['email' => $_GET['email']])); } \ No newline at end of file diff --git a/public/index.php b/public/index.php index 733871d..989a840 100644 --- a/public/index.php +++ b/public/index.php @@ -2,12 +2,7 @@ // load and initialize any global libraries require_once __DIR__ . '/../config/app.php'; -require_once LIBRARY_DIR . '/functions.php'; -require_once LIBRARY_DIR . '/dbconn.php'; -require_once LIBRARY_DIR . '/models/product.php'; -require_once LIBRARY_DIR . '/controllers/product.php'; -require_once LIBRARY_DIR . '/models/wishlist.php'; -require_once LIBRARY_DIR . '/controllers/wishlist.php'; +require_once __DIR__ . '/../vendor/autoload.php'; // route the request internally $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);