FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
jet/src/AbstractClient.php at master · hyperf/jet · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
hyperf
/
jet
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
7
Star
61
Code
Issues
1
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
jet
/
src
/
AbstractClient.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
71 lines (57 loc) · 2.12 KB
Breadcrumbs
jet
/
src
/
AbstractClient.php
Copy path
File metadata and controls
71 lines (57 loc) · 2.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare
(strict_types=
1
);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace
Hyperf
\
Jet
;
use
Hyperf
\
Jet
\
DataFormatter
\
DataFormatter
;
use
Hyperf
\
Jet
\
Exception
\
RecvFailedException
;
use
Hyperf
\
Jet
\
Exception
\
ServerException
;
use
Hyperf
\
Jet
\
PathGenerator
\
PathGenerator
;
use
Hyperf
\
Rpc
\
Contract
\
DataFormatterInterface
;
use
Hyperf
\
Rpc
\
Contract
\
PackerInterface
;
use
Hyperf
\
Rpc
\
Contract
\
PathGeneratorInterface
;
use
Hyperf
\
Rpc
\
Contract
\
TransporterInterface
;
use
Hyperf
\
Rpc
\
Request
;
abstract
class
AbstractClient
{
/**
* @var null|resource
*/
protected
mixed
$
client
=
null
;
protected
string
$
service
;
protected
PackerInterface
$
packer
;
protected
DataFormatterInterface
$
dataFormatter
;
protected
PathGeneratorInterface
$
pathGenerator
;
protected
TransporterInterface
$
transporter
;
public
function
__construct
(
string
$
service
,
TransporterInterface
$
transporter
,
PackerInterface
$
packer
, ?
DataFormatterInterface
$
dataFormatter
=
null
, ?
PathGeneratorInterface
$
pathGenerator
=
null
)
{
$
this
->
service
=
$
service
;
$
this
->
packer
=
$
packer
;
$
this
->
transporter
=
$
transporter
;
is_null
(
$
dataFormatter
) &&
$
dataFormatter
=
new
DataFormatter
();
$
this
->
dataFormatter
=
$
dataFormatter
;
is_null
(
$
pathGenerator
) &&
$
pathGenerator
=
new
PathGenerator
();
$
this
->
pathGenerator
=
$
pathGenerator
;
}
public
function
__call
(
$
name
,
$
arguments
)
{
$
path
=
$
this
->
pathGenerator
->
generate
(
$
this
->
service
,
$
name
);
$
data
=
$
this
->
dataFormatter
->
formatRequest
(
new
Request
(
$
path
,
$
arguments
,
uniqid
()));
$
this
->
transporter
->
send
(
$
this
->
packer
->
pack
(
$
data
));
$
ret
=
$
this
->
transporter
->
recv
();
if
(!
is_string
(
$
ret
)) {
throw
new
RecvFailedException
();
}
$
data
=
$
this
->
packer
->
unpack
(
$
ret
);
if
(
array_key_exists
(
'
result
'
,
$
data
)) {
return
$
data
[
'
result
'
];
}
throw
new
ServerException
(
$
data
[
'
error
'
] ?? []);
}
}
Back
|
FazBrowse Home
|
New Git URL