This commit is contained in:
Marcel Pociot
2020-05-01 20:52:12 +02:00
parent ea394c8e54
commit c717683634
16 changed files with 145 additions and 96 deletions

View File

@@ -35,14 +35,14 @@ class ConnectionManager implements ConnectionManagerContract
return $storedConnection;
}
public function storeHttpConnection(ConnectionInterface $httpConnection, $requestId): ConnectionInterface
public function storeHttpConnection(ConnectionInterface $httpConnection, $requestId): HttpConnection
{
$this->httpConnections[$requestId] = $httpConnection;
$this->httpConnections[$requestId] = new HttpConnection($httpConnection);
return $httpConnection;
return $this->httpConnections[$requestId];
}
public function getHttpConnectionForRequestId(string $requestId): ?ConnectionInterface
public function getHttpConnectionForRequestId(string $requestId): ?HttpConnection
{
return $this->httpConnections[$requestId] ?? null;
}

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Server\Connections;
use Evenement\EventEmitterTrait;
use Ratchet\ConnectionInterface;
class HttpConnection
{
use EventEmitterTrait;
/** @var ConnectionInterface */
public $socket;
public function __construct(ConnectionInterface $socket)
{
$this->socket = $socket;
}
public function send($data)
{
$this->emit('data', [$data]);
$this->socket->send($data);
}
public function close()
{
$this->emit('close');
$this->socket->close();
}
}