Merge branch 'benconnito'

This commit is contained in:
Chris Boden 2014-11-24 09:05:13 -05:00
commit 99285acca0
5 changed files with 43 additions and 17 deletions

10
.gitignore vendored
View File

@ -1,5 +1,5 @@
phpunit.xml
reports
sandbox
vendor
composer.lock
phpunit.xml
reports
sandbox
vendor
composer.lock

View File

@ -43,6 +43,12 @@ class App {
*/
protected $httpHost;
/***
* The port the socket is listening
* @var int
*/
protected $port;
/**
* @var int
*/
@ -56,7 +62,7 @@ class App {
*/
public function __construct($httpHost = 'localhost', $port = 8080, $address = '127.0.0.1', LoopInterface $loop = null) {
if (extension_loaded('xdebug')) {
trigger_error("XDebug extension detected. Remember to disable this if performance testing or going live!", E_USER_WARNING);
trigger_error('XDebug extension detected. Remember to disable this if performance testing or going live!', E_USER_WARNING);
}
if (3 !== strlen('✓')) {
@ -68,6 +74,7 @@ class App {
}
$this->httpHost = $httpHost;
$this->port = $port;
$socket = new Reactor($loop);
$socket->listen($port, $address);
@ -80,7 +87,6 @@ class App {
$policy->addAllowedAccess($httpHost, $port);
$flashSock = new Reactor($loop);
$this->flashServer = new IoServer($policy, $flashSock);
if (80 == $port) {
$flashSock->listen(843, '0.0.0.0');
} else {
@ -119,6 +125,13 @@ class App {
$decorated = new OriginCheck($decorated, $allowedOrigins);
}
//allow origins in flash policy server
if(empty($this->flashServer) === false) {
foreach($allowedOrigins as $allowedOrgin) {
$this->flashServer->app->addAllowedAccess($allowedOrgin, $this->port);
}
}
$this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost));
return $decorated;

View File

@ -107,7 +107,7 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface {
$json = $json[0];
}
$this->_decorating->onCall($from, $callID, $procURI, $json);
$this->_decorating->onCall($from, $callID, $from->getUri($procURI), $json);
break;
case static::MSG_SUBSCRIBE:

View File

@ -17,7 +17,7 @@ class WampConnection extends AbstractConnectionDecorator {
parent::__construct($conn);
$this->WAMP = new \StdClass;
$this->WAMP->sessionId = uniqid();
$this->WAMP->sessionId = str_replace('.', '', uniqid(mt_rand(), true));
$this->WAMP->prefixes = array();
$this->send(json_encode(array(WAMP::MSG_WELCOME, $this->WAMP->sessionId, 1, \Ratchet\VERSION)));
@ -26,10 +26,10 @@ class WampConnection extends AbstractConnectionDecorator {
/**
* Successfully respond to a call made by the client
* @param string $id The unique ID given by the client to respond to
* @param array $data An array of data to return to the client
* @param array $data an object or array
* @return WampConnection
*/
public function callResult($id, array $data = array()) {
public function callResult($id, $data = array()) {
return $this->send(json_encode(array(WAMP::MSG_CALL_RESULT, $id, $data)));
}
@ -81,7 +81,19 @@ class WampConnection extends AbstractConnectionDecorator {
* @return string
*/
public function getUri($uri) {
return (array_key_exists($uri, $this->WAMP->prefixes) ? $this->WAMP->prefixes[$uri] : $uri);
$curieSeperator = ':';
$fullSeperator = '#';
if (preg_match('/http(s*)\:\/\//', $uri) == false) {
if (strpos($uri, $curieSeperator) !== false) {
list($prefix, $action) = explode($curieSeperator, $uri);
$expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix;
return $expandedPrefix . $fullSeperator . $action;
}
}
return $uri;
}
/**

View File

@ -211,13 +211,14 @@ class ServerProtocolTest extends \PHPUnit_Framework_TestCase {
$conn = new WampConnection($this->newConn());
$this->_comp->onOpen($conn);
$shortIn = 'incoming';
$longIn = 'http://example.com/incoming/';
$prefix = 'incoming';
$fullURI = "http://example.com/$prefix";
$method = 'call';
$this->_comp->onMessage($conn, json_encode(array(1, $shortIn, $longIn)));
$this->_comp->onMessage($conn, json_encode(array(1, $prefix, $fullURI)));
$this->assertEquals($longIn, $conn->WAMP->prefixes[$shortIn]);
$this->assertEquals($longIn, $conn->getUri($shortIn));
$this->assertEquals($fullURI, $conn->WAMP->prefixes[$prefix]);
$this->assertEquals("$fullURI#$method", $conn->getUri("$prefix:$method"));
}
public function testMessageMustBeJson() {