[Http] Routing spike
This commit is contained in:
parent
dc59a0a3c0
commit
18bc114408
@ -28,6 +28,7 @@
|
|||||||
"php": ">=5.3.9"
|
"php": ">=5.3.9"
|
||||||
, "react/socket": "0.2.*"
|
, "react/socket": "0.2.*"
|
||||||
, "guzzle/http": "~3.0"
|
, "guzzle/http": "~3.0"
|
||||||
, "symfony/http-foundation": "~2.1"
|
, "symfony/http-foundation": "~2.2"
|
||||||
|
, "symfony/routing": "~2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
135
composer.lock
generated
135
composer.lock
generated
@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"hash": "9ccce99ef687cb79dad8a4c581f38cc5",
|
"_readme": [
|
||||||
|
"This file locks the dependencies of your project to a known state",
|
||||||
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||||
|
],
|
||||||
|
"hash": "b51075c0a68acb956c32e59869790571",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "evenement/evenement",
|
"name": "evenement/evenement",
|
||||||
@ -42,17 +46,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzle/common",
|
"name": "guzzle/common",
|
||||||
"version": "v3.3.0",
|
"version": "v3.4.1",
|
||||||
"target-dir": "Guzzle/Common",
|
"target-dir": "Guzzle/Common",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/common.git",
|
"url": "https://github.com/guzzle/common.git",
|
||||||
"reference": "v3.3.0"
|
"reference": "v3.4.1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/common/zipball/v3.3.0",
|
"url": "https://api.github.com/repos/guzzle/common/zipball/v3.4.1",
|
||||||
"reference": "v3.3.0",
|
"reference": "v3.4.1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -62,7 +66,7 @@
|
|||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "3.0-dev"
|
"dev-master": "3.3-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -82,21 +86,21 @@
|
|||||||
"event",
|
"event",
|
||||||
"exception"
|
"exception"
|
||||||
],
|
],
|
||||||
"time": "2013-03-04 00:41:45"
|
"time": "2013-04-16 20:56:26"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzle/http",
|
"name": "guzzle/http",
|
||||||
"version": "v3.3.0",
|
"version": "v3.4.1",
|
||||||
"target-dir": "Guzzle/Http",
|
"target-dir": "Guzzle/Http",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/http.git",
|
"url": "https://github.com/guzzle/http.git",
|
||||||
"reference": "v3.3.0"
|
"reference": "v3.4.1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/http/zipball/v3.3.0",
|
"url": "https://api.github.com/repos/guzzle/http/zipball/v3.4.1",
|
||||||
"reference": "v3.3.0",
|
"reference": "v3.4.1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -111,7 +115,7 @@
|
|||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "3.0-dev"
|
"dev-master": "3.3-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -139,21 +143,21 @@
|
|||||||
"http",
|
"http",
|
||||||
"http client"
|
"http client"
|
||||||
],
|
],
|
||||||
"time": "2013-03-03 21:40:51"
|
"time": "2013-04-16 20:27:11"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzle/parser",
|
"name": "guzzle/parser",
|
||||||
"version": "v3.3.0",
|
"version": "v3.4.1",
|
||||||
"target-dir": "Guzzle/Parser",
|
"target-dir": "Guzzle/Parser",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/parser.git",
|
"url": "https://github.com/guzzle/parser.git",
|
||||||
"reference": "v3.3.0"
|
"reference": "v3.4.1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/parser/zipball/v3.3.0",
|
"url": "https://api.github.com/repos/guzzle/parser/zipball/v3.4.1",
|
||||||
"reference": "v3.3.0",
|
"reference": "v3.4.1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -162,7 +166,7 @@
|
|||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "3.0-dev"
|
"dev-master": "3.3-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -183,31 +187,34 @@
|
|||||||
"message",
|
"message",
|
||||||
"url"
|
"url"
|
||||||
],
|
],
|
||||||
"time": "2013-01-12 21:43:21"
|
"time": "2013-03-07 22:13:59"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzle/stream",
|
"name": "guzzle/stream",
|
||||||
"version": "v3.3.0",
|
"version": "v3.4.1",
|
||||||
"target-dir": "Guzzle/Stream",
|
"target-dir": "Guzzle/Stream",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/stream.git",
|
"url": "https://github.com/guzzle/stream.git",
|
||||||
"reference": "v3.3.0"
|
"reference": "v3.4.1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/stream/zipball/v3.3.0",
|
"url": "https://api.github.com/repos/guzzle/stream/zipball/v3.4.1",
|
||||||
"reference": "v3.3.0",
|
"reference": "v3.4.1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"guzzle/common": "self.version",
|
"guzzle/common": "self.version",
|
||||||
"php": ">=5.3.2"
|
"php": ">=5.3.2"
|
||||||
},
|
},
|
||||||
|
"suggest": {
|
||||||
|
"guzzle/http": "To convert Guzzle request objects to PHP streams"
|
||||||
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "3.0-dev"
|
"dev-master": "3.3-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -233,7 +240,7 @@
|
|||||||
"component",
|
"component",
|
||||||
"stream"
|
"stream"
|
||||||
],
|
],
|
||||||
"time": "2013-03-03 03:07:02"
|
"time": "2013-04-06 18:28:51"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "react/event-loop",
|
"name": "react/event-loop",
|
||||||
@ -367,17 +374,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/event-dispatcher",
|
"name": "symfony/event-dispatcher",
|
||||||
"version": "v2.2.0",
|
"version": "v2.2.1",
|
||||||
"target-dir": "Symfony/Component/EventDispatcher",
|
"target-dir": "Symfony/Component/EventDispatcher",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/EventDispatcher.git",
|
"url": "https://github.com/symfony/EventDispatcher.git",
|
||||||
"reference": "v2.2.0-RC3"
|
"reference": "v2.2.1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.2.0-RC3",
|
"url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/v2.2.1",
|
||||||
"reference": "v2.2.0-RC3",
|
"reference": "v2.2.1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -421,17 +428,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "symfony/http-foundation",
|
"name": "symfony/http-foundation",
|
||||||
"version": "v2.2.0",
|
"version": "v2.2.1",
|
||||||
"target-dir": "Symfony/Component/HttpFoundation",
|
"target-dir": "Symfony/Component/HttpFoundation",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/symfony/HttpFoundation.git",
|
"url": "https://github.com/symfony/HttpFoundation.git",
|
||||||
"reference": "v2.2.0"
|
"reference": "v2.2.1"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.2.0",
|
"url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/v2.2.1",
|
||||||
"reference": "v2.2.0",
|
"reference": "v2.2.1",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -467,7 +474,65 @@
|
|||||||
],
|
],
|
||||||
"description": "Symfony HttpFoundation Component",
|
"description": "Symfony HttpFoundation Component",
|
||||||
"homepage": "http://symfony.com",
|
"homepage": "http://symfony.com",
|
||||||
"time": "2013-02-26 09:42:13"
|
"time": "2013-04-06 10:15:43"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/routing",
|
||||||
|
"version": "v2.2.1",
|
||||||
|
"target-dir": "Symfony/Component/Routing",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/Routing.git",
|
||||||
|
"reference": "v2.2.1"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/Routing/zipball/v2.2.1",
|
||||||
|
"reference": "v2.2.1",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"doctrine/common": ">=2.2,<3.0",
|
||||||
|
"psr/log": ">=1.0,<2.0",
|
||||||
|
"symfony/config": ">=2.2,<2.3-dev",
|
||||||
|
"symfony/yaml": ">=2.0,<3.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"doctrine/common": "~2.2",
|
||||||
|
"symfony/config": "2.2.*",
|
||||||
|
"symfony/yaml": "2.2.*"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "2.2-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"Symfony\\Component\\Routing\\": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Fabien Potencier",
|
||||||
|
"email": "fabien@symfony.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Symfony Community",
|
||||||
|
"homepage": "http://symfony.com/contributors"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Symfony Routing Component",
|
||||||
|
"homepage": "http://symfony.com",
|
||||||
|
"time": "2013-03-23 12:03:22"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
@ -481,7 +546,7 @@
|
|||||||
|
|
||||||
],
|
],
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": ">=5.3.3"
|
"php": ">=5.3.9"
|
||||||
},
|
},
|
||||||
"platform-dev": [
|
"platform-dev": [
|
||||||
|
|
||||||
|
@ -2,16 +2,15 @@
|
|||||||
namespace Ratchet\Http;
|
namespace Ratchet\Http;
|
||||||
use Ratchet\MessageComponentInterface;
|
use Ratchet\MessageComponentInterface;
|
||||||
use Ratchet\ConnectionInterface;
|
use Ratchet\ConnectionInterface;
|
||||||
|
use Guzzle\Http\Message\Response;
|
||||||
use Symfony\Component\Routing\RouteCollection;
|
use Symfony\Component\Routing\RouteCollection;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
use Symfony\Component\Routing\RequestContext;
|
||||||
|
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||||
|
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||||
|
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
|
||||||
|
|
||||||
class HttpServer implements MessageComponentInterface {
|
class HttpServer implements MessageComponentInterface {
|
||||||
/**
|
|
||||||
* Decorated component
|
|
||||||
* @var HttpServerInterface
|
|
||||||
*/
|
|
||||||
protected $_decorating;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffers incoming HTTP requests returning a Guzzle Request when coalesced
|
* Buffers incoming HTTP requests returning a Guzzle Request when coalesced
|
||||||
* @var HttpRequestParser
|
* @var HttpRequestParser
|
||||||
@ -24,14 +23,24 @@ class HttpServer implements MessageComponentInterface {
|
|||||||
*/
|
*/
|
||||||
protected $_routes;
|
protected $_routes;
|
||||||
|
|
||||||
/**
|
public function __construct() {
|
||||||
* @todo Change parameter from HttpServerInterface to RouteCollection
|
$this->_routes = new RouteCollection;
|
||||||
*/
|
|
||||||
public function __construct(HttpServerInterface $component) {
|
|
||||||
$this->_decorating = $component;
|
|
||||||
$this->_reqParser = new HttpRequestParser;
|
$this->_reqParser = new HttpRequestParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string
|
||||||
|
* @param string
|
||||||
|
* @param Ratchet\Http\HttpServerInterface
|
||||||
|
* @param array
|
||||||
|
*/
|
||||||
|
public function addRoute($name, $path, MessageComponentInterface $controller, $allowedOrigins = array()) {
|
||||||
|
$this->_routes->add($name, new Route($path, array(
|
||||||
|
'_controller' => $controller
|
||||||
|
, 'allowedOrigins' => $allowedOrigins
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @{inheritdoc}
|
* @{inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -53,15 +62,25 @@ class HttpServer implements MessageComponentInterface {
|
|||||||
return $this->close($from, 413);
|
return $this->close($from, 413);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check routes, return 404 or onOpen the route
|
$context = new RequestContext($request->getUrl(), $request->getMethod(), $request->getHost(), $request->getScheme(), $request->getPort());
|
||||||
|
$matcher = new UrlMatcher($this->_routes, $context);
|
||||||
|
|
||||||
$from->Http->headers = true;
|
try {
|
||||||
$from->Http->request = $request;
|
$route = $matcher->match($request->getPath());
|
||||||
|
} catch (MethodNotAllowedException $nae) {
|
||||||
|
return $this->close($from, 403);
|
||||||
|
} catch (ResourceNotFoundException $nfe) {
|
||||||
|
return $this->close($from, 404);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->_decorating->onOpen($from, $request);
|
$from->Http->headers = true;
|
||||||
|
$from->Http->request = $request;
|
||||||
|
$from->Http->controller = $route['_controller'];
|
||||||
|
|
||||||
|
return $from->Http->controller->onOpen($from, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_decorating->onMessage($from, $msg);
|
$from->Http->controller->onMessage($from, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user