summaryrefslogtreecommitdiff
path: root/src/Support/Parser.php
blob: 02ec251d62785e83e51f292e46fd6e8c55cc7d21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php

namespace App\Support;

class Parser
{
  /**
   * @return array<string, string>
   */
  public static function parseUser(string $user): array
  {
    $username = $user;
    $server = "";

    if (str_starts_with($user, "@")) {
      $username = substr($user, 1);
      $usernameParts = explode(":", $username);
      $username = $usernameParts[0];
      $server = $usernameParts[1];
    }

    return [
      "username" => $username,
      "server" => $server,
    ];
  }

  /**
   * @return array<string, string>
   */
  public static function parseRoomAlias(string $alias): array
  {
    $name = "";
    $server = "";

    $parts = explode(":", $alias);
    $name = substr($parts[0], 1);
    $server = $parts[1];

    return [
      "name" => $name,
      "server" => $server,
    ];
  }
}