1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the "php-ipfs" package. |
7
|
|
|
* |
8
|
|
|
* (c) Robert Schönthal <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace IPFS\Api; |
15
|
|
|
|
16
|
|
|
use IPFS\Annotation\Api as Endpoint; |
17
|
|
|
use IPFS\Command\Command; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Robert Schönthal <[email protected]> |
21
|
|
|
* @autogenerated |
22
|
|
|
* @codeCoverageIgnore |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
final class Pubsub implements Api |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* List subscribed topics by name. |
28
|
|
|
* |
29
|
|
|
* @Endpoint(name="pubsub:ls") |
30
|
|
|
* |
31
|
|
|
* @return Command |
32
|
|
|
*/ |
33
|
|
|
public function ls(): Command |
34
|
|
|
{ |
35
|
|
|
return new Command(__METHOD__, get_defined_vars()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* List peers we are currently pubsubbing with. |
40
|
|
|
* |
41
|
|
|
* @Endpoint(name="pubsub:peers") |
42
|
|
|
* |
43
|
|
|
* @param string $arg topic to list connected peers of Required: no |
44
|
|
|
* |
45
|
|
|
* @return Command |
46
|
|
|
*/ |
47
|
|
|
public function peers(string $arg = null): Command |
48
|
|
|
{ |
49
|
|
|
return new Command(__METHOD__, get_defined_vars()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Publish a message to a given pubsub topic. |
54
|
|
|
* |
55
|
|
|
* @Endpoint(name="pubsub:pub") |
56
|
|
|
* |
57
|
|
|
* @param string $arg topic to publish to |
58
|
|
|
* @param string $arg1 payload of message to publish |
59
|
|
|
* |
60
|
|
|
* @return Command |
61
|
|
|
*/ |
62
|
|
|
public function pub(string $arg, string $arg1): Command |
63
|
|
|
{ |
64
|
|
|
return new Command(__METHOD__, get_defined_vars()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Subscribe to messages on a given topic. |
69
|
|
|
* |
70
|
|
|
* @Endpoint(name="pubsub:sub") |
71
|
|
|
* |
72
|
|
|
* @param string $arg string name of topic to subscribe to |
73
|
|
|
* @param bool $discover try to discover other peers subscribed to the same topic |
74
|
|
|
* |
75
|
|
|
* @return Command |
76
|
|
|
*/ |
77
|
|
|
public function sub(string $arg, bool $discover = null): Command |
78
|
|
|
{ |
79
|
|
|
return new Command(__METHOD__, get_defined_vars()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.