-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.php
More file actions
28 lines (24 loc) · 745 Bytes
/
Copy pathConfig.php
File metadata and controls
28 lines (24 loc) · 745 Bytes
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
<?php
namespace Gared\EtherScan\Model;
class Config
{
public readonly string $padId;
public ?string $pathPrefix = null;
public function __construct(
public string $baseUrl,
public readonly float $timeout = 5.0,
) {
$domain = parse_url($this->baseUrl, PHP_URL_HOST);
if (is_string($domain) === false) {
$domain = $this->baseUrl;
}
$hash = $this->generateShortHash($domain);
$this->padId = 'test' . $hash;
}
private function generateShortHash(string $domain): string
{
$base64 = base64_encode(hash('sha256', $domain, true));
$hashStripped = str_replace(['+', '/'], '', $base64);
return substr($hashStripped, 0, 5);
}
}