@artilingo/artiframe-cli 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +660 -660
- package/bin/artiframe.js +0 -0
- package/bin/artiframe.php +0 -0
- package/core-stubs/app/ApiAuthControl.php +76 -0
- package/core-stubs/app/ApiControl.php +81 -35
- package/core-stubs/app/AuthControl.php +39 -0
- package/core-stubs/app/Database.php +36 -35
- package/core-stubs/app/DotEnv.php +19 -1
- package/core-stubs/app/ViewControl.php +47 -1
- package/core-stubs/bin/SQLMethod.php +261 -0
- package/core-stubs/bin/SystemMethod.php +115 -74
- package/core-stubs/bin/ViewMethod.php +19 -5
- package/core-stubs/docs/de.html +4325 -4347
- package/core-stubs/docs/en.html +4325 -4347
- package/core-stubs/docs/es.html +4325 -4347
- package/core-stubs/docs/fr.html +4325 -4347
- package/core-stubs/docs/tr.html +117 -46
- package/core-stubs/public/403.php +52 -0
- package/core-stubs/public/assets/css/components/header.css +174 -0
- package/core-stubs/public/assets/css/components/mobilenav.css +198 -0
- package/core-stubs/public/assets/css/components/sidebar.css +184 -0
- package/core-stubs/public/assets/css/root/app.css +975 -38
- package/core-stubs/public/assets/css/root/root.css +64 -0
- package/core-stubs/public/assets/js/components/header.js +380 -0
- package/core-stubs/public/assets/js/components/mobilenav.js +97 -0
- package/core-stubs/public/assets/js/components/theme-modal.js +74 -0
- package/core-stubs/public/assets/js/root/app.js +1870 -0
- package/core-stubs/public/includes/footer.php +4 -5
- package/core-stubs/public/includes/head-auth.php +65 -0
- package/core-stubs/public/includes/head.php +56 -17
- package/core-stubs/public/includes/header.php +135 -1
- package/core-stubs/public/includes/mobilenav.php +75 -3
- package/core-stubs/public/includes/sidebar.php +186 -1
- package/core-stubs/public/includes/theme-modal.php +1 -0
- package/db-studio/debug.log +3 -0
- package/db-studio/index.html +1755 -0
- package/db-studio/launcher.html +102 -0
- package/db-studio/launcher.js +180 -0
- package/db-studio/logo.svg +22 -0
- package/db-studio/main.js +568 -0
- package/db-studio/package-lock.json +1034 -0
- package/db-studio/package.json +16 -0
- package/db-studio/preload.js +29 -0
- package/devops-studio/api-inspector.js +222 -0
- package/devops-studio/index.html +1892 -0
- package/devops-studio/logo.svg +22 -0
- package/devops-studio/main.js +67 -0
- package/devops-studio/make-wizard.js +635 -0
- package/devops-studio/package-lock.json +871 -0
- package/devops-studio/package.json +12 -0
- package/package.json +5 -2
- package/scripts/postinstall.js +44 -8
- package/server-studio/.json-404-guard +1 -0
- package/server-studio/index.html +283 -0
- package/server-studio/logo.svg +22 -0
- package/server-studio/main.js +133 -0
- package/server-studio/package-lock.json +1179 -0
- package/server-studio/package.json +15 -0
- package/server-studio/router.php +99 -0
- package/src/App.php +29 -0
- package/src/Commands/AddCommand.php +26 -9
- package/src/Commands/DbExportCommand.php +131 -0
- package/src/Commands/DbStartCommand.php +46 -0
- package/src/Commands/DevopsCommand.php +35 -0
- package/src/Commands/GoCommand.php +48 -48
- package/src/Commands/ListCommand.php +68 -68
- package/src/Commands/MakeApiCommand.php +6 -1
- package/src/Commands/MakeViewCommand.php +25 -2
- package/src/Commands/NewProjectCommand.php +16 -11
- package/src/Commands/OptimizeCommand.php +61 -0
- package/src/Commands/RemoveCommand.php +35 -7
- package/src/Commands/ServeCommand.php +46 -91
- package/src/Commands/ShowCommand.php +24 -24
- package/src/Commands/UpgradeCommand.php +39 -10
- package/stubs/make/api-switch-case.stub +1 -1
- package/stubs/make/auth-api-standart.stub +20 -0
- package/stubs/make/auth-api-switch-case.stub +38 -0
- package/stubs/make/auth-view.stub +26 -0
- package/stubs/make/class.stub +10 -2
- package/stubs/make/view.stub +3 -0
- package/stubs/service/image.stub +334 -334
- package/stubs/service/iyzico.stub +637 -637
- package/stubs/service/jwt.stub +312 -312
- package/stubs/service/phpmailer.stub +143 -143
- package/stubs/service/pusher.stub +232 -232
- package/stubs/service/qrcode.stub +169 -169
- package/stubs/service/redis.stub +361 -361
- package/stubs/service/s3.stub +377 -377
- package/stubs/service/stripe.stub +526 -526
- package/stubs/service/twilio.stub +361 -361
|
@@ -1,232 +1,232 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
namespace Src\Service;
|
|
4
|
-
|
|
5
|
-
use Pusher\Pusher;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Pusher Realtime Service
|
|
9
|
-
*
|
|
10
|
-
* Provides a clean interface for Pusher Channels — broadcasting events,
|
|
11
|
-
* authenticating private/presence channels, and querying channel state.
|
|
12
|
-
* Uses the pusher/pusher-php-server SDK. All configuration from $_ENV.
|
|
13
|
-
*
|
|
14
|
-
* Required environment variables:
|
|
15
|
-
* PUSHER_APP_ID — Your Pusher application ID
|
|
16
|
-
* PUSHER_APP_KEY — Your Pusher application key
|
|
17
|
-
* PUSHER_APP_SECRET — Your Pusher application secret
|
|
18
|
-
* PUSHER_CLUSTER — Pusher cluster region (e.g., 'eu', 'us2', 'ap1')
|
|
19
|
-
*
|
|
20
|
-
* @package Service
|
|
21
|
-
*/
|
|
22
|
-
class PusherService
|
|
23
|
-
{
|
|
24
|
-
/**
|
|
25
|
-
* The Pusher SDK client instance.
|
|
26
|
-
*
|
|
27
|
-
* @var \Pusher\Pusher
|
|
28
|
-
*/
|
|
29
|
-
private Pusher $pusher;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Create a new PusherService instance.
|
|
33
|
-
*
|
|
34
|
-
* Initializes the Pusher SDK client using credentials
|
|
35
|
-
* and cluster configuration from environment variables.
|
|
36
|
-
*
|
|
37
|
-
* @throws \Pusher\PusherException If credentials are invalid or missing
|
|
38
|
-
*/
|
|
39
|
-
public function __construct()
|
|
40
|
-
{
|
|
41
|
-
$this->pusher = new Pusher(
|
|
42
|
-
$_ENV['PUSHER_APP_KEY'],
|
|
43
|
-
$_ENV['PUSHER_APP_SECRET'],
|
|
44
|
-
$_ENV['PUSHER_APP_ID'],
|
|
45
|
-
[
|
|
46
|
-
'cluster' => $_ENV['PUSHER_CLUSTER'] ?? 'mt1',
|
|
47
|
-
'useTLS' => true,
|
|
48
|
-
'encrypted' => true,
|
|
49
|
-
]
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Broadcast an event to a single channel.
|
|
55
|
-
*
|
|
56
|
-
* Triggers an event on the specified channel, delivering
|
|
57
|
-
* the given data payload to all subscribers of that channel.
|
|
58
|
-
*
|
|
59
|
-
* Channel naming conventions:
|
|
60
|
-
* - Public channels: 'my-channel'
|
|
61
|
-
* - Private channels: 'private-my-channel'
|
|
62
|
-
* - Presence channels: 'presence-my-channel'
|
|
63
|
-
*
|
|
64
|
-
* @param string $channel The channel name to broadcast on
|
|
65
|
-
* @param string $event The event name to trigger
|
|
66
|
-
* @param array $data The event payload data
|
|
67
|
-
* @return bool True on success, false on failure
|
|
68
|
-
*/
|
|
69
|
-
public function broadcast(string $channel, string $event, array $data): bool
|
|
70
|
-
{
|
|
71
|
-
try {
|
|
72
|
-
$response = $this->pusher->trigger($channel, $event, $data);
|
|
73
|
-
|
|
74
|
-
return (bool) $response;
|
|
75
|
-
} catch (\Exception $e) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Broadcast an event to multiple channels simultaneously.
|
|
82
|
-
*
|
|
83
|
-
* Triggers the same event with the same payload across
|
|
84
|
-
* multiple channels in a single API call. Pusher limits
|
|
85
|
-
* this to a maximum of 100 channels per call.
|
|
86
|
-
*
|
|
87
|
-
* @param array $channels List of channel names (max 100)
|
|
88
|
-
* @param string $event The event name to trigger
|
|
89
|
-
* @param array $data The event payload data
|
|
90
|
-
* @return bool True on success, false on failure
|
|
91
|
-
*/
|
|
92
|
-
public function broadcastToMany(array $channels, string $event, array $data): bool
|
|
93
|
-
{
|
|
94
|
-
try {
|
|
95
|
-
$response = $this->pusher->trigger($channels, $event, $data);
|
|
96
|
-
|
|
97
|
-
return (bool) $response;
|
|
98
|
-
} catch (\Exception $e) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Send an event to a specific user via their user channel.
|
|
105
|
-
*
|
|
106
|
-
* Uses Pusher's user event feature to deliver a message directly
|
|
107
|
-
* to a single authenticated user, regardless of which channels
|
|
108
|
-
* they are subscribed to. The user must have been authenticated
|
|
109
|
-
* with a user ID on the client side.
|
|
110
|
-
*
|
|
111
|
-
* @param string $userId The target user's unique identifier
|
|
112
|
-
* @param string $event The event name to trigger
|
|
113
|
-
* @param array $data The event payload data
|
|
114
|
-
* @return bool True on success, false on failure
|
|
115
|
-
*/
|
|
116
|
-
public function toUser(string $userId, string $event, array $data): bool
|
|
117
|
-
{
|
|
118
|
-
try {
|
|
119
|
-
$response = $this->pusher->sendToUser($userId, $event, $data);
|
|
120
|
-
|
|
121
|
-
return (bool) $response;
|
|
122
|
-
} catch (\Exception $e) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Get information about a specific channel.
|
|
129
|
-
*
|
|
130
|
-
* Returns metadata about the channel including whether it is
|
|
131
|
-
* currently occupied and, for presence channels, the user count.
|
|
132
|
-
*
|
|
133
|
-
* @param string $channel The channel name to query
|
|
134
|
-
* @return array Channel info ['occupied' => bool, 'user_count' => int|null]
|
|
135
|
-
* Returns empty array on failure
|
|
136
|
-
*/
|
|
137
|
-
public function channelInfo(string $channel): array
|
|
138
|
-
{
|
|
139
|
-
try {
|
|
140
|
-
$info = $this->pusher->getChannelInfo($channel, [
|
|
141
|
-
'info' => 'user_count,subscription_count',
|
|
142
|
-
]);
|
|
143
|
-
|
|
144
|
-
return [
|
|
145
|
-
'occupied' => $info->occupied ?? false,
|
|
146
|
-
'user_count' => $info->user_count ?? null,
|
|
147
|
-
'subscription_count' => $info->subscription_count ?? null,
|
|
148
|
-
];
|
|
149
|
-
} catch (\Exception $e) {
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* List all active (occupied) channels.
|
|
156
|
-
*
|
|
157
|
-
* Optionally filters channels by a name prefix. For example,
|
|
158
|
-
* passing 'presence-' will return only active presence channels.
|
|
159
|
-
*
|
|
160
|
-
* @param string $prefix Optional channel name prefix filter
|
|
161
|
-
* @return array List of active channel names
|
|
162
|
-
*/
|
|
163
|
-
public function channels(string $prefix = ''): array
|
|
164
|
-
{
|
|
165
|
-
try {
|
|
166
|
-
$params = [];
|
|
167
|
-
|
|
168
|
-
if ($prefix !== '') {
|
|
169
|
-
$params['filter_by_prefix'] = $prefix;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
$result = $this->pusher->getChannels($params);
|
|
173
|
-
|
|
174
|
-
if (isset($result->channels)) {
|
|
175
|
-
return array_keys((array) $result->channels);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return [];
|
|
179
|
-
} catch (\Exception $e) {
|
|
180
|
-
return [];
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Authenticate a private or presence channel subscription.
|
|
186
|
-
*
|
|
187
|
-
* This method should be called from your authentication endpoint
|
|
188
|
-
* when a client attempts to subscribe to a private or presence channel.
|
|
189
|
-
* Returns the authentication signature string that the client SDK expects.
|
|
190
|
-
*
|
|
191
|
-
* For presence channels, use presenceAuth() instead to include user data.
|
|
192
|
-
*
|
|
193
|
-
* @param string $channelName The channel being subscribed to
|
|
194
|
-
* @param string $socketId The connecting socket's ID
|
|
195
|
-
* @return string JSON-encoded authentication response
|
|
196
|
-
*/
|
|
197
|
-
public function auth(string $channelName, string $socketId): string
|
|
198
|
-
{
|
|
199
|
-
try {
|
|
200
|
-
return $this->pusher->authorizeChannel($channelName, $socketId);
|
|
201
|
-
} catch (\Exception $e) {
|
|
202
|
-
return json_encode(['error' => $e->getMessage()]);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Authenticate a presence channel subscription with user data.
|
|
208
|
-
*
|
|
209
|
-
* Similar to auth() but also attaches user identity and optional
|
|
210
|
-
* metadata to the presence channel. This allows other subscribers
|
|
211
|
-
* to see who is present in the channel.
|
|
212
|
-
*
|
|
213
|
-
* @param string $channelName The presence channel being subscribed to
|
|
214
|
-
* @param string $socketId The connecting socket's ID
|
|
215
|
-
* @param string $userId The unique identifier for the subscribing user
|
|
216
|
-
* @param array $userInfo Optional additional user metadata (e.g., name, avatar)
|
|
217
|
-
* @return string JSON-encoded authentication response with user data
|
|
218
|
-
*/
|
|
219
|
-
public function presenceAuth(string $channelName, string $socketId, string $userId, array $userInfo = []): string
|
|
220
|
-
{
|
|
221
|
-
try {
|
|
222
|
-
$presenceData = [
|
|
223
|
-
'user_id' => $userId,
|
|
224
|
-
'user_info' => $userInfo,
|
|
225
|
-
];
|
|
226
|
-
|
|
227
|
-
return $this->pusher->authorizePresenceChannel($channelName, $socketId, $userId, $userInfo);
|
|
228
|
-
} catch (\Exception $e) {
|
|
229
|
-
return json_encode(['error' => $e->getMessage()]);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Src\Service;
|
|
4
|
+
|
|
5
|
+
use Pusher\Pusher;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pusher Realtime Service
|
|
9
|
+
*
|
|
10
|
+
* Provides a clean interface for Pusher Channels — broadcasting events,
|
|
11
|
+
* authenticating private/presence channels, and querying channel state.
|
|
12
|
+
* Uses the pusher/pusher-php-server SDK. All configuration from $_ENV.
|
|
13
|
+
*
|
|
14
|
+
* Required environment variables:
|
|
15
|
+
* PUSHER_APP_ID — Your Pusher application ID
|
|
16
|
+
* PUSHER_APP_KEY — Your Pusher application key
|
|
17
|
+
* PUSHER_APP_SECRET — Your Pusher application secret
|
|
18
|
+
* PUSHER_CLUSTER — Pusher cluster region (e.g., 'eu', 'us2', 'ap1')
|
|
19
|
+
*
|
|
20
|
+
* @package Service
|
|
21
|
+
*/
|
|
22
|
+
class PusherService
|
|
23
|
+
{
|
|
24
|
+
/**
|
|
25
|
+
* The Pusher SDK client instance.
|
|
26
|
+
*
|
|
27
|
+
* @var \Pusher\Pusher
|
|
28
|
+
*/
|
|
29
|
+
private Pusher $pusher;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Create a new PusherService instance.
|
|
33
|
+
*
|
|
34
|
+
* Initializes the Pusher SDK client using credentials
|
|
35
|
+
* and cluster configuration from environment variables.
|
|
36
|
+
*
|
|
37
|
+
* @throws \Pusher\PusherException If credentials are invalid or missing
|
|
38
|
+
*/
|
|
39
|
+
public function __construct()
|
|
40
|
+
{
|
|
41
|
+
$this->pusher = new Pusher(
|
|
42
|
+
$_ENV['PUSHER_APP_KEY'],
|
|
43
|
+
$_ENV['PUSHER_APP_SECRET'],
|
|
44
|
+
$_ENV['PUSHER_APP_ID'],
|
|
45
|
+
[
|
|
46
|
+
'cluster' => $_ENV['PUSHER_CLUSTER'] ?? 'mt1',
|
|
47
|
+
'useTLS' => true,
|
|
48
|
+
'encrypted' => true,
|
|
49
|
+
]
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Broadcast an event to a single channel.
|
|
55
|
+
*
|
|
56
|
+
* Triggers an event on the specified channel, delivering
|
|
57
|
+
* the given data payload to all subscribers of that channel.
|
|
58
|
+
*
|
|
59
|
+
* Channel naming conventions:
|
|
60
|
+
* - Public channels: 'my-channel'
|
|
61
|
+
* - Private channels: 'private-my-channel'
|
|
62
|
+
* - Presence channels: 'presence-my-channel'
|
|
63
|
+
*
|
|
64
|
+
* @param string $channel The channel name to broadcast on
|
|
65
|
+
* @param string $event The event name to trigger
|
|
66
|
+
* @param array $data The event payload data
|
|
67
|
+
* @return bool True on success, false on failure
|
|
68
|
+
*/
|
|
69
|
+
public function broadcast(string $channel, string $event, array $data): bool
|
|
70
|
+
{
|
|
71
|
+
try {
|
|
72
|
+
$response = $this->pusher->trigger($channel, $event, $data);
|
|
73
|
+
|
|
74
|
+
return (bool) $response;
|
|
75
|
+
} catch (\Exception $e) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Broadcast an event to multiple channels simultaneously.
|
|
82
|
+
*
|
|
83
|
+
* Triggers the same event with the same payload across
|
|
84
|
+
* multiple channels in a single API call. Pusher limits
|
|
85
|
+
* this to a maximum of 100 channels per call.
|
|
86
|
+
*
|
|
87
|
+
* @param array $channels List of channel names (max 100)
|
|
88
|
+
* @param string $event The event name to trigger
|
|
89
|
+
* @param array $data The event payload data
|
|
90
|
+
* @return bool True on success, false on failure
|
|
91
|
+
*/
|
|
92
|
+
public function broadcastToMany(array $channels, string $event, array $data): bool
|
|
93
|
+
{
|
|
94
|
+
try {
|
|
95
|
+
$response = $this->pusher->trigger($channels, $event, $data);
|
|
96
|
+
|
|
97
|
+
return (bool) $response;
|
|
98
|
+
} catch (\Exception $e) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Send an event to a specific user via their user channel.
|
|
105
|
+
*
|
|
106
|
+
* Uses Pusher's user event feature to deliver a message directly
|
|
107
|
+
* to a single authenticated user, regardless of which channels
|
|
108
|
+
* they are subscribed to. The user must have been authenticated
|
|
109
|
+
* with a user ID on the client side.
|
|
110
|
+
*
|
|
111
|
+
* @param string $userId The target user's unique identifier
|
|
112
|
+
* @param string $event The event name to trigger
|
|
113
|
+
* @param array $data The event payload data
|
|
114
|
+
* @return bool True on success, false on failure
|
|
115
|
+
*/
|
|
116
|
+
public function toUser(string $userId, string $event, array $data): bool
|
|
117
|
+
{
|
|
118
|
+
try {
|
|
119
|
+
$response = $this->pusher->sendToUser($userId, $event, $data);
|
|
120
|
+
|
|
121
|
+
return (bool) $response;
|
|
122
|
+
} catch (\Exception $e) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get information about a specific channel.
|
|
129
|
+
*
|
|
130
|
+
* Returns metadata about the channel including whether it is
|
|
131
|
+
* currently occupied and, for presence channels, the user count.
|
|
132
|
+
*
|
|
133
|
+
* @param string $channel The channel name to query
|
|
134
|
+
* @return array Channel info ['occupied' => bool, 'user_count' => int|null]
|
|
135
|
+
* Returns empty array on failure
|
|
136
|
+
*/
|
|
137
|
+
public function channelInfo(string $channel): array
|
|
138
|
+
{
|
|
139
|
+
try {
|
|
140
|
+
$info = $this->pusher->getChannelInfo($channel, [
|
|
141
|
+
'info' => 'user_count,subscription_count',
|
|
142
|
+
]);
|
|
143
|
+
|
|
144
|
+
return [
|
|
145
|
+
'occupied' => $info->occupied ?? false,
|
|
146
|
+
'user_count' => $info->user_count ?? null,
|
|
147
|
+
'subscription_count' => $info->subscription_count ?? null,
|
|
148
|
+
];
|
|
149
|
+
} catch (\Exception $e) {
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* List all active (occupied) channels.
|
|
156
|
+
*
|
|
157
|
+
* Optionally filters channels by a name prefix. For example,
|
|
158
|
+
* passing 'presence-' will return only active presence channels.
|
|
159
|
+
*
|
|
160
|
+
* @param string $prefix Optional channel name prefix filter
|
|
161
|
+
* @return array List of active channel names
|
|
162
|
+
*/
|
|
163
|
+
public function channels(string $prefix = ''): array
|
|
164
|
+
{
|
|
165
|
+
try {
|
|
166
|
+
$params = [];
|
|
167
|
+
|
|
168
|
+
if ($prefix !== '') {
|
|
169
|
+
$params['filter_by_prefix'] = $prefix;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
$result = $this->pusher->getChannels($params);
|
|
173
|
+
|
|
174
|
+
if (isset($result->channels)) {
|
|
175
|
+
return array_keys((array) $result->channels);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return [];
|
|
179
|
+
} catch (\Exception $e) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Authenticate a private or presence channel subscription.
|
|
186
|
+
*
|
|
187
|
+
* This method should be called from your authentication endpoint
|
|
188
|
+
* when a client attempts to subscribe to a private or presence channel.
|
|
189
|
+
* Returns the authentication signature string that the client SDK expects.
|
|
190
|
+
*
|
|
191
|
+
* For presence channels, use presenceAuth() instead to include user data.
|
|
192
|
+
*
|
|
193
|
+
* @param string $channelName The channel being subscribed to
|
|
194
|
+
* @param string $socketId The connecting socket's ID
|
|
195
|
+
* @return string JSON-encoded authentication response
|
|
196
|
+
*/
|
|
197
|
+
public function auth(string $channelName, string $socketId): string
|
|
198
|
+
{
|
|
199
|
+
try {
|
|
200
|
+
return $this->pusher->authorizeChannel($channelName, $socketId);
|
|
201
|
+
} catch (\Exception $e) {
|
|
202
|
+
return json_encode(['error' => $e->getMessage()]);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Authenticate a presence channel subscription with user data.
|
|
208
|
+
*
|
|
209
|
+
* Similar to auth() but also attaches user identity and optional
|
|
210
|
+
* metadata to the presence channel. This allows other subscribers
|
|
211
|
+
* to see who is present in the channel.
|
|
212
|
+
*
|
|
213
|
+
* @param string $channelName The presence channel being subscribed to
|
|
214
|
+
* @param string $socketId The connecting socket's ID
|
|
215
|
+
* @param string $userId The unique identifier for the subscribing user
|
|
216
|
+
* @param array $userInfo Optional additional user metadata (e.g., name, avatar)
|
|
217
|
+
* @return string JSON-encoded authentication response with user data
|
|
218
|
+
*/
|
|
219
|
+
public function presenceAuth(string $channelName, string $socketId, string $userId, array $userInfo = []): string
|
|
220
|
+
{
|
|
221
|
+
try {
|
|
222
|
+
$presenceData = [
|
|
223
|
+
'user_id' => $userId,
|
|
224
|
+
'user_info' => $userInfo,
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
return $this->pusher->authorizePresenceChannel($channelName, $socketId, $userId, $userInfo);
|
|
228
|
+
} catch (\Exception $e) {
|
|
229
|
+
return json_encode(['error' => $e->getMessage()]);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|