DiscoverActor.php 981 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Util\ActivityPub;
  3. use Zttp\Zttp;
  4. class DiscoverActor
  5. {
  6. protected $url;
  7. protected $response;
  8. public function __construct($url)
  9. {
  10. $this->url = $url;
  11. }
  12. public function fetch()
  13. {
  14. $res = Zttp::withHeaders([
  15. 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
  16. 'User-Agent' => 'PixelfedBot - https://pixelfed.org',
  17. ])->get($this->url);
  18. $this->response = $res->body();
  19. return $this;
  20. }
  21. public function getResponse()
  22. {
  23. return json_decode($this->response, true);
  24. }
  25. public function getJsonResponse()
  26. {
  27. return $this->response;
  28. }
  29. public function discover()
  30. {
  31. $this->fetch();
  32. $res = $this->getResponse();
  33. if (empty($res) || !in_array('type', $res) || $res['type'] !== 'Person') {
  34. throw new \Exception('Invalid Actor Object');
  35. }
  36. return $res;
  37. }
  38. }