From 97b654006a9975c84813697b364adc9fae0dc225 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Thu, 11 Sep 2025 11:36:46 -0500 Subject: [PATCH] switch to autoload --- .gitignore | 3 ++- App.php | 7 ------- Context.php | 3 --- Response.php | 1 - auth/Auth.php | 3 --- auth/AuthMiddleware.php | 1 - autoload.php | 25 +++++++++++++++++++++++++ 7 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 autoload.php diff --git a/.gitignore b/.gitignore index c816185..6147c44 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.claude \ No newline at end of file +.claude +test_*.php \ No newline at end of file diff --git a/App.php b/App.php index c4a4007..a3e7492 100644 --- a/App.php +++ b/App.php @@ -2,13 +2,6 @@ namespace Web; -require_once __DIR__ . '/HTTPMethod.php'; -require_once __DIR__ . '/Request.php'; -require_once __DIR__ . '/Response.php'; -require_once __DIR__ . '/Context.php'; -require_once __DIR__ . '/Router.php'; -require_once __DIR__ . '/ErrorHandler.php'; -require_once __DIR__ . '/Cookies.php'; /** * App is the application controller itself diff --git a/Context.php b/Context.php index 73eca06..16c5a2e 100644 --- a/Context.php +++ b/Context.php @@ -2,9 +2,6 @@ namespace Web; -require_once __DIR__ . '/Session.php'; -require_once __DIR__ . '/Validator.php'; -require_once __DIR__ . '/Cookies.php'; /** * Context holds the request, response, and shared state for a request diff --git a/Response.php b/Response.php index 1a75460..463fdf0 100644 --- a/Response.php +++ b/Response.php @@ -2,7 +2,6 @@ namespace Web; -require_once __DIR__ . '/Cookies.php'; /** * Response class represents an HTTP response diff --git a/auth/Auth.php b/auth/Auth.php index a57d4bc..c78a8ca 100644 --- a/auth/Auth.php +++ b/auth/Auth.php @@ -2,9 +2,6 @@ namespace Web; -require_once __DIR__ . '/User.php'; -require_once __DIR__ . '/../Session.php'; -require_once __DIR__ . '/../Cookies.php'; /** * Simplified Auth handles user authentication with external verification diff --git a/auth/AuthMiddleware.php b/auth/AuthMiddleware.php index 2a3e23c..443554a 100644 --- a/auth/AuthMiddleware.php +++ b/auth/AuthMiddleware.php @@ -2,7 +2,6 @@ namespace Web; -require_once __DIR__ . '/Auth.php'; /** * AuthMiddleware provides authentication checks for routes diff --git a/autoload.php b/autoload.php new file mode 100644 index 0000000..d9277f8 --- /dev/null +++ b/autoload.php @@ -0,0 +1,25 @@ + __DIR__ . '/App.php', + 'Web\\Context' => __DIR__ . '/Context.php', + 'Web\\Cookies' => __DIR__ . '/Cookies.php', + 'Web\\ErrorHandler' => __DIR__ . '/ErrorHandler.php', + 'Web\\HTTPMethod' => __DIR__ . '/HTTPMethod.php', + 'Web\\Request' => __DIR__ . '/Request.php', + 'Web\\Response' => __DIR__ . '/Response.php', + 'Web\\Router' => __DIR__ . '/Router.php', + 'Web\\Session' => __DIR__ . '/Session.php', + 'Web\\Validator' => __DIR__ . '/Validator.php', + 'Web\\Auth' => __DIR__ . '/auth/Auth.php', + 'Web\\AuthMiddleware' => __DIR__ . '/auth/AuthMiddleware.php', + 'Web\\User' => __DIR__ . '/auth/User.php', + ]; + + // Check if class exists in the map + if (isset($classMap[$class])) { + require_once $classMap[$class]; + } +}); \ No newline at end of file