Browse Source

add a framework php/cyberphp

root 7 months ago
parent
commit
0e431e4386

+ 2 - 2
frameworks/PHP/cyberphp/README.md

@@ -15,11 +15,11 @@ http://localhost:8080/db
 
 ### QUERY
 
-http://localhost:8080/query/[count]
+http://localhost:8080/queries/[count]
 
 ### UPDATE
 
-http://localhost:8080/update/[count]
+http://localhost:8080/updates/[count]
 
 ### FORTUNES
 

+ 3 - 3
frameworks/PHP/cyberphp/app/config.php

@@ -16,9 +16,9 @@ return [
     ],
     'orm' => 'pdo',
     'pdo' => [
-        'dsn' => 'pgsql:host=tfb-database;dbname=hello_world',
-        'username' => 'benchmarkdbuser',
-        'password' => 'benchmarkdbpass',
+        'dsn' => 'mysql:host=127.0.0.1;dbname=hello_world',
+        'username' => 'root',
+        'password' => 'root',
         'options' => [
             PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
             PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,

+ 4 - 4
frameworks/PHP/cyberphp/app/controller/Index.php

@@ -38,10 +38,10 @@ class Index {
         return Response::html("<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>$html</table></body></html>");
     }
 
-    public function queries($q = 1)
+    public function queries($q=1)
     {
         $statement = app()->db->prepare('SELECT id,randomNumber FROM World WHERE id=?');
-        $query_count = min(max((int) $q, 1), 500);
+        $query_count = max(min(intval($q), 500), 1);
         $arr = [];
         while ($query_count--) {
             $statement->execute([mt_rand(1, 10000)]);
@@ -50,12 +50,12 @@ class Index {
         return Response::json($arr);
     }
 
-    public function updates($q = 1)
+    public function updates($q=1)
     {
         static $updates = [];
 
         $random = app()->db->prepare('SELECT id,randomNumber FROM World WHERE id=?');
-        $count = min(max((int) $q, 1), 500);
+        $count = max(min(intval($q), 500), 1);
 
         $worlds = $keys = $values = [];
         for ($i = 0; $i < $count; ++ $i) {

+ 10 - 4
frameworks/PHP/cyberphp/src/App.php

@@ -91,16 +91,22 @@ class App
         $requestMiddlewares = $this->getConfig('request_middleware');
         
         /* Execute request object middleware */
-        $this->request = $this->middleware->handleRequest($requestMiddlewares);
+        if(!empty($requestMiddlewares)){
+            $this->request = $this->middleware->handleRequest($requestMiddlewares);
+        }
         
         /* Parse route and return the closure to be executed */
         $handleRoute = $this->route->handleRoute();
         /* Middleware list */
         $Middlewares = $this->getConfig('middleware');
         /* Execute middleware */
-        $response = $this->middleware->handle($Middlewares,function() use ($handleRoute) {
-            return $handleRoute;
-        });
+        if(!empty($Middlewares)){
+            $response = $this->middleware->handle($Middlewares,function() use ($handleRoute) {
+                return $handleRoute;
+            });
+        }else{
+            $response =  $handleRoute;
+        }
         /* Return response */
         return $response;
     }

+ 2 - 2
frameworks/PHP/cyberphp/src/Route.php

@@ -40,14 +40,14 @@ class Route
         } elseif ($routeInfo[0] == 1) {
             $handler = $routeInfo[1];
             $vars = $routeInfo[2];
-            $parameters = [$request, ...array_values($vars)];
+            $parameters = [...array_values($vars)];
 
             // Create a closure to pass to your middleware to execute the final handler
             $finalHandler = function() use ($handler, $parameters, $container) {
                 // If handler is a string (controller@method)
                 if (is_string($handler)) {
                     list($controller, $method) = explode('@', $handler);
-                    $class = $container->get($controller);
+                    $class = new $controller();
                     return $class->$method(...$parameters);
                 } elseif (is_callable($handler)) {
                     return $handler(...$parameters);