-
Notifications
You must be signed in to change notification settings - Fork 2
/
inc.account.php
41 lines (32 loc) · 1015 Bytes
/
inc.account.php
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
<?php
class Account {
public function __construct(
public string $apiUrl,
public string $auth,
public string $username,
public string $server,
public bool $active,
) {}
public function getServerLabel() : string {
return parse_url($this->server, PHP_URL_HOST);
}
public function getLabel() : string {
return $this->username . ' @ ' . $this->getServerLabel();
}
public function pack() : array {
return [$this->apiUrl, $this->auth, $this->username, $this->server];
}
static public function unpackAll( array $infos ) : array {
$accounts = [];
foreach ( $infos AS $i => $info ) {
$accounts[] = static::unpackOne($info, $i == 0);
}
return $accounts;
}
static public function fromLogin( string $apiUrl, string $auth, string $username, string $server ) : self {
return new static($apiUrl, $auth, $username, $server, false);
}
static public function unpackOne( array $info, bool $active ) : self {
return new static($info[0], $info[1], $info[2], $info[3], $active);
}
}