|
@@ -15,7 +15,9 @@ namespace App\Controller;
|
|
use App\Model\Fortune;
|
|
use App\Model\Fortune;
|
|
use App\Model\World;
|
|
use App\Model\World;
|
|
use App\Render;
|
|
use App\Render;
|
|
|
|
+use Hyperf\DbConnection\Db;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
+use Hyperf\HttpMessage\Stream\SwooleStream;
|
|
use Hyperf\HttpServer\Annotation\Controller;
|
|
use Hyperf\HttpServer\Annotation\Controller;
|
|
use Hyperf\HttpServer\Annotation\GetMapping;
|
|
use Hyperf\HttpServer\Annotation\GetMapping;
|
|
use Hyperf\HttpServer\Contract\ResponseInterface;
|
|
use Hyperf\HttpServer\Contract\ResponseInterface;
|
|
@@ -54,6 +56,14 @@ class IndexController
|
|
return $this->response->json(World::find(random_int(1, 10000)));
|
|
return $this->response->json(World::find(random_int(1, 10000)));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @GetMapping(path="/raw-db")
|
|
|
|
+ */
|
|
|
|
+ public function rawDb()
|
|
|
|
+ {
|
|
|
|
+ return $this->response->json(Db::select('SELECT id, randomNumber FROM World WHERE id = ?', [random_int(1, 10000)]));
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @GetMapping(path="/queries/[{queries}]")
|
|
* @GetMapping(path="/queries/[{queries}]")
|
|
*/
|
|
*/
|
|
@@ -70,6 +80,22 @@ class IndexController
|
|
return $this->response->json($rows);
|
|
return $this->response->json($rows);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @GetMapping(path="/raw-queries/[{queries}]")
|
|
|
|
+ */
|
|
|
|
+ public function rawQueries($queries = 1)
|
|
|
|
+ {
|
|
|
|
+ $queries = $this->clamp($queries);
|
|
|
|
+
|
|
|
|
+ $rows = [];
|
|
|
|
+
|
|
|
|
+ while ($queries--) {
|
|
|
|
+ $rows[] = Db::selectOne('SELECT id, randomNumber FROM World WHERE id = ?', [random_int(1, 10000)]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $this->response->json($rows);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @GetMapping(path="/fortunes")
|
|
* @GetMapping(path="/fortunes")
|
|
*/
|
|
*/
|
|
@@ -87,6 +113,30 @@ class IndexController
|
|
return $this->render->render('fortunes', ['rows' => $rows]);
|
|
return $this->render->render('fortunes', ['rows' => $rows]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @GetMapping(path="/micro-fortunes")
|
|
|
|
+ */
|
|
|
|
+ public function microFortunes()
|
|
|
|
+ {
|
|
|
|
+ $rows = Db::select('SELECT id, message FROM Fortune');
|
|
|
|
+
|
|
|
|
+ $fortune = [];
|
|
|
|
+ foreach ($rows ?? [] as $row) {
|
|
|
|
+ $fortune[$row->id] = $row->message;
|
|
|
|
+ }
|
|
|
|
+ $fortune[0] = 'Additional fortune added at request time.';
|
|
|
|
+ asort($fortune);
|
|
|
|
+
|
|
|
|
+ $html = '<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>';
|
|
|
|
+ foreach ($fortune as $id => $message) {
|
|
|
|
+ $message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8');
|
|
|
|
+ $html .= "<tr><td>{$id}</td><td>{$message}</td></tr>";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $html .= '</table></body></html>';
|
|
|
|
+ return $this->response->withAddedHeader('content-type', 'text/html; charset=utf-8')->withBody(new SwooleStream($html));
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @GetMapping(path="/updates/[{queries}]")
|
|
* @GetMapping(path="/updates/[{queries}]")
|
|
*/
|
|
*/
|
|
@@ -106,6 +156,26 @@ class IndexController
|
|
return $this->response->json($rows);
|
|
return $this->response->json($rows);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @GetMapping(path="/raw-updates/[{queries}]")
|
|
|
|
+ */
|
|
|
|
+ public function rawUpdates($queries = 1)
|
|
|
|
+ {
|
|
|
|
+ $queries = $this->clamp($queries);
|
|
|
|
+
|
|
|
|
+ $rows = [];
|
|
|
|
+
|
|
|
|
+ while ($queries--) {
|
|
|
|
+ $row = Db::selectOne('SELECT id, randomNumber FROM World WHERE id = ?', [$id = random_int(1, 10000)]);
|
|
|
|
+ $rand = random_int(1, 10000);
|
|
|
|
+ $row->randomNumber = $rand;
|
|
|
|
+ Db::update('UPDATE World SET randomNumber = ? WHERE id = ?', [$rand, $id]);
|
|
|
|
+ $rows[] = $row;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $this->response->json($rows);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @GetMapping(path="/plaintext")
|
|
* @GetMapping(path="/plaintext")
|
|
*/
|
|
*/
|