|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BeyondCode\LaravelWebSockets\Apps; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
|
|
7
|
|
|
class ConfigAppProvider implements AppProvider |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var Collection */ |
|
10
|
|
|
protected $apps; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->apps = collect(config('websockets.apps')); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** @return array[\BeyondCode\LaravelWebSockets\AppProviders\App] */ |
|
|
|
|
|
|
18
|
|
|
public function all(): array |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->apps |
|
21
|
|
|
->map(function (array $appAttributes) { |
|
22
|
|
|
return $this->instantiate($appAttributes); |
|
23
|
|
|
}) |
|
24
|
|
|
->toArray(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function findById($appId): ?App |
|
28
|
|
|
{ |
|
29
|
|
|
$appAttributes = $this |
|
30
|
|
|
->apps |
|
31
|
|
|
->firstWhere('id', $appId); |
|
32
|
|
|
|
|
33
|
|
|
return $this->instantiate($appAttributes); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function findByKey(string $appKey): ?App |
|
37
|
|
|
{ |
|
38
|
|
|
$appAttributes = $this |
|
39
|
|
|
->apps |
|
40
|
|
|
->firstWhere('key', $appKey); |
|
41
|
|
|
|
|
42
|
|
|
return $this->instantiate($appAttributes); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function findBySecret(string $appSecret): ?App |
|
46
|
|
|
{ |
|
47
|
|
|
$appAttributes = $this |
|
48
|
|
|
->apps |
|
49
|
|
|
->firstWhere('secret', $appSecret); |
|
50
|
|
|
|
|
51
|
|
|
return $this->instantiate($appAttributes); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function instantiate(?array $appAttributes): ?App |
|
55
|
|
|
{ |
|
56
|
|
|
if (! $appAttributes) { |
|
57
|
|
|
return null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$app = new App( |
|
61
|
|
|
$appAttributes['id'], |
|
62
|
|
|
$appAttributes['key'], |
|
63
|
|
|
$appAttributes['secret'] |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
if (isset($appAttributes['name'])) { |
|
67
|
|
|
$app->setName($appAttributes['name']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if (isset($appAttributes['host'])) { |
|
71
|
|
|
$app->setHost($appAttributes['host']); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$app |
|
75
|
|
|
->enableClientMessages($appAttributes['enable_client_messages']) |
|
76
|
|
|
->enableStatistics($appAttributes['enable_statistics']) |
|
77
|
|
|
->setCapacity($appAttributes['capacity'] ?? null); |
|
78
|
|
|
|
|
79
|
|
|
return $app; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.