gnu-social/plugins/ActivityPub/Util/Response/ActorResponse.php

28 lines
731 B
PHP
Raw Normal View History

<?php
declare(strict_types = 1);
namespace Plugin\ActivityPub\Util\Response;
2021-09-18 03:22:27 +01:00
use App\Entity\Actor;
use App\Util\Exception\ClientException;
use Exception;
use Plugin\ActivityPub\Util\Model\EntityToType\GSActorToType;
abstract class ActorResponse
{
/**
* @param int $status The response status code
*
2021-09-18 03:22:27 +01:00
*@throws Exception
*/
2021-09-18 03:22:27 +01:00
public static function handle(Actor $gsactor, int $status = 200): TypeResponse
{
if ($gsactor->getIsLocal()) {
return new TypeResponse(data: GSActorToType::translate($gsactor), status: $status);
} else {
throw new ClientException('This is a remote actor, you should request it to its source of authority instead.');
}
}
}