Skip to content

Commit

Permalink
Rename WebsocketObserver to WebsocketServerObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jul 1, 2020
1 parent 40758b5 commit ebccbdb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/stackexchange-questions/server.php
Expand Up @@ -22,15 +22,15 @@
use Amp\Websocket\Server\ClientHandler;
use Amp\Websocket\Server\Gateway;
use Amp\Websocket\Server\Websocket;
use Amp\Websocket\Server\WebsocketObserver;
use Amp\Websocket\Server\WebsocketServerObserver;
use Monolog\Logger;
use function Amp\ByteStream\getStdout;
use function Amp\call;

require __DIR__ . '/../../vendor/autoload.php';

Loop::run(function (): Promise {
$websocket = new Websocket(new class implements ClientHandler, WebsocketObserver {
$websocket = new Websocket(new class implements ClientHandler, WebsocketServerObserver {
/** @var string|null */
private $watcher;

Expand Down
14 changes: 7 additions & 7 deletions src/Websocket.php
Expand Up @@ -69,15 +69,15 @@ public function __construct(
$this->compressionFactory = $compressionFactory ?? new Rfc7692CompressionFactory;
$this->clientFactory = $clientFactory ?? new Rfc6455ClientFactory;

if ($this->clientHandler instanceof WebsocketObserver) {
if ($this->clientHandler instanceof WebsocketServerObserver) {
$this->observers->attach($this->clientHandler);
}

if ($this->clientFactory instanceof WebsocketObserver) {
if ($this->clientFactory instanceof WebsocketServerObserver) {
$this->observers->attach($this->clientFactory);
}

if ($this->compressionFactory instanceof WebsocketObserver) {
if ($this->compressionFactory instanceof WebsocketServerObserver) {
$this->observers->attach($this->compressionFactory);
}
}
Expand Down Expand Up @@ -418,9 +418,9 @@ public function getOptions(): Options
/**
* Attaches a WebsocketObserver that is notified when the server starts and stops.
*
* @param WebsocketObserver $observer
* @param WebsocketServerObserver $observer
*/
public function attach(WebsocketObserver $observer): void
public function attach(WebsocketServerObserver $observer): void
{
$this->observers->attach($observer);
}
Expand All @@ -441,7 +441,7 @@ public function onStart(HttpServer $server): Promise
return call(function () use ($server): \Generator {
$onStartPromises = [];
foreach ($this->observers as $observer) {
\assert($observer instanceof WebsocketObserver);
\assert($observer instanceof WebsocketServerObserver);
$onStartPromises[] = $observer->onStart($server, $this);
}

Expand All @@ -461,7 +461,7 @@ public function onStop(HttpServer $server): Promise
return call(function () use ($server): \Generator {
$onStopPromises = [];
foreach ($this->observers as $observer) {
\assert($observer instanceof WebsocketObserver);
\assert($observer instanceof WebsocketServerObserver);
$onStopPromises[] = $observer->onStop($server, $this);
}

Expand Down
Expand Up @@ -5,7 +5,7 @@
use Amp\Http\Server\HttpServer;
use Amp\Promise;

interface WebsocketObserver
interface WebsocketServerObserver
{
/**
* Called when the HTTP server is started. If an instance of WebsocketObserver is attached to multiple
Expand Down
4 changes: 2 additions & 2 deletions test/WebsocketTest.php
Expand Up @@ -20,7 +20,7 @@
use Amp\Websocket\Server\ClientHandler;
use Amp\Websocket\Server\Gateway;
use Amp\Websocket\Server\Websocket;
use Amp\Websocket\Server\WebsocketObserver;
use Amp\Websocket\Server\WebsocketServerObserver;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\UriInterface as PsrUri;
use Psr\Log\NullLogger;
Expand Down Expand Up @@ -297,7 +297,7 @@ public function testWebsocketObserverAttachment(): \Generator

$webserver = new HttpServer([Server::listen('127.0.0.1:0')], $websocket, new NullLogger);

$observer = $this->createMock(WebsocketObserver::class);
$observer = $this->createMock(WebsocketServerObserver::class);
$observer->expects($this->once())
->method('onStart')
->willReturn(new Success);
Expand Down

0 comments on commit ebccbdb

Please sign in to comment.