response->json(['message' => 'Hello, World!']); } /** * @GetMapping(path="/db") */ public function db() { 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}]") */ public function queries($queries = 1) { $queries = $this->clamp($queries); $rows = []; while ($queries--) { $rows[] = World::find(random_int(1, 10000)); } 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") */ public function fortunes() { $rows = Fortune::all(); $insert = new Fortune(); $insert->id = 0; $insert->message = 'Additional fortune added at request time.'; $rows->add($insert); $rows = $rows->sortBy('message'); 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 = '
id | message |
---|---|
{$id} | {$message} |