. // }}} namespace App\Controller; use App\Core\Controller; use App\Core\DB\DB; use function App\Core\I18n\_m; use App\Util\Exception\ClientException; use Symfony\Component\HttpFoundation\Request; class GSActor extends Controller { /** * Generic function that handles getting a representation for an actor from id */ private function GSActorById(int $id, callable $handle) { $gsactor = DB::findOneBy('gsactor', ['id' => $id]); if (empty($gsactor)) { throw new ClientException(_m('No such actor.'), 404); } else { return $handle($gsactor); } } /** * Generic function that handles getting a representation for an actor from nickname */ private function GSActorByNickname(string $nickname, callable $handle) { $user = DB::findOneBy('local_user', ['nickname' => $nickname]); $gsactor = DB::findOneBy('gsactor', ['id' => $user->getId()]); if (empty($gsactor)) { throw new ClientException(_m('No such actor.'), 404); } else { return $handle($gsactor); } } /** * The page where the note and it's info is shown */ public function GSActorShowId(Request $request, int $id) { return $this->GSActorById($id, fn ($gsactor) => ['_template' => 'actor/view.html.twig', 'gsactor' => $gsactor]); } public function GSActorShowNickname(Request $request, string $nickname) { return $this->GSActorByNickname($nickname, fn ($gsactor) => ['_template' => 'actor/view.html.twig', 'gsactor' => $gsactor]); } }