File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+ /**
5+ * This file is part of friendsofhyperf/components.
6+ *
7+ * @link https://github.com/friendsofhyperf/components
8+ * @document https://github.com/friendsofhyperf/components/blob/main/README.md
9+ * @contact huangdijia@gmail.com
10+ */
11+
12+ namespace FriendsOfHyperf \Support ;
13+
14+ use Stringable ;
15+
16+ use function Hyperf \Collection \collect ;
17+
18+ class RedisCommand implements Stringable
19+ {
20+ public function __construct (public string $ command , public array $ parameters = [])
21+ {
22+ }
23+
24+ public function __toString (): string
25+ {
26+ return $ this ->formatCommand ($ this ->command , $ this ->parameters );
27+ }
28+
29+ protected function formatCommand (string $ command , array $ parameters ): string
30+ {
31+ $ parameters = collect ($ parameters )->map (function ($ parameter ) {
32+ if (is_array ($ parameter )) {
33+ return collect ($ parameter )->map (function ($ value , $ key ) {
34+ if (is_array ($ value )) {
35+ return sprintf ('%s %s ' , $ key , json_encode ($ value ));
36+ }
37+
38+ return is_int ($ key ) ? $ value : sprintf ('%s %s ' , $ key , $ value );
39+ })->implode (' ' );
40+ }
41+
42+ return $ parameter ;
43+ })->implode (' ' );
44+
45+ return sprintf ('%s %s ' , $ command , $ parameters );
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments