This commit is contained in:
Marcel Pociot
2020-04-14 21:19:23 +02:00
commit 2b03398f40
48 changed files with 8099 additions and 0 deletions

58
app/Server/Factory.php Normal file
View File

@@ -0,0 +1,58 @@
<?php
namespace App\Server;
use App\Server\Connections\ConnectionManager;
use React\Socket\Server;
use React\EventLoop\LoopInterface;
use React\EventLoop\Factory as LoopFactory;
class Factory
{
/** @var string */
protected $host = '127.0.0.1';
/** @var int */
protected $port = 8080;
/** @var \React\EventLoop\LoopInterface */
protected $loop;
public function __construct()
{
$this->loop = LoopFactory::create();
}
public function setHost(string $host)
{
$this->host = $host;
return $this;
}
public function setPort(int $port)
{
$this->port = $port;
return $this;
}
public function setLoop(LoopInterface $loop)
{
$this->loop = $loop;
return $this;
}
public function createServer()
{
$socket = new Server("{$this->host}:{$this->port}", $this->loop);
$connectionManager = new ConnectionManager($this->host, $this->port);
$app = new Shaft($connectionManager);
return new IoServer($app, $socket, $this->loop);
}
}