Skip to content

Commit

Permalink
Added some examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Jul 27, 2016
1 parent 6566118 commit 912ceee
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/src/client/asyncInvoke.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
require_once "../../vendor/autoload.php";

use Hprose\Client;

$client = Client::create('http://hprose.com/example/');

$client->sum(1, 2)
->then(function($result) use ($client) {
return $client->sum($result, 3);
})
->then(function($result) use ($client) {
return $client->sum($result, 4);
})
->then(function($result) {
var_dump($result);
});
12 changes: 12 additions & 0 deletions examples/src/client/asyncInvoke1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require_once "../../vendor/autoload.php";

use Hprose\Client;

$client = Client::create('http://hprose.com/example/');

$client->sum($client->sum($client->sum(1, 2), 3), 4)
->then(function($result) {
var_dump($result);
});

12 changes: 12 additions & 0 deletions examples/src/client/asyncInvoke2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require_once "../../vendor/autoload.php";

use Hprose\Client;
use Hprose\Future;

$client = Client::create('http://hprose.com/example/');

$var_dump = Future\wrap('var_dump');
$sum = $client->sum;

$var_dump($sum($sum($sum(1, 2), 3), 4));
15 changes: 15 additions & 0 deletions examples/src/client/asyncInvoke3.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
require_once "../../vendor/autoload.php";

use Hprose\Client;
use Hprose\Future;

$client = Client::create('http://hprose.com/example/');

$var_dump = Future\wrap('var_dump');
$sum = $client->sum;

$r1 = $sum(1, 3, 5, 7, 9);
$r2 = $sum(2, 4, 6, 8, 10);
$r3 = $sum($r1, $r2);
$var_dump($r1, $r2, $r3);
25 changes: 25 additions & 0 deletions examples/src/client/byref.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
require_once "../../vendor/autoload.php";

use Hprose\Client;
use Hprose\InvokeSettings;

$client = Client::create('http://hprose.com/example/', false);

$weeks = array(
'Monday' => 'Mon',
'Tuesday' => 'Tue',
'Wednesday' => 'Wed',
'Thursday' => 'Thu',
'Friday' => 'Fri',
'Saturday' => 'Sat',
'Sunday' => 'Sun'
);

$args = array($weeks);
$client->invoke('swapKeyAndValue', $args, new InvokeSettings(array('byref' => true)));
var_dump($args[0]);

$client->swapKeyAndValue($weeks, function($result, $args) {
var_dump($args[0]);
}, array('byref' => true));
23 changes: 23 additions & 0 deletions examples/src/client/byref1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
require_once "../../vendor/autoload.php";

use Hprose\Client;

$client = Client::create('http://hprose.com/example/', false);

$weeks = array(
'Monday' => 'Mon',
'Tuesday' => 'Tue',
'Wednesday' => 'Wed',
'Thursday' => 'Thu',
'Friday' => 'Fri',
'Saturday' => 'Sat',
'Sunday' => 'Sun'
);

$args = array($weeks);

$client->swapKeyAndValue["byref"] = true;
$client->swapKeyAndValue($weeks, function($result, $args) {
var_dump($args[0]);
});
13 changes: 13 additions & 0 deletions examples/src/client/mode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
require_once "../../vendor/autoload.php";

use Hprose\Client;
use Hprose\InvokeSettings;
use Hprose\ResultMode;

$client = Client::create('http://hprose.com/example/', false);

var_dump($client->hello("World", new InvokeSettings(array('mode' => ResultMode::Normal))));
var_dump($client->hello("World", new InvokeSettings(array('mode' => ResultMode::Serialized))));
var_dump($client->hello("World", new InvokeSettings(array('mode' => ResultMode::Raw))));
var_dump($client->hello("World", new InvokeSettings(array('mode' => ResultMode::RawWithEndTag))));

0 comments on commit 912ceee

Please sign in to comment.