Skip to content

Commit

Permalink
Merge pull request #3 from voryx/2.0
Browse files Browse the repository at this point in the history
Updated to RxPHP v2
  • Loading branch information
davidwdan authored Mar 21, 2017
2 parents 85a8b52 + bfa47d5 commit 71d4484
Show file tree
Hide file tree
Showing 22 changed files with 406 additions and 431 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ sudo: required

php:
- 7
- 7.1

install:
- composer install

script:
- phpunit
- vendor/bin/phpunit
25 changes: 21 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,34 @@
"Rx\\Thruway\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rx\\Thruway\\Tests\\": "tests/",
"Rx\\": "vendor/reactivex/rxphp/test/Rx"
},
"files": [
"vendor/reactivex/rxphp/test/helper-functions.php"
]
},
"require": {
"reactivex/rxphp": "^1.4.1",
"voryx/thruway-common": "^1.0.0",
"php": "^7.0",
"voryx/thruway-common": "^1.0.0",
"ratchet/pawl": "^0.2.2",
"voryx/event-loop": "^0.2.0"
"voryx/event-loop": "^2.0.1",
"reactivex/rxphp": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.5"
},
"repositories": [
{
"type": "vcs",
"url": "[email protected]:voryx/ThruwayCommon.git"
}
]
],
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
}
}
26 changes: 15 additions & 11 deletions examples/authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@

require __DIR__ . '/../vendor/autoload.php';

$client = new Client('ws://127.0.0.1:9090', "somerealm", ["authmethods" => ["simplysimple"]]);
$client = new Client('ws://127.0.0.1:9090', 'somerealm', ['authmethods' => ['simplysimple']]);

$client->onChallenge(function (Observable $challenge) {
return $challenge->map(function ($args) {
list($method, $extra) = $args;
return "letMeIn";
return 'letMeIn';
});
});

$client->register('com.myapp.example', function ($x) {
return $x;
})->subscribeCallback(function () {
echo "Registered ", PHP_EOL;
});
$client
->register('com.myapp.example', function ($x) {
return $x;
})
->subscribe(function () {
echo 'Registered ', PHP_EOL;
});

$client->call('com.myapp.example', [1234])->subscribeCallback(function ($res) {
list($args, $argskw, $details) = $res;
$client
->call('com.myapp.example', [1234])
->subscribe(function ($res) {
list($args, $argskw, $details) = $res;

echo "Call result: ", $args[0], PHP_EOL;
});
echo 'Call result: ', $args[0], PHP_EOL;
});
7 changes: 5 additions & 2 deletions examples/publish.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

require __DIR__ . '/../vendor/autoload.php';

$client = new Client('ws://127.0.0.1:9090', "realm1");
$driver = new \Amp\Loop\LoopFactory();
\Interop\Async\Loop::setFactory($driver);

$client = new Client('ws://127.0.0.1:9090', 'realm1');

$source = Observable::interval(1000);

$x = $client->publish('com.myapp.hello', $source);
$client->publish('com.myapp.hello', $source);
32 changes: 16 additions & 16 deletions examples/register-progress.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php

use Rx\Observer\CallbackObserver;
use Rx\Thruway\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client('ws://127.0.0.1:9090', "realm1");

$client->register('com.myapp.example', function ($x) {
return \Rx\Observable::interval(300, new \Rx\Scheduler\EventLoopScheduler(\EventLoop\getLoop()))->doOnNext(function () {
echo ".";
});
}, ["progress" => true])->subscribeCallback(
function () {
echo "Registered ", PHP_EOL;
},
function (Exception $e) {
echo "Register error: ", $e->getMessage(), PHP_EOL;
},
function () {
echo "Register completed", PHP_EOL;
}
);
$client
->register('com.myapp.example', function ($x) {
return \Rx\Observable::interval(300)->doOnNext(function () {
echo '.';
});
}, ['progress' => true])
->subscribe(
function () {
echo 'Registered ', PHP_EOL;
},
function (Exception $e) {
echo 'Register error: ', $e->getMessage(), PHP_EOL;
},
function () {
echo 'Register completed', PHP_EOL;
});

56 changes: 28 additions & 28 deletions examples/rpc-extended.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
<?php

use Rx\Observer\CallbackObserver;
use Rx\Thruway\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client('ws://127.0.0.1:9090', "realm1");
$client = new Client('ws://127.0.0.1:9090', 'realm1');

$client->registerExtended('com.myapp.example', function ($args, $argskw, $details, $invocationMsg) {
return 1234567;
})->subscribeCallback(
function () {
echo "Registered ", PHP_EOL;
},
function (Exception $e) {
echo "Register error: ", $e->getMessage(), PHP_EOL;
},
function () {
echo "Register completed", PHP_EOL;
}
);
$client
->registerExtended('com.myapp.example', function ($args, $argskw, $details, $invocationMsg) {
return 1234567;
})
->subscribe(
function () {
echo 'Registered ', PHP_EOL;
},
function (Exception $e) {
echo 'Register error: ', $e->getMessage(), PHP_EOL;
},
function () {
echo 'Register completed', PHP_EOL;
});

$client->call('com.myapp.example', [123], ["foo" => "bar"])
->subscribe(new CallbackObserver(
function ($res) {
list($args, $argskw, $details) = $res;
$client
->call('com.myapp.example', [123], ['foo' => 'bar'])
->subscribe(
function ($res) {
list($args, $argskw, $details) = $res;

echo "Call result: ", $args[0], PHP_EOL;
},
function (Exception $e) {
echo "Call error: ", $e->getMessage(), PHP_EOL;
},
function () {
echo "Call completed", PHP_EOL;
})
);
echo 'Call result: ', $args[0], PHP_EOL;
},
function (Exception $e) {
echo 'Call error: ', $e->getMessage(), PHP_EOL;
},
function () {
echo 'Call completed', PHP_EOL;
});
31 changes: 15 additions & 16 deletions examples/rpc-progress.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<?php

use Rx\Observer\CallbackObserver;
use Rx\Thruway\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client('ws://127.0.0.1:9090', "realm1");
$client = new Client('ws://127.0.0.1:9090', 'realm1');

$client->progressiveCall('com.myapp.example', [1234], [])
// ->take(10)
->subscribe(new CallbackObserver(
function ($res) {
list($args, $argskw, $details) = $res;
$client
->progressiveCall('com.myapp.example', [1234], [])
->take(10)
->subscribe(
function ($res) {
list($args, $argskw, $details) = $res;

echo "Call result: ", $args[0], PHP_EOL;
},
function (Exception $e) {
echo "Call error: ", $e->getMessage(), PHP_EOL;
},
function () {
echo "Call completed", PHP_EOL;
})
);
echo 'Call result: ', $args[0], PHP_EOL;
},
function (Exception $e) {
echo 'Call error: ', $e->getMessage(), PHP_EOL;
},
function () {
echo 'Call completed', PHP_EOL;
});
34 changes: 34 additions & 0 deletions examples/rpc-publish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Rx\Observable;
use Rx\Thruway\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client('ws://127.0.0.1:9090', "realm1");

//$source = Observable::interval(1000);

//$x = $client->publish('com.myapp.hello', $source);


$client->register('com.myapp.example', function ($x) {
return $x;
})->subscribe(new \Rx\Observer\CallbackObserver(
function () {
echo "Registered ", PHP_EOL;
},
function (Exception $e) {
echo "Register error: ", $e->getMessage(), PHP_EOL;
},
function () {
echo "Register completed", PHP_EOL;
}), new \Rx\Scheduler\EventLoopScheduler(\EventLoop\getLoop())

);

\EventLoop\addTimer(1, function () use ($client) {
echo "a";
// $client->publish('com.myapp.hello', "hi");
$client->close();
});
27 changes: 13 additions & 14 deletions examples/rpc-repeat-progress.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
<?php

use Rx\Observable;
use Rx\Observer\CallbackObserver;
use Rx\Scheduler\EventLoopScheduler;
use Rx\Thruway\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new Client("ws://127.0.0.1:9090", "realm1");
$scheduler = new EventLoopScheduler(\EventLoop\getLoop());

$client->progressiveRegister('com.myapp.example', function () {
return Observable::interval(500);
})->subscribe(new CallbackObserver(), $scheduler);
$client = new Client('ws://127.0.0.1:9090', 'realm1');

$client
->progressiveRegister('com.myapp.example', function () {
return Observable::interval(500);
})
->subscribe();

$client->progressiveCall('com.myapp.example', [], [])
$client
->progressiveCall('com.myapp.example', [], [])
->take(5)
->repeatWhen(function (Observable $attempts) {
return $attempts->delay(1000)->take(1);
})
->subscribe(new CallbackObserver(
->subscribe(
function ($res) {
list($args, $argskw, $details) = $res;

echo "Call result: ", $args[0], PHP_EOL;
echo 'Call result: ', $args[0], PHP_EOL;
},
function (Exception $e) {
echo "Call error: ", $e->getMessage(), PHP_EOL;
echo 'Call error: ', $e->getMessage(), PHP_EOL;
},
function () {
echo "Call completed", PHP_EOL;
}), $scheduler);
echo 'Call completed', PHP_EOL;
});


//Output
Expand Down
23 changes: 13 additions & 10 deletions examples/rpc-repeat.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
<?php

use Rx\Observable;
use Rx\Thruway\Client;

require __DIR__ . '/../vendor/autoload.php';

$client = new \Rx\Thruway\Client("ws://127.0.0.1:9090", "realm1");
$scheduler = new \Rx\Scheduler\EventLoopScheduler(\EventLoop\getLoop());
$client = new Client('ws://127.0.0.1:9090', 'realm1');


//Repeat only after the proceeding call has completed
$source = $client
->register('com.myapp.example', function () {
return 123;
})
->mapTo($client->call('com.myapp.example'))
->switchLatest()
->switch()
->take(1)
->timeout(2000)
->repeatWhen(function (\Rx\Observable $attempts) {
->repeatWhen(function (Observable $attempts) {
return $attempts->delay(1000);
})
->retryWhen(function (\Rx\Observable $errors) {
->retryWhen(function (Observable $errors) {
return $errors->delay(1000);
});

$source->subscribe(new \Rx\Observer\CallbackObserver(
$source->subscribe(
function ($res) {
list($args, $argskw, $details) = $res;

echo "Call result: ", $args[0], PHP_EOL;
echo 'Call result: ', $args[0], PHP_EOL;
},
function (Exception $e) {
echo "Call error: ", $e->getMessage(), PHP_EOL;
echo 'Call error: ', $e->getMessage(), PHP_EOL;
},
function () {
echo "Call completed", PHP_EOL;
}), $scheduler);
echo 'Call completed', PHP_EOL;
});
Loading

0 comments on commit 71d4484

Please sign in to comment.