Skip to content

Commit 6254af9

Browse files
author
ahmard
committed
Initial Commit
0 parents  commit 6254af9

11 files changed

+168
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.idea
2+
/vendor
3+
4+
/composer.lock

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# PHP RTC Contracts

composer.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "phprtc/contracts",
3+
"description": "PHP RTC Contracts",
4+
"type": "project",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"RTC\\Contracts\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "Ahmard",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {
18+
"php": ">=8.1",
19+
"guzzlehttp/psr7": "^2.0"
20+
},
21+
"require-dev": {
22+
"swoole/ide-helper": "^4.7"
23+
}
24+
}

src/Http/HttpHandlerInterface.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Http;
4+
5+
use QuickRoute\Router\Collector;
6+
7+
interface HttpHandlerInterface
8+
{
9+
public function handle(RequestInterface $request): void;
10+
11+
public function setRouteCollector(Collector $collector): static;
12+
13+
public function hasRouteCollector(): bool;
14+
15+
public function getRouteCollector(): Collector;
16+
}

src/Http/MiddlewareInterface.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Http;
4+
5+
interface MiddlewareInterface
6+
{
7+
public function handle(RequestInterface $request): void;
8+
}

src/Http/RequestInterface.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Http;
4+
5+
use QuickRoute\Router\DispatchResult;
6+
7+
interface RequestInterface extends \Psr\Http\Message\RequestInterface
8+
{
9+
public function initMiddleware(MiddlewareInterface ...$middlewares): void;
10+
11+
public function getResponse(): ResponseInterface;
12+
13+
public function getMiddleware(): RequestMiddlewareInterface;
14+
15+
public function getRouteDispatchResult(): DispatchResult;
16+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Http;
4+
5+
use SplQueue;
6+
7+
interface RequestMiddlewareInterface
8+
{
9+
public function __construct(RequestInterface $request, array $middlewares);
10+
11+
public function push(MiddlewareInterface $middleware): void;
12+
13+
public function next(): void;
14+
15+
public function getCurrent(): MiddlewareInterface;
16+
17+
public function getQueue(): SplQueue;
18+
}

src/Http/ResponseInterface.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Http;
4+
5+
use Swoole\Http\Response as Http1Response;
6+
use Swoole\Http2\Response as Http2Response;
7+
8+
interface ResponseInterface
9+
{
10+
public function __construct(RequestInterface $request, Http1Response|Http2Response $response);
11+
12+
public function json(array|object $data, int $status = 200, array $headers = []): void;
13+
14+
public function html(string $code, int $status = 200, array $headers = []): void;
15+
16+
public function plain(string $string, int $status = 200, array $headers = []): void;
17+
18+
public function redirect(string $url, array $headers = []): void;
19+
}

src/Websocket/ConnectionInterface.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Websocket;
4+
5+
interface ConnectionInterface
6+
{
7+
/**
8+
* Send message to this connection
9+
*
10+
* @param string $command
11+
* @param mixed $data
12+
* @return void
13+
*/
14+
public function send(string $command, mixed $data): void;
15+
16+
/**
17+
* Close this connection
18+
*
19+
* @return void
20+
*/
21+
public function close(): void;
22+
23+
/**
24+
* Gets the connection unique identifier
25+
*
26+
* @return int
27+
*/
28+
public function getIdentifier(): int;
29+
}

src/Websocket/FrameInterface.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Websocket;
4+
5+
use Swoole\WebSocket\Frame;
6+
7+
interface FrameInterface
8+
{
9+
/**
10+
* Returns Swoole frame object
11+
*
12+
* @return Frame
13+
*/
14+
public function getFrame(): Frame;
15+
16+
/**
17+
* Returns json-decoded message array
18+
*
19+
* @return array
20+
*/
21+
public function getMessage(): array;
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace RTC\Contracts\Websocket;
4+
5+
use Swoole\Http\Server;
6+
use Swoole\WebSocket\Frame;
7+
8+
interface WebsocketHandlerInterface
9+
{
10+
public function handle(ConnectionInterface $connection, FrameInterface $frame): void;
11+
}

0 commit comments

Comments
 (0)