Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Base DNode on top of react/socket, fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
igorw committed Jun 16, 2012
1 parent 5e34020 commit 5379dd2
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 90 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
],
"require": {
"php": ">=5.3.0",
"evenement/evenement": ">=0.1.0"
"evenement/evenement": ">=0.1.0",
"react/socket": "dev-master"
},
"autoload": {
"psr-0": {
Expand Down
6 changes: 5 additions & 1 deletion examples/bidirectional/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public function temperature($cb)
}
}

$dnode = new DNode\DNode(new Temp());
$loop = new React\EventLoop\StreamSelectLoop();

$dnode = new DNode\DNode($loop, new Temp());
$dnode->connect(6060, function($remote, $connection) {
// Ask server for temperature in Fahrenheit
$remote->clientTempF(function($degF) use ($connection) {
Expand All @@ -23,3 +25,5 @@ public function temperature($cb)
$connection->end();
});
});

$loop->run();
6 changes: 5 additions & 1 deletion examples/bidirectional/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public function clientTempF($cb)
}
}

$loop = new React\EventLoop\StreamSelectLoop();

// Create a DNode server
$server = new DNode\DNode(new Converter());
$server = new DNode\DNode($loop, new Converter());
$server->listen(6060);

$loop->run();
10 changes: 8 additions & 2 deletions examples/phpcr/RemoteSessionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ class RemoteSessionClient
private $value = null;
private $error = null;
private $exception = null;
private $dnode = null;
private $loop = null;
private $port = 0;
private $dnode = null;

public function __construct ($port)
{
$this->loop = new React\EventLoop\StreamSelectLoop();

$this->port = $port;
$this->dnode = new DNode\DNode($this);
$this->dnode = new DNode\DNode($this->loop, $this);
}

public function getPropertyValue($path)
Expand All @@ -25,13 +28,16 @@ public function getPropertyValue($path)
$connection->end();
});
});
$this->loop->run();

if ($this->exception != null) {
$exception = $this->exception;
$msg = $this->error;
$this->exception = null;
$this->error = null;
throw new $exception($msg);
}

return $this->value;
}

Expand Down
16 changes: 12 additions & 4 deletions examples/phpcr/RemoteSessionServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class RemoteSessionServer

public function __construct ($repository, $credentials, $workspace = null)
{
$this->crSession = $repository->login($credentials, $workspace);
$this->dnode = new DNode\DNode($this);
$this->loop = new React\EventLoop\StreamSelectLoop();

$this->crSession = $repository->login($credentials, $workspace);
$this->dnode = new DNode\DNode($this->loop, $this);
}

/* Get value of the property at defined path */
Expand All @@ -24,14 +26,15 @@ public function getPropertyValue($path, $cb)
} catch (\Exception $e) {
$this->remote->setException(get_class($e), $e->getMessage());
}
$this->remote->setValue($value, function() use ($cb) {
$this->remote->setValue($value, function() use ($cb) {
$cb();
});
}

public function listen($port)
{
$this->dnode->listen($port);
$this->loop->run();
}
}

Expand All @@ -47,7 +50,12 @@ public function listen($port)
$server->listen(6060);
exit;
$loop = new React\EventLoop\StreamSelectLoop();
// Create a DNode server
$server = new DNode\DNode(new Converter());
$server = new DNode\DNode($loop, new Converter());
$server->listen(6060);
$loop->run();
*/
8 changes: 6 additions & 2 deletions examples/phpcr/simple/client.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
// Include Composer-generated autoloader
require(__DIR__.'/../../vendor/.composer/autoload.php');
require(__DIR__.'/../../vendor/autoload.php');

$loop = new React\EventLoop\StreamSelectLoop();

// Connect to DNode server running in port 7070 and call Zing with argument 33
$dnode = new DNode\DNode();
$dnode = new DNode\DNode($loop);
$dnode->connect(7070, function($remote, $connection) {
$remote->getPropertyValue("default", "/jcr:primaryType", function($val, $exc, $error) use ($connection) {
echo $val;
Expand All @@ -12,3 +14,5 @@
$connection->end();
});
});

$loop->run();
21 changes: 12 additions & 9 deletions examples/phpcr/simple/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class SimpleRemoteRepository
*
* @param $repository - Repository created with RepositoryFactory.
* @return new remote repository
*/
*/
public function __construct ($repository) {
$this->loop = new React\EventLoop\StreamSelectLoop();

$this->repository = $repository;
$this->dnode = new DNode\DNode($this);
}
$this->dnode = new DNode\DNode($this->loop, $this);
}

private function validateSessionName($name, $cb)
{
Expand All @@ -35,12 +37,12 @@ private function validateSessionName($name, $cb)
/**
* Get the names of children nodes
*
* @param $sessionName - name of the session
* @param $sessionName - name of the session
* @param $path - absolute path of the parent node
* @param $cb - callback function
*
* @return void
*/
*/
public function getNodes($sessionName, $path, $cb)
{
if (!$this->validateSessionName($sessionName, $cb))
Expand All @@ -65,12 +67,12 @@ public function getNodes($sessionName, $path, $cb)
/**
* Get the names of all properties
*
* @param $sessionName - name of the session
* @param $sessionName - name of the session
* @param $path - absolute path of the node
* @param $cb - callback function
*
* @return void
*/
*/
public function getProperties($sessionName, $path, $cb)
{
if (!$this->validateSessionName($sessionName, $cb))
Expand Down Expand Up @@ -133,7 +135,7 @@ public function addNode($sessionName, $path, $name, $type, $cb)

try {
$parent = $this->sessions[$sessionName]->getNode($path);
$parent->addNode($name, $type);
$parent->addNode($name, $type);
} catch (\Exception $e) {
$exception = get_class($e);
$msg = $e->getMessage();
Expand All @@ -152,7 +154,7 @@ public function setProperty($sessionName, $path, $name, $value, $type, $cb)

try {
$parent = $this->sessions[$sessionName]->getNode($path);
$parent->setProperty($name, $value, $type);
$parent->setProperty($name, $value, $type);
} catch (\Exception $e) {
$exception = get_class($e);
$msg = $e->getMessage();
Expand All @@ -171,6 +173,7 @@ public function createSession($sessionName, $name, $password)
public function listen($port)
{
$this->dnode->listen($port);
$this->loop->run();
}
}

Expand Down
6 changes: 5 additions & 1 deletion examples/simple/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
// Include Composer-generated autoloader
require(__DIR__.'/../../vendor/autoload.php');

$loop = new React\EventLoop\StreamSelectLoop();

// Connect to DNode server running in port 7070 and call Zing with argument 33
$dnode = new DNode\DNode();
$dnode = new DNode\DNode($loop);
$dnode->connect(7070, function($remote, $connection) {
$remote->zing(33, function($n) use ($connection) {
echo "n = {$n}\n";
$connection->end();
});
});

$loop->run();
6 changes: 5 additions & 1 deletion examples/simple/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public function zing($n, $cb)
}
}

$loop = new React\EventLoop\StreamSelectLoop();

// Create a DNode server
$server = new DNode\DNode(new Zinger());
$server = new DNode\DNode($loop, new Zinger());
$server->listen(7070);

$loop->run();
Loading

0 comments on commit 5379dd2

Please sign in to comment.