Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
middleware update
  • Loading branch information
valentint committed Feb 21, 2017
commit 86a91f2a6ad08df399a63c9bfa6c8614efc9791b
17 changes: 5 additions & 12 deletions Server/App/Stack/Factory/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,38 @@ public function __construct(
) {
$this->_component = $component;
$this->_middleware = $middleware;
$this->_middleware->setComponent($component);
}

/**
* {@inheritdoc}
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
$answer = $this->_middleware->onOpen($conn, $request);

return $answer instanceof ConnectionInterface ? $answer : $this->_component->onOpen($conn, $request);
return $this->_middleware->onOpen($conn, $request);
}

/**
* {@inheritdoc}
*/
public function onMessage(ConnectionInterface $from, $msg)
{
$this->_middleware->onMessage($from, $msg);

return $this->_component->onMessage($from, $msg);
return $this->_middleware->onMessage($from, $msg);
}

/**
* {@inheritdoc}
*/
public function onClose(ConnectionInterface $conn)
{
$this->_middleware->onClose($conn);

return $this->_component->onClose($conn);
return $this->_middleware->onClose($conn);
}

/**
* {@inheritdoc}
*/
public function onError(ConnectionInterface $conn, \Exception $e)
{
$this->_middleware->onError($conn, $e);

return $this->_component->onError($conn, $e);
return $this->_middleware->onError($conn, $e);
}
}
45 changes: 39 additions & 6 deletions Server/App/Stack/HandshakeMiddlewareAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,50 @@ abstract class HandshakeMiddlewareAbstract implements HttpServerInterface
*/
protected $_component;

/**
* @param MessageComponentInterface $component
*/
public function setComponent(MessageComponentInterface $component)
{
$this->_component = $component;
}

/**
* @param \Ratchet\ConnectionInterface $conn
* @param \Guzzle\Http\Message\RequestInterface $request null is default because PHP won't let me overload; don't pass null!!!
*
* @return ConnectionInterface|void
* @throws \UnexpectedValueException if a RequestInterface is not passed
* @param ConnectionInterface $conn
* @param RequestInterface|null $request
* @return mixed
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
return $this->_component->onOpen($conn, $request);
}

/**
* @param ConnectionInterface $conn
* @return mixed
*/
abstract public function onOpen(ConnectionInterface $conn, RequestInterface $request = null);
public function onClose(ConnectionInterface $conn)
{
return $this->_component->onClose($conn);
}

/**
* @param ConnectionInterface $conn
* @param \Exception $e
* @return mixed
*/
public function onError(ConnectionInterface $conn, \Exception $e)
{
return $this->_component->onError($conn, $e);
}

/**
* @param ConnectionInterface $from
* @param string $msg
* @return mixed
*/
public function onMessage(ConnectionInterface $from, $msg)
{
return $this->_component->onMessage($from, $msg);
}
}