Bläddra i källkod

Fortune testcase for Kohana

Skamander 12 år sedan
förälder
incheckning
eec82b1e11

+ 28 - 0
php-kohana/application/classes/Controller/Bench.php

@@ -29,4 +29,32 @@ Class Controller_Bench extends Controller
             ->headers(array('Content-Type' => 'application/json'))
             ->body(json_encode($worlds));
     }
+
+    public function action_fortunes()
+    {
+        $fortunes = DB::select()->from('Fortune')
+            ->execute()
+            ->as_array();
+
+        $fortunes[] = array(
+            'id' => 0,
+            'message' => 'Additional fortune added at request time.'
+        );
+
+        usort($fortunes, function($left, $right) {
+            if ($left['message'] === $right['message']) {
+                return 0;
+            } else if ($left['message'] > $right['message']) {
+                return 1;
+            } else {
+                return -1;
+            }
+        });
+
+        $this->response->body(
+            View::factory('bench/fortunes')
+                ->bind('fortunes', $fortunes)
+                ->render()
+        );
+    }
 }

+ 25 - 0
php-kohana/application/views/bench/fortunes.php

@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Benchmark</title>
+</head>
+<body>
+
+<table>
+    <tr>
+        <th>id</th>
+        <th>message</th>
+    </tr>
+
+    <?php foreach($fortunes as $fortune): ?>
+        <tr>
+            <td><?php echo $fortune['id']; ?></td>
+            <td><?php echo htmlspecialchars($fortune['message'], ENT_QUOTES, "UTF-8", false); ?></td>
+        </tr>
+    <?php endforeach; ?>
+
+</table>
+
+</body>
+</html>

+ 1 - 0
php-kohana/benchmark_config

@@ -11,6 +11,7 @@
       "setup_file": "setup",
       "db_url": "/bench/db",
       "query_url": "/bench/db/",
+      "fortune_url": "/bench/fortunes",
       "port": 8080,
       "sort": 61
     }