'Hello, World!']; } /** * @Action */ public function plaintext(): IHttpResponse { $response = $this->response; $response->setHeader('Content-Type', 'text/plain; charset=utf-8') ->getBody() ->write('Hello, World!'); return $response; } /** * @Action */ public function dbModel(): ?World { return World::find(\mt_rand(1, 10000)); } /** * @Action */ public function dbRaw(): array { $db = Db::getInstance(); $stmt = $db->prepare('SELECT id, randomNumber FROM World WHERE id = ? LIMIT 1'); $stmt->execute([\mt_rand(1, 10000)]); return $stmt->fetch(); } /** * @Action */ public function queryModel($queries): array { $queries = (int)$queries; if($queries > 1) { $queryCount = \min($queries, 500); } else { $queryCount = 1; } $list = []; while ($queryCount--) { $list[] = World::find(\mt_rand(1, 10000)); } return $list; } /** * @Action * * @return void */ public function queryRaw($queries): array { $queries = (int)$queries; if($queries > 1) { $queryCount = \min($queries, 500); } else { $queryCount = 1; } $list = []; $db = Db::getInstance(); $stmt = $db->prepare('SELECT id, randomNumber FROM World WHERE id = ? LIMIT 1'); while ($queryCount--) { $stmt->execute([\mt_rand(1, 10000)]); $list[] = $stmt->fetch(); } return $list; } /** * @Action * @View(renderType="html") */ public function fortunes(): array { $this->response->setHeader('Content-Type', 'text/html; charset=UTF-8'); $list = Fortune::select(); $rows = []; foreach($list as $item) { $rows[$item->id] = $item->message; } $rows[0] = 'Additional fortune added at request time.'; \asort($rows); return [ 'rows' => $rows, ]; } /** * @Action * @View(renderType="html") * * @return void */ public function fortunesRaw(): IHttpResponse { $rows = []; foreach(Db::getInstance()->query('SELECT id, message FROM Fortune')->fetchAll() as $item) { $rows[$item['id']] = $item['message']; } $rows[0] = 'Additional fortune added at request time.'; \asort($rows); $html = ''; foreach ($rows as $id => $message) { $message = \htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); $html .= "
id | message |
---|