Create a noop controller for impatient clients
This commit is contained in:
parent
e3e223066c
commit
a83a4e460a
18
src/Ratchet/Http/NoOpHttpServerController.php
Normal file
18
src/Ratchet/Http/NoOpHttpServerController.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
namespace Ratchet\Http;
|
||||||
|
use Ratchet\ConnectionInterface;
|
||||||
|
use Psr\Http\Message\RequestInterface;
|
||||||
|
|
||||||
|
class NoOpHttpServerController implements HttpServerInterface {
|
||||||
|
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onMessage(ConnectionInterface $from, $msg) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onClose(ConnectionInterface $conn) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onError(ConnectionInterface $conn, \Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
@ -15,8 +15,11 @@ class Router implements HttpServerInterface {
|
|||||||
*/
|
*/
|
||||||
protected $_matcher;
|
protected $_matcher;
|
||||||
|
|
||||||
|
private $_noopController;
|
||||||
|
|
||||||
public function __construct(UrlMatcherInterface $matcher) {
|
public function __construct(UrlMatcherInterface $matcher) {
|
||||||
$this->_matcher = $matcher;
|
$this->_matcher = $matcher;
|
||||||
|
$this->_noopController = new NoOpHttpServerController;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,6 +31,8 @@ class Router implements HttpServerInterface {
|
|||||||
throw new \UnexpectedValueException('$request can not be null');
|
throw new \UnexpectedValueException('$request can not be null');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$conn->controller = $this->_noopController;
|
||||||
|
|
||||||
$uri = $request->getUri();
|
$uri = $request->getUri();
|
||||||
|
|
||||||
$context = $this->_matcher->getContext();
|
$context = $this->_matcher->getContext();
|
||||||
@ -67,14 +72,14 @@ class Router implements HttpServerInterface {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
function onMessage(ConnectionInterface $from, $msg) {
|
public function onMessage(ConnectionInterface $from, $msg) {
|
||||||
$from->controller->onMessage($from, $msg);
|
$from->controller->onMessage($from, $msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
function onClose(ConnectionInterface $conn) {
|
public function onClose(ConnectionInterface $conn) {
|
||||||
if (isset($conn->controller)) {
|
if (isset($conn->controller)) {
|
||||||
$conn->controller->onClose($conn);
|
$conn->controller->onClose($conn);
|
||||||
}
|
}
|
||||||
@ -83,7 +88,7 @@ class Router implements HttpServerInterface {
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
function onError(ConnectionInterface $conn, \Exception $e) {
|
public function onError(ConnectionInterface $conn, \Exception $e) {
|
||||||
if (isset($conn->controller)) {
|
if (isset($conn->controller)) {
|
||||||
$conn->controller->onError($conn, $e);
|
$conn->controller->onError($conn, $e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user