Skip to content

Commit 30c664e

Browse files
committed
Mark Server and SecureServer as final
Classes should be used via composition rather than extension. This reduces our API footprint and avoids future BC breaks by avoiding exposing its internal assumptions.
1 parent 5166af7 commit 30c664e

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ If you want to typehint in your higher-level protocol implementation, you SHOULD
296296
use the generic [`ServerInterface`](#serverinterface) instead.
297297

298298
> Advanced usage: Despite allowing any `ServerInterface` as first parameter,
299-
you SHOULD pass an unmodified `Server` instance as first parameter, unless you
299+
you SHOULD pass a `Server` instance as first parameter, unless you
300300
know what you're doing.
301301
Internally, the `SecureServer` has to set the required TLS context options on
302302
the underlying stream resources.
303303
These resources are not exposed through any of the interfaces defined in this
304304
package, but only through the `React\Stream\Stream` class.
305-
The unmodified `Server` class is guaranteed to emit connections that implement
305+
The `Server` class is guaranteed to emit connections that implement
306306
the `ConnectionInterface` and also extend the `Stream` class in order to
307307
expose these underlying resources.
308308
If you use a custom `ServerInterface` and its `connection` event does not

src/SecureServer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @see ServerInterface
5353
* @see ConnectionInterface
5454
*/
55-
class SecureServer extends EventEmitter implements ServerInterface
55+
final class SecureServer extends EventEmitter implements ServerInterface
5656
{
5757
private $tcp;
5858
private $encryption;
@@ -96,13 +96,13 @@ class SecureServer extends EventEmitter implements ServerInterface
9696
* Passing unknown context options has no effect.
9797
*
9898
* Advanced usage: Despite allowing any `ServerInterface` as first parameter,
99-
* you SHOULD pass an unmodified `Server` instance as first parameter, unless you
99+
* you SHOULD pass a `Server` instance as first parameter, unless you
100100
* know what you're doing.
101101
* Internally, the `SecureServer` has to set the required TLS context options on
102102
* the underlying stream resources.
103103
* These resources are not exposed through any of the interfaces defined in this
104104
* package, but only through the `React\Stream\Stream` class.
105-
* The unmodified `Server` class is guaranteed to emit connections that implement
105+
* The `Server` class is guaranteed to emit connections that implement
106106
* the `ConnectionInterface` and also extend the `Stream` class in order to
107107
* expose these underlying resources.
108108
* If you use a custom `ServerInterface` and its `connection` event does not

src/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @see ServerInterface
3535
* @see ConnectionInterface
3636
*/
37-
class Server extends EventEmitter implements ServerInterface
37+
final class Server extends EventEmitter implements ServerInterface
3838
{
3939
private $master;
4040
private $loop;

tests/SecureServerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace React\Tests\Socket;
44

55
use React\Socket\SecureServer;
6+
use React\Socket\Server;
67

78
class SecureServerTest extends TestCase
89
{
@@ -39,10 +40,10 @@ public function testCloseWillBePassedThroughToTcpServer()
3940

4041
public function testConnectionWillBeEndedWithErrorIfItIsNotAStream()
4142
{
42-
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->setMethods(null)->getMock();
43-
4443
$loop = $this->getMock('React\EventLoop\LoopInterface');
4544

45+
$tcp = new Server(0, $loop);
46+
4647
$connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
4748
$connection->expects($this->once())->method('end');
4849

@@ -55,10 +56,10 @@ public function testConnectionWillBeEndedWithErrorIfItIsNotAStream()
5556

5657
public function testSocketErrorWillBeForwarded()
5758
{
58-
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->setMethods(null)->getMock();
59-
6059
$loop = $this->getMock('React\EventLoop\LoopInterface');
6160

61+
$tcp = new Server(0, $loop);
62+
6263
$server = new SecureServer($tcp, $loop, array());
6364

6465
$server->on('error', $this->expectCallableOnce());

0 commit comments

Comments
 (0)