Nickname.php 700 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Util\Lexer;
  3. use Illuminate\Support\Str;
  4. class Nickname
  5. {
  6. public static function normalizeProfileUrl($url)
  7. {
  8. if(!Str::of($url)->contains('@')) {
  9. return;
  10. }
  11. if(Str::startsWith($url, 'acct:')) {
  12. $url = str_replace('acct:', '', $url);
  13. }
  14. if(Str::startsWith($url, '@')) {
  15. $url = substr($url, 1);
  16. if(!Str::of($url)->contains('@')) {
  17. return;
  18. }
  19. }
  20. $parts = explode('@', $url);
  21. $username = $parts[0];
  22. $domain = $parts[1];
  23. return [
  24. 'domain' => $domain,
  25. 'username' => $username
  26. ];
  27. }
  28. }