1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BeyondCode\LaravelWebSockets\Apps; |
4
|
|
|
|
5
|
|
|
use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp; |
6
|
|
|
|
7
|
|
|
class App |
8
|
|
|
{ |
9
|
|
|
/** @var int */ |
10
|
|
|
public $id; |
11
|
|
|
|
12
|
|
|
/** @var string */ |
13
|
|
|
public $key; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
public $secret; |
17
|
|
|
|
18
|
|
|
/** @var string|null */ |
19
|
|
|
public $name; |
20
|
|
|
|
21
|
|
|
/** @var string|null */ |
22
|
|
|
public $host; |
23
|
|
|
|
24
|
|
|
/** @var int|null */ |
25
|
|
|
public $capacity = null; |
26
|
|
|
|
27
|
|
|
/** @var bool */ |
28
|
|
|
public $clientMessagesEnabled = false; |
29
|
|
|
|
30
|
|
|
/** @var array */ |
31
|
|
|
public $dispatchEventsForClientMessages = []; |
32
|
|
|
|
33
|
|
|
/** @var bool */ |
34
|
|
|
public $statisticsEnabled = true; |
35
|
|
|
|
36
|
|
|
public static function findById($appId) |
37
|
|
|
{ |
38
|
|
|
return app(AppProvider::class)->findById($appId); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function findByKey(string $appKey): ?self |
42
|
|
|
{ |
43
|
|
|
return app(AppProvider::class)->findByKey($appKey); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function findBySecret(string $appSecret): ?self |
47
|
|
|
{ |
48
|
|
|
return app(AppProvider::class)->findBySecret($appSecret); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function __construct($appId, string $appKey, string $appSecret) |
52
|
|
|
{ |
53
|
|
|
if ($appKey === '') { |
54
|
|
|
throw InvalidApp::valueIsRequired('appKey', $appId); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($appSecret === '') { |
58
|
|
|
throw InvalidApp::valueIsRequired('appSecret', $appId); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->id = $appId; |
62
|
|
|
|
63
|
|
|
$this->key = $appKey; |
64
|
|
|
|
65
|
|
|
$this->secret = $appSecret; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setName(string $appName) |
69
|
|
|
{ |
70
|
|
|
$this->name = $appName; |
71
|
|
|
|
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function setHost(string $host) |
76
|
|
|
{ |
77
|
|
|
$this->host = $host; |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function enableClientMessages(bool $enabled = true) |
83
|
|
|
{ |
84
|
|
|
$this->clientMessagesEnabled = $enabled; |
85
|
|
|
|
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function dispatchEventsForClientMessages(array $events = []) |
90
|
|
|
{ |
91
|
|
|
$this->dispatchEventsForClientMessages = $events; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setCapacity(?int $capacity) |
97
|
|
|
{ |
98
|
|
|
$this->capacity = $capacity; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function enableStatistics(bool $enabled = true) |
104
|
|
|
{ |
105
|
|
|
$this->statisticsEnabled = $enabled; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|