Skip to content

Commit 2dd19cf

Browse files
committed
Added Client
1 parent ca7987a commit 2dd19cf

File tree

7 files changed

+63
-34
lines changed

7 files changed

+63
-34
lines changed

.php_cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?php
22

33
$header = <<<'EOF'
4-
This file is part of Hyperf.
4+
This file is part of Simps.
55
6-
@link https://www.hyperf.io
7-
@document https://hyperf.wiki
8-
9-
@license https://github.com/hyperf/hyperf/blob/master/LICENSE
6+
@link https://simps.io
7+
@document https://doc.simps.io
8+
@license https://github.com/simple-swoole/simps/blob/master/LICENSE
109
EOF;
1110

1211
return PhpCsFixer\Config::create()
@@ -83,7 +82,9 @@ return PhpCsFixer\Config::create()
8382
])
8483
->setFinder(
8584
PhpCsFixer\Finder::create()
85+
->exclude('public')
86+
->exclude('runtime')
8687
->exclude('vendor')
8788
->in(__DIR__)
8889
)
89-
->setUsingCache(false);
90+
->setUsingCache(false);

src/Client.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Simps.
6+
*
7+
* @link https://simps.io
8+
* @document https://doc.simps.io
9+
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
10+
*/
11+
namespace Simps\RpcMultiplex;
12+
13+
use Multiplex\Socket;
14+
use Simps\Singleton;
15+
16+
class Client extends Socket\Client
17+
{
18+
use Singleton;
19+
20+
public function __construct(string $name, int $port)
21+
{
22+
parent::__construct($name, $port);
23+
}
24+
25+
public function call(string $class, string $method, ...$params): Protocol
26+
{
27+
$protocol = new Protocol($class, $method, $params);
28+
29+
return unserialize(parent::request(serialize($protocol)));
30+
}
31+
}

src/Protocol.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
declare(strict_types=1);
44
/**
5-
* This file is part of Hyperf.
5+
* This file is part of Simps.
66
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact [email protected]
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
7+
* @link https://simps.io
8+
* @document https://doc.simps.io
9+
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1110
*/
1211
namespace Simps\RpcMultiplex;
1312

src/TcpServer.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
declare(strict_types=1);
44
/**
5-
* This file is part of Hyperf.
5+
* This file is part of Simps.
66
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact [email protected]
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
7+
* @link https://simps.io
8+
* @document https://doc.simps.io
9+
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1110
*/
1211
namespace Simps\RpcMultiplex;
1312

@@ -22,6 +21,8 @@
2221

2322
class TcpServer
2423
{
24+
public static $incr = 0;
25+
2526
/**
2627
* @var Server
2728
*/
@@ -67,7 +68,7 @@ public function __construct()
6768
$this->_server->on('workerStart', [$this, 'onWorkerStart']);
6869
$this->_server->on('receive', [$this, 'onReceive']);
6970

70-
foreach ($wsConfig['callbacks'] as $eventKey => $callbackItem) {
71+
foreach ($wsConfig['callbacks'] ?? [] as $eventKey => $callbackItem) {
7172
[$class, $func] = $callbackItem;
7273
$this->_server->on($eventKey, [$class, $func]);
7374
}
@@ -112,8 +113,8 @@ public function onReceive(Server $server, int $fd, int $fromId, string $data)
112113
$class = $protocol->getClass();
113114
$method = $protocol->getMethod();
114115
$params = $protocol->getParams();
115-
$protocol->setResult((new $class())->{$method}(...$params));
116-
$result = serialize($protocol);
116+
117+
$result = serialize($protocol->setResult((new $class())->{$method}(...$params)));
117118
} catch (\Throwable $exception) {
118119
$result = serialize($protocol->setError($exception->getCode(), $exception->getMessage()));
119120
} finally {

tests/Cases/AbstractTestCase.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
declare(strict_types=1);
44
/**
5-
* This file is part of Hyperf.
5+
* This file is part of Simps.
66
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact [email protected]
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
7+
* @link https://simps.io
8+
* @document https://doc.simps.io
9+
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1110
*/
1211
namespace HyperfTest\Cases;
1312

tests/Cases/ExampleTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
declare(strict_types=1);
44
/**
5-
* This file is part of Hyperf.
5+
* This file is part of Simps.
66
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact [email protected]
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
7+
* @link https://simps.io
8+
* @document https://doc.simps.io
9+
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1110
*/
1211
namespace HyperfTest\Cases;
1312

tests/bootstrap.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
declare(strict_types=1);
44
/**
5-
* This file is part of Hyperf.
5+
* This file is part of Simps.
66
*
7-
* @link https://www.hyperf.io
8-
* @document https://hyperf.wiki
9-
* @contact [email protected]
10-
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
7+
* @link https://simps.io
8+
* @document https://doc.simps.io
9+
* @license https://github.com/simple-swoole/simps/blob/master/LICENSE
1110
*/
1211
require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';

0 commit comments

Comments
 (0)