Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PacketManager | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| handle | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Message\Socket |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Message\Socket; |
| 16 | |
| 17 | use phpOMS\Dispatcher\Dispatcher; |
| 18 | use phpOMS\Router\RouteVerb; |
| 19 | use phpOMS\Router\SocketRouter; |
| 20 | |
| 21 | /** |
| 22 | * Server class. |
| 23 | * |
| 24 | * Parsing/serializing arrays to and from php file |
| 25 | * |
| 26 | * @package phpOMS\Message\Socket |
| 27 | * @license OMS License 2.0 |
| 28 | * @link https://jingga.app |
| 29 | * @since 1.0.0 |
| 30 | */ |
| 31 | class PacketManager |
| 32 | { |
| 33 | /** |
| 34 | * Socket router. |
| 35 | * |
| 36 | * @var SocketRouter |
| 37 | * @since 1.0.0 |
| 38 | */ |
| 39 | private SocketRouter $router; |
| 40 | |
| 41 | /** |
| 42 | * Dispatcher. |
| 43 | * |
| 44 | * @var Dispatcher |
| 45 | * @since 1.0.0 |
| 46 | */ |
| 47 | private Dispatcher $dispatcher; |
| 48 | |
| 49 | /** |
| 50 | * Constructor. |
| 51 | * |
| 52 | * @param SocketRouter $router Socket router |
| 53 | * @param Dispatcher $dispatcher Dispatcher |
| 54 | * |
| 55 | * @since 1.0.0 |
| 56 | */ |
| 57 | public function __construct(SocketRouter $router, Dispatcher $dispatcher) |
| 58 | { |
| 59 | $this->router = $router; |
| 60 | $this->dispatcher = $dispatcher; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Handle package. |
| 65 | * |
| 66 | * @param string $data Package data |
| 67 | * |
| 68 | * @return void |
| 69 | * |
| 70 | * @since 1.0.0 |
| 71 | */ |
| 72 | public function handle(string $data, $client) : void |
| 73 | { |
| 74 | $request = new SocketRequest(); |
| 75 | $request->header->account = $client->getAccount()->getId(); |
| 76 | |
| 77 | $response = new SocketResponse(); |
| 78 | |
| 79 | $this->dispatcher->dispatch( |
| 80 | $this->router->route($data, null, RouteVerb::ANY, 2, 1, $client->getAccount()), |
| 81 | $request, |
| 82 | $response |
| 83 | ); |
| 84 | } |
| 85 | } |