forked from beyondcode/laravel-websockets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelpers.php
50 lines (43 loc) · 1.32 KB
/
Helpers.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
<?php
namespace BlaxSoftware\LaravelWebSockets;
use React\Promise\PromiseInterface;
class Helpers
{
/**
* The loop used to create the Fulfilled Promise.
*
* @var null|\React\EventLoop\LoopInterface
*/
public static $loop = null;
/**
* Transform the Redis' list of key after value
* to key-value pairs.
*
* @param array $list
* @return array
*/
public static function redisListToArray(array $list)
{
// Redis lists come into a format where the keys are on even indexes
// and the values are on odd indexes. This way, we know which
// ones are keys and which ones are values and their get combined
// later to form the key => value array.
[$keys, $values] = collect($list)->partition(function ($value, $key) {
return $key % 2 === 0;
});
return array_combine($keys->all(), $values->all());
}
/**
* Create a new fulfilled promise with a value.
*
* @param mixed $value
* @return \React\Promise\PromiseInterface
*/
public static function createFulfilledPromise($value): PromiseInterface
{
$resolver = config(
'websockets.promise_resolver', \React\Promise\FulfilledPromise::class
);
return new $resolver($value, static::$loop);
}
}