-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathApiSettings.php
53 lines (44 loc) · 1.29 KB
/
ApiSettings.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
42
43
44
45
46
47
48
49
50
51
52
53
<?php declare(strict_types=1);
namespace ApiClients\Client\Pusher;
use Jean85\PrettyVersions;
final class ApiSettings
{
/**
* Create Pusher compatible version.
*
* @param string $version
* @return string
*/
public static function getVersion(string $version = ''): string
{
if ($version === '') {
$version = PrettyVersions::getVersion('api-clients/pusher')->getFullVersion();
}
list($version, $hash) = \explode('@', $version);
if (\strpos($version, 'dev') !== false) {
return '0.0.1-' . $hash;
}
return $version;
}
/**
* Create WebSocket URL for given App ID.
*
* @param string $appId
* @return array
*/
public static function createUrl(string $appId, string $cluster = null, string $host = null): string
{
$query = [
'client' => 'api-clients/pusher (https://php-api-clients.org/clients/pusher)',
'protocol' => 7,
'version' => ApiSettings::getVersion(),
];
if (!$host) {
$host = ($cluster !== null) ? "ws-{$cluster}.pusher.com" : 'ws.pusherapp.com';
}
return 'wss://'.$host.'/app/' .
$appId .
'?' . \http_build_query($query)
;
}
}