Author: Shivam Mathur (shivammathur)
Date: 2024-11-25T05:11:07+05:30

Commit: 
https://github.com/php/web-downloads/commit/08dc064dd6ab74f564e00f2d9b40b63ace711f14
Raw diff: 
https://github.com/php/web-downloads/commit/08dc064dd6ab74f564e00f2d9b40b63ace711f14.diff

Refactor into directories

Changed paths:
  A  src/Actions/FetchArtifact.php
  A  src/Actions/GetArtifacts.php
  A  src/Http/BaseController.php
  A  src/Http/ControllerInterface.php
  A  src/Http/Controllers/IndexController.php
  A  src/Http/Controllers/PeclController.php
  A  src/Http/Controllers/PhpController.php
  A  src/Http/Controllers/WinlibsController.php
  D  src/BaseHandler.php
  D  src/FetchArtifact.php
  D  src/GetArtifacts.php
  D  src/HandlerInterface.php
  D  src/IndexHandler.php
  D  src/PeclHandler.php
  D  src/PhpHandler.php
  D  src/WinlibsHandler.php
  M  routes.php
  M  src/Router.php


Diff:

diff --git a/routes.php b/routes.php
index 624f643..fd0bacb 100644
--- a/routes.php
+++ b/routes.php
@@ -1,14 +1,14 @@
 <?php
 
-use App\IndexHandler;
-use App\PeclHandler;
-use App\PhpHandler;
-use App\WinlibsHandler;
+use App\Http\Controllers\IndexController;
+use App\Http\Controllers\PeclController;
+use App\Http\Controllers\PhpController;
+use App\Http\Controllers\WinlibsController;
 use App\Router;
 
 $router = new Router();
-$router->registerRoute('/', 'GET', IndexHandler::class);
-$router->registerRoute('/pecl', 'POST', PeclHandler::class, true);
-$router->registerRoute('/winlibs', 'POST', WinlibsHandler::class, true);
-$router->registerRoute('/php', 'POST', PhpHandler::class, true);
+$router->registerRoute('/', 'GET', IndexController::class);
+$router->registerRoute('/pecl', 'POST', PeclController::class, true);
+$router->registerRoute('/winlibs', 'POST', WinlibsController::class, true);
+$router->registerRoute('/php', 'POST', PhpController::class, true);
 $router->handleRequest();
diff --git a/src/FetchArtifact.php b/src/Actions/FetchArtifact.php
similarity index 96%
rename from src/FetchArtifact.php
rename to src/Actions/FetchArtifact.php
index 9279783..2339e1c 100644
--- a/src/FetchArtifact.php
+++ b/src/Actions/FetchArtifact.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace App;
+namespace App\Actions;
 
 class FetchArtifact
 {
diff --git a/src/GetArtifacts.php b/src/Actions/GetArtifacts.php
similarity index 98%
rename from src/GetArtifacts.php
rename to src/Actions/GetArtifacts.php
index 7a38e2d..b1f03d5 100644
--- a/src/GetArtifacts.php
+++ b/src/Actions/GetArtifacts.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace App;
+namespace App\Actions;
 
 class GetArtifacts
 {
diff --git a/src/HandlerInterface.php b/src/HandlerInterface.php
deleted file mode 100644
index f2bdacc..0000000
--- a/src/HandlerInterface.php
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-namespace App;
-
-interface HandlerInterface
-{
-    public function handle(): void;
-}
\ No newline at end of file
diff --git a/src/BaseHandler.php b/src/Http/BaseController.php
similarity index 80%
rename from src/BaseHandler.php
rename to src/Http/BaseController.php
index b6a7961..e0495b7 100644
--- a/src/BaseHandler.php
+++ b/src/Http/BaseController.php
@@ -1,8 +1,8 @@
 <?php
 
-namespace App;
+namespace App\Http;
 
-abstract class BaseHandler implements HandlerInterface
+abstract class BaseController implements ControllerInterface
 {
     public function handle(): void {
         $data = json_decode(file_get_contents('php://input'), true);
diff --git a/src/Http/ControllerInterface.php b/src/Http/ControllerInterface.php
new file mode 100644
index 0000000..bb7a226
--- /dev/null
+++ b/src/Http/ControllerInterface.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace App\Http;
+
+interface ControllerInterface
+{
+    public function handle(): void;
+}
\ No newline at end of file
diff --git a/src/IndexHandler.php b/src/Http/Controllers/IndexController.php
similarity index 69%
rename from src/IndexHandler.php
rename to src/Http/Controllers/IndexController.php
index 62af27b..2a08444 100644
--- a/src/IndexHandler.php
+++ b/src/Http/Controllers/IndexController.php
@@ -1,7 +1,9 @@
 <?php
 
-namespace App;
-class IndexHandler extends BaseHandler
+namespace App\Http\Controllers;
+use App\Http\BaseController;
+
+class IndexController extends BaseController
 {
     public function handle(): void
     {
diff --git a/src/PeclHandler.php b/src/Http/Controllers/PeclController.php
similarity index 89%
rename from src/PeclHandler.php
rename to src/Http/Controllers/PeclController.php
index abba598..511130f 100644
--- a/src/PeclHandler.php
+++ b/src/Http/Controllers/PeclController.php
@@ -1,11 +1,13 @@
 <?php
 
-namespace App;
+namespace App\Http\Controllers;
 
+use App\Actions\FetchArtifact;
+use App\Http\BaseController;
+use App\Validator;
 use Exception;
-use ZipArchive;
 
-class PeclHandler extends BaseHandler
+class PeclController extends BaseController
 {
     protected function validate(mixed $data): bool
     {
diff --git a/src/PhpHandler.php b/src/Http/Controllers/PhpController.php
similarity index 88%
rename from src/PhpHandler.php
rename to src/Http/Controllers/PhpController.php
index e3425e5..0c120c0 100644
--- a/src/PhpHandler.php
+++ b/src/Http/Controllers/PhpController.php
@@ -1,12 +1,13 @@
 <?php
 
-namespace App;
+namespace App\Http\Controllers;
 
-use DateTimeImmutable;
+use App\Actions\FetchArtifact;
+use App\Http\BaseController;
+use App\Validator;
 use Exception;
-use ZipArchive;
 
-class PhpHandler extends BaseHandler
+class PhpController extends BaseController
 {
     protected function validate(array $data): bool
     {
diff --git a/src/WinlibsHandler.php b/src/Http/Controllers/WinlibsController.php
similarity index 87%
rename from src/WinlibsHandler.php
rename to src/Http/Controllers/WinlibsController.php
index f123d82..89d7a55 100644
--- a/src/WinlibsHandler.php
+++ b/src/Http/Controllers/WinlibsController.php
@@ -1,8 +1,12 @@
 <?php
 
-namespace App;
+namespace App\Http\Controllers;
 
-class WinlibsHandler extends BaseHandler
+use App\Actions\GetArtifacts;
+use App\Http\BaseController;
+use App\Validator;
+
+class WinlibsController extends BaseController
 {
     protected function validate(array $data): bool
     {
diff --git a/src/Router.php b/src/Router.php
index 9152eec..06e7ca4 100644
--- a/src/Router.php
+++ b/src/Router.php
@@ -2,6 +2,8 @@
 
 namespace App;
 
+use App\Http\BaseController;
+
 class Router
 {
     private array $routes = [];
@@ -42,7 +44,7 @@ public function handleRequest(): void
                 return;
             }
 
-            /** @var BaseHandler $handler */
+            /** @var BaseController $handler */
             $handler = $route['handler'];
             (new $handler)->handle();
         } elseif (!empty($allowedMethods)) {

Reply via email to