From 5d83143664aba11bc319f8cc3779673f80f95bea Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Mon, 12 Nov 2018 17:13:29 +0100 Subject: [PATCH 1/2] Use composer autoloader for source files (except tests) --- server/composer.json | 3 ++ server/index.php | 44 ------------------- server/tests/controllers/user/loginTest.php | 2 - server/tests/libs/HashingTest.php | 2 - .../libs/LinearCongruentialGeneratorTest.php | 3 -- server/tests/libs/validations/captchaTest.php | 3 -- server/tests/models/DataStoreTest.php | 1 - server/tests/models/MailTemplateTest.php | 1 - server/tests/models/ResponseTest.php | 1 - 9 files changed, 3 insertions(+), 57 deletions(-) diff --git a/server/composer.json b/server/composer.json index 33104af1..48bc8e7b 100755 --- a/server/composer.json +++ b/server/composer.json @@ -11,5 +11,8 @@ }, "require-dev": { "phpunit/phpunit": "^5.7" + }, + "autoload":{ + "classmap": ["libs/", "models/", "controllers/", "data/"] } } diff --git a/server/index.php b/server/index.php index 66048610..0702f045 100644 --- a/server/index.php +++ b/server/index.php @@ -15,49 +15,5 @@ if(defined('MYSQL_HOST') && defined('MYSQL_DATABASE') && defined('MYSQL_USER') & \Slim\Slim::registerAutoLoader(); $app = new \Slim\Slim(); -// LOAD LIBRARIES -include_once 'libs/Controller.php'; -include_once 'libs/ControllerGroup.php'; -include_once 'libs/Hashing.php'; -include_once 'libs/MailSender.php'; -include_once 'libs/Date.php'; -include_once 'libs/DataStoreList.php'; -include_once 'libs/LinearCongruentialGenerator.php'; -include_once 'libs/FileManager.php'; -include_once 'libs/FileDownloader.php'; -include_once 'libs/FileUploader.php'; - Controller::init(); - -// LOAD DATA -spl_autoload_register(function ($class) { - $classPath = "data/{$class}.php"; - - if(file_exists($classPath)) { - include_once $classPath; - } -}); - -// LOAD MODELS -spl_autoload_register(function ($class) { - $classPath = "models/{$class}.php"; - - if(file_exists($classPath)) { - include_once $classPath; - } -}); - -// LOAD CUSTOM VALIDATIONS -include_once 'libs/validations/dataStoreId.php'; -include_once 'libs/validations/userEmail.php'; -include_once 'libs/validations/staffEmail.php'; -include_once 'libs/validations/captcha.php'; -include_once 'libs/validations/validLanguage.php'; -include_once 'libs/validations/validTicketNumber.php'; - -// LOAD CONTROLLERS -foreach (glob('controllers/*.php') as $controller) { - include_once $controller; -} - $app->run(); diff --git a/server/tests/controllers/user/loginTest.php b/server/tests/controllers/user/loginTest.php index f86ec8b6..0cca2e80 100755 --- a/server/tests/controllers/user/loginTest.php +++ b/server/tests/controllers/user/loginTest.php @@ -10,8 +10,6 @@ include_once 'tests/__mocks__/HashingMock.php'; include_once 'tests/__mocks__/SessionCookieMock.php'; include_once 'data/ERRORS.php'; -include_once 'controllers/user/login.php'; - use PHPUnit\Framework\TestCase; class LoginControllerTest extends TestCase { diff --git a/server/tests/libs/HashingTest.php b/server/tests/libs/HashingTest.php index 9b4cfb95..966be913 100644 --- a/server/tests/libs/HashingTest.php +++ b/server/tests/libs/HashingTest.php @@ -1,6 +1,4 @@ Date: Mon, 12 Nov 2018 17:46:44 +0100 Subject: [PATCH 2/2] Removed some more includes; restore loading controller groups manually --- server/controllers/article.php | 8 ------ server/controllers/staff.php | 13 ---------- server/controllers/system.php | 28 --------------------- server/controllers/system/init-database.php | 1 - server/controllers/ticket.php | 15 ----------- server/controllers/user.php | 19 -------------- server/data/InitialMails.php | 2 -- server/index.php | 5 ++++ server/libs/Controller.php | 3 --- server/libs/DataStoreList.php | 2 -- server/libs/Validator.php | 2 -- 11 files changed, 5 insertions(+), 93 deletions(-) diff --git a/server/controllers/article.php b/server/controllers/article.php index e2079885..6d8b6285 100755 --- a/server/controllers/article.php +++ b/server/controllers/article.php @@ -1,12 +1,4 @@ setGroupPath('/article'); diff --git a/server/controllers/staff.php b/server/controllers/staff.php index 9967e9db..997c5f25 100755 --- a/server/controllers/staff.php +++ b/server/controllers/staff.php @@ -1,17 +1,4 @@ setGroupPath('/staff'); diff --git a/server/controllers/system.php b/server/controllers/system.php index 458dd036..733f6810 100755 --- a/server/controllers/system.php +++ b/server/controllers/system.php @@ -1,32 +1,4 @@ setGroupPath('/system'); diff --git a/server/controllers/system/init-database.php b/server/controllers/system/init-database.php index 67aefd8c..3d5a8793 100755 --- a/server/controllers/system/init-database.php +++ b/server/controllers/system/init-database.php @@ -1,5 +1,4 @@ setGroupPath('/ticket'); diff --git a/server/controllers/user.php b/server/controllers/user.php index 7d10b549..d65541f7 100755 --- a/server/controllers/user.php +++ b/server/controllers/user.php @@ -1,23 +1,4 @@ setGroupPath('/user'); diff --git a/server/data/InitialMails.php b/server/data/InitialMails.php index 70030839..61a396a1 100755 --- a/server/data/InitialMails.php +++ b/server/data/InitialMails.php @@ -1,6 +1,4 @@ run(); diff --git a/server/libs/Controller.php b/server/libs/Controller.php index 246e3e6f..15df8c85 100755 --- a/server/libs/Controller.php +++ b/server/libs/Controller.php @@ -1,7 +1,4 @@