. // }}} /** * Base class for feed controllers * * @package GNUsocial * @category Controller * * @author Hugo Sales * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace Component\Collection\Util; use App\Core\DB\DB; use function App\Core\I18n\_m; use App\Core\Router\Router; use App\Util\Exception\ClientException; trait ActorControllerTrait { /** * Generic function that handles getting a representation for an actor from id */ protected function handleActorById(int $id, callable $handle) { $actor = DB::findOneBy('actor', ['id' => $id]); if ($actor->getIsLocal()) { return ['_redirect' => $actor->getUrl(Router::ABSOLUTE_PATH), 'actor' => $actor]; } if (empty($actor)) { throw new ClientException(_m('No such actor.'), 404); } else { return $handle($actor); } } /** * Generic function that handles getting a representation for an actor from nickname */ protected function handleActorByNickname(string $nickname, callable $handle) { $user = DB::findOneBy('local_user', ['nickname' => $nickname]); $actor = DB::findOneBy('actor', ['id' => $user->getId()]); if (empty($actor)) { throw new ClientException(_m('No such actor.'), 404); } else { return $handle($actor); } } }