Skip to content

Commit 8d962fd

Browse files
committed
Update bridgeclient.class.php
Added getall() function to get all values from json string with only one socket
1 parent 9ed0aa4 commit 8d962fd

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

bridge/php/bridgeclient.class.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Usage
1616
-----
1717
The usage is the same as bridgeclient.py
18-
You have just two methods: get and put (see example.php)
18+
You have just three methods: get, put and getall (see example.php)
1919
2020
*/
2121

@@ -39,14 +39,15 @@ private function disconnect() {
3939
socket_close($this->socket);
4040
}
4141

42-
private function sendcommand($command,$key,$value="") {
42+
private function sendcommand($command,$key="",$value="") {
4343
$jsonreceive = "";
4444
$obraces=0;
4545
$cbraces=0;
4646

4747
$this->connect();
4848

49-
$jsonsend = '{"command":"'.$command.'","key":"'.$key.'","value":"'.$value.'"}';
49+
if($key<>""){$jsonsend = '{"command":"'.$command.'","key":"'.$key.'","value":"'.$value.'"}';}
50+
else{$jsonsend = '{"command":"'.$command.'"}';}
5051
socket_write($this->socket, $jsonsend, strlen($jsonsend));
5152

5253
do {
@@ -58,10 +59,15 @@ private function sendcommand($command,$key,$value="") {
5859

5960
$this->disconnect();
6061

61-
$jsonarray=json_decode($jsonreceive);
62-
if ($jsonarray->{'value'} == NULL) $jsonarray->{'value'}="None";
62+
if($key<>""){
63+
$jsonarray=json_decode($jsonreceive);
64+
if ($jsonarray->{'value'} == NULL) $jsonarray->{'value'}="None";
6365

64-
return $jsonarray->{'value'};
66+
return $jsonarray->{'value'};
67+
}
68+
else{
69+
return $jsonreceive;
70+
}
6571
}
6672

6773
public function get($key) {
@@ -71,6 +77,10 @@ public function get($key) {
7177
public function put($key,$value) {
7278
return $this->sendcommand("put",$key,$value);
7379
}
80+
81+
public function getall() {
82+
return $this->sendcommand("get");
83+
}
7484

7585
}
7686
?>

0 commit comments

Comments
 (0)