carno-php /
hrpca
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Feature marking for service discovery |
||
| 4 | * User: moyo |
||
| 5 | * Date: 2018/8/1 |
||
| 6 | * Time: 11:13 AM |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Carno\HRPC\Accel; |
||
| 10 | |||
| 11 | use Carno\Cluster\Contracts\Tags; |
||
| 12 | use Carno\HRPC\Accel\Contracts\Named; |
||
| 13 | |||
| 14 | class Marking |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @param int $port |
||
| 18 | * @return string |
||
| 19 | */ |
||
| 20 | public static function viaTCP(int $port) : string |
||
| 21 | { |
||
| 22 | return Tags::CMD . sprintf('%s:%s::%d', Named::KEY, Named::TCP, $port); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $tagging |
||
| 27 | * @return int |
||
| 28 | */ |
||
| 29 | public static function commTCP(string $tagging) : int |
||
| 30 | { |
||
| 31 | if (substr($tagging, 0, strlen(Named::KEY)) === Named::KEY) { |
||
| 32 | [1 => $proto, 3 => $port] = explode(':', $tagging); |
||
| 33 | switch ($proto) { |
||
| 34 | case Named::TCP: |
||
| 35 | return $port; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 36 | } |
||
| 37 | } |
||
| 38 | return 0; |
||
| 39 | } |
||
| 40 | } |
||
| 41 |