AccountTransformer.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Transformer\Api\Mastodon\v1;
  3. use App\Profile;
  4. use League\Fractal;
  5. use Illuminate\Support\Str;
  6. class AccountTransformer extends Fractal\TransformerAbstract
  7. {
  8. public function transform(Profile $profile)
  9. {
  10. $local = $profile->domain == null;
  11. $username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
  12. return [
  13. 'id' => (string) $profile->id,
  14. 'username' => $username,
  15. 'acct' => $username,
  16. 'display_name' => $profile->name,
  17. 'locked' => (bool) $profile->is_private,
  18. 'bot' => false,
  19. 'created_at' => $profile->created_at->toJSON(),
  20. 'note' => $profile->bio ?? '',
  21. 'url' => $profile->url(),
  22. 'avatar' => $profile->avatarUrl(),
  23. 'avatar_static' => $profile->avatarUrl(),
  24. 'header' => url('/storage/headers/missing.png'),
  25. 'header_static' => url('/storage/headers/missing.png'),
  26. 'followers_count' => (int) $profile->followerCount(),
  27. 'following_count' => (int) $profile->followingCount(),
  28. 'statuses_count' => (int) $profile->statusCount(),
  29. 'last_status_at' => optional($profile->last_status_at)->toJSON(),
  30. 'emojis' => [],
  31. 'moved' => null,
  32. 'fields' => [],
  33. ];
  34. }
  35. }