public function getUser(string $username = null) : array { if (!$this->user) { if (!$username) { throw new \RuntimeException('No user was authenticated yet, the username parameter is mandatory'); } // IDEA separate into AuthDao / UsersDao, both to clean things up // and to show an example of how to work with a child of Dao $data = Database::run('SELECT id, username, email, password FROM users WHERE username = ?', [$username], [Col::INT()]); if (!$data) { return $res->build(HttpStatus::NotFound, [], ['title' => 'User not found', 'detail' => 'No user exists with the provided username']); } $this->user = $data[0]; } return $this->user; }
public function deleteOne(int $id) : int { return $this->db->run('delete from ' . $this->tableName . ' where ' . $this->idName . ' = ?', [Col::INT() => $id]); }