Skip to content

Commit 293c109

Browse files
committed
Merge pull request #21 from 5a2v0/master
new getall() function
2 parents 9ed0aa4 + a1d7ec1 commit 293c109

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
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
?>

bridge/php/example.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
$client = new bridgeclient();
55

66
$client->put("D13","Test");
7-
$test= $client->get("D13");
7+
8+
$test = $client->get("D13");
89
echo $test;
10+
11+
$all = $client->getall();
12+
$all = json_decode($all, true);
13+
print_r($all);
914
?>
1015

0 commit comments

Comments
 (0)