kanata-php /
socket-conveyor
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Conveyor\SocketHandlers; |
||
| 4 | |||
| 5 | use Exception; |
||
| 6 | use League\Pipeline\Pipeline; |
||
| 7 | use Conveyor\Exceptions\InvalidActionException; |
||
| 8 | use Conveyor\Actions\Interfaces\ActionInterface; |
||
| 9 | use Conveyor\SocketHandlers\Abstractions\SocketHandler; |
||
| 10 | use Conveyor\SocketHandlers\Traits\HasPipeline; |
||
| 11 | |||
| 12 | class SocketMessageRouter extends SocketHandler |
||
| 13 | { |
||
| 14 | use HasPipeline; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Call this method to get singleton |
||
| 18 | * |
||
| 19 | * @return SocketMessageRouter |
||
| 20 | */ |
||
| 21 | public static function getInstance(): SocketMessageRouter |
||
| 22 | { |
||
| 23 | static $instance = null; |
||
| 24 | |||
| 25 | if ($instance === null) { |
||
| 26 | $instance = new self; |
||
| 27 | } |
||
| 28 | |||
| 29 | return $instance; |
||
| 30 | } |
||
| 31 | |||
| 32 | private function __construct() |
||
| 33 | { |
||
| 34 | |||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @internal This method also leave the $parsedData property set to the instance. |
||
| 39 | * |
||
| 40 | * @param string $data |
||
| 41 | * @return ActionInterface |
||
| 42 | * |
||
| 43 | * @throws InvalidArgumentException|InvalidActionException |
||
| 44 | */ |
||
| 45 | public function parseData(string $data) : ActionInterface |
||
| 46 | { |
||
| 47 | $this->parsedData = json_decode($data, true); |
||
| 48 | |||
| 49 | // @throws InvalidArgumentException|InvalidActionException |
||
| 50 | $this->validateData($this->parsedData); |
||
| 51 | |||
| 52 | return $this->getAction($this->parsedData['action']); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 53 | } |
||
| 54 | } |
||
| 55 |