File tree 10 files changed +92
-20
lines changed
10 files changed +92
-20
lines changed Original file line number Diff line number Diff line change 18
18
"php" : " >=8.1" ,
19
19
"guzzlehttp/psr7" : " ^2.0"
20
20
},
21
+ "scripts" : {
22
+ "analyse" : " phpstan analyse" ,
23
+ "test" : " phpunit"
24
+ },
21
25
"require-dev" : {
22
- "openswoole/ide-helper" : " ^4.10"
26
+ "openswoole/ide-helper" : " ^4.10" ,
27
+ "phpstan/phpstan" : " ^1.4" ,
28
+ "phpunit/phpunit" : " ^9.5"
23
29
}
24
30
}
Original file line number Diff line number Diff line change
1
+ parameters :
2
+ level : 8
3
+ paths : [' src' , ' tests' ]
4
+ checkMissingIterableValueType : false
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+
3
+ <phpunit backupGlobals =" false"
4
+ backupStaticAttributes =" false"
5
+ colors =" true"
6
+ convertErrorsToExceptions =" true"
7
+ convertNoticesToExceptions =" true"
8
+ convertWarningsToExceptions =" true"
9
+ processIsolation =" false"
10
+ >
11
+ <testsuites >
12
+ <testsuite name =" PHP RTC Websocket Server Tests" >
13
+ <directory >./tests</directory >
14
+ </testsuite >
15
+ </testsuites >
16
+ </phpunit >
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ abstract public static function throw(
12
12
string $ message ,
13
13
int $ code = 0 ,
14
14
Throwable |null $ previous = null
15
- );
15
+ ): never ;
16
16
17
17
abstract public function getRequest (): RequestInterface ;
18
18
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace RTC \Contracts \Http ;
4
4
5
- use RTC \Http \Exceptions \MiddlewareException ;
6
5
use SplQueue ;
7
6
8
7
interface RequestMiddlewareInterface
@@ -21,7 +20,7 @@ public function push(MiddlewareInterface $middleware): void;
21
20
* Executes next middleware in the queue
22
21
*
23
22
* @return void
24
- * @throws MiddlewareException
23
+ * @throws HttpException
25
24
*/
26
25
public function next (): void ;
27
26
@@ -49,7 +48,7 @@ public function getCurrent(): null|MiddlewareInterface;
49
48
/**
50
49
* Retrieve middlewares queue object
51
50
*
52
- * @return SplQueue
51
+ * @return SplQueue<MiddlewareInterface>
53
52
*/
54
53
public function getQueue (): SplQueue ;
55
54
}
Original file line number Diff line number Diff line change @@ -28,11 +28,11 @@ public function write(string $data): static;
28
28
public function cookie (
29
29
string $ key ,
30
30
string $ value = '' ,
31
- int $ expire = 0 ,
31
+ int $ expire = 0 ,
32
32
string $ path = '/ ' ,
33
33
string $ domain = '' ,
34
- bool $ secure = false ,
35
- bool $ httponly = false ,
34
+ bool $ secure = false ,
35
+ bool $ httponly = false ,
36
36
string $ samesite = '' ,
37
37
string $ priority = ''
38
38
): static ;
Original file line number Diff line number Diff line change 2
2
3
3
namespace RTC \Contracts \Http \Router ;
4
4
5
+ use FastRoute \RouteCollector ;
6
+
5
7
interface CollectorInterface
6
8
{
7
9
public function collectFile (string $ filePath , array $ routesInfo = []): static ;
@@ -14,7 +16,7 @@ public function prefixDelimiter(string $delimiter): static;
14
16
15
17
public function register (): static ;
16
18
17
- public function getFastRouteCollector (bool $ createNew = false ): \ FastRoute \ RouteCollector ;
19
+ public function getFastRouteCollector (bool $ createNew = false ): RouteCollector ;
18
20
19
21
public function getCollectedRoutes (): array ;
20
22
Original file line number Diff line number Diff line change @@ -9,23 +9,30 @@ interface FrameInterface
9
9
public function __construct (Frame $ frame );
10
10
11
11
/**
12
- * Returns Swoole frame object
12
+ * Gets message sent from client
13
13
*
14
- * @return Frame
14
+ * @return mixed
15
15
*/
16
- public function getFrame (): Frame ;
16
+ public function getMessage (): mixed ;
17
17
18
18
/**
19
- * Returns json-decoded message array
19
+ * Returns command name sent by client
20
20
*
21
- * @return array
21
+ * @return string|null
22
22
*/
23
- public function getMessage (): array ;
23
+ public function getCommand (): string | null ;
24
24
25
25
/**
26
- * Returns json-decoded message array
26
+ * Returns payload-sent time
27
27
*
28
28
* @return string
29
29
*/
30
- public function getRawMessage (): string ;
30
+ public function getTime (): string ;
31
+
32
+ /**
33
+ * Returns json-decoded message array
34
+ *
35
+ * @return PayloadInterface
36
+ */
37
+ public function getPayload (): PayloadInterface ;
31
38
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace RTC \Contracts \Websocket ;
4
+
5
+ use Swoole \WebSocket \Frame ;
6
+
7
+ interface PayloadInterface
8
+ {
9
+ public function __construct (Frame $ frame );
10
+
11
+ /**
12
+ * Returns payload sent from client
13
+ *
14
+ * @return string
15
+ */
16
+ public function getRaw (): string ;
17
+
18
+ /**
19
+ * Returns json-decoded client-sent payload
20
+ *
21
+ * @return array
22
+ */
23
+ public function getDecoded (): array ;
24
+
25
+ /**
26
+ * Returns Swoole frame object
27
+ *
28
+ * @return Frame
29
+ */
30
+ public function getSwooleFrame (): Frame ;
31
+
32
+ /**
33
+ * Returns time which the server receives this payload
34
+ *
35
+ * @return string
36
+ */
37
+ public function getServerTime (): string ;
38
+
39
+ }
Original file line number Diff line number Diff line change 3
3
namespace RTC \Contracts \Websocket ;
4
4
5
5
use RTC \Server \Server ;
6
- use RTC \Websocket \Frame ;
7
6
use Throwable ;
8
7
9
8
interface WebsocketHandlerInterface
@@ -14,11 +13,11 @@ public function __construct(Server $server);
14
13
* Method that will be called when message is received
15
14
*
16
15
* @param ConnectionInterface $connection
17
- * @param Frame $frame
16
+ * @param FrameInterface $frame
18
17
* @return void
19
18
* @throws Throwable
20
19
*/
21
- public function onMessage (ConnectionInterface $ connection , Frame $ frame ): void ;
20
+ public function onMessage (ConnectionInterface $ connection , FrameInterface $ frame );
22
21
23
22
/**
24
23
* Method that will be called when new connection is received
You can’t perform that action at this time.
0 commit comments