1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tidal/WampWatch package. |
5
|
|
|
* (c) 2016 Timo Michna <timomichna/yahoo.de> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tidal\WampWatch; |
13
|
|
|
|
14
|
|
|
use Tidal\WampWatch\ClientSessionInterface as ClientSession; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Tidal\WampWatch\RegistrationMonitor. |
18
|
|
|
*/ |
19
|
|
|
class RegistrationMonitor |
20
|
|
|
{ |
21
|
|
|
use MonitorTrait; |
22
|
|
|
|
23
|
|
|
const REGISTRATION_CREATE_TOPIC = 'wamp.registration.on_create'; |
24
|
|
|
const REGISTRATION_REG_TOPIC = 'wamp.registration.on_register'; |
25
|
|
|
const REGISTRATION_UNREG_TOPIC = 'wamp.registration.on_unregister'; |
26
|
|
|
const REGISTRATION_DELETE_TOPIC = 'wamp.registration.on_delete'; |
27
|
|
|
const REGISTRATION_LIST_TOPIC = 'wamp.registration.list'; |
28
|
|
|
const REGISTRATION_LOOKUP_TOPIC = 'wamp.registration.lookup'; |
29
|
|
|
const REGISTRATION_MATCH_TOPIC = 'wamp.registration.match'; |
30
|
|
|
const REGISTRATION_GET_TOPIC = 'wamp.registration.get'; |
31
|
|
|
const REGISTRATION_REGLIST_TOPIC = 'wamp.registration.list_callees'; |
32
|
|
|
const REGISTRATION_REGCOUNT_TOPIC = 'wamp.registration.count_callees'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var \stdClass Objects withs lists of subscriptions (exact, prefix, wildcard) |
36
|
|
|
*/ |
37
|
|
|
protected $registrationIds = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Constructor. |
41
|
|
|
* |
42
|
|
|
* @param ClientSession $session |
43
|
|
|
*/ |
44
|
|
|
public function __construct(ClientSession $session) |
45
|
|
|
{ |
46
|
|
|
$this->setClientSession($session); |
47
|
|
|
$this->initSetupCalls(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Initializes the subscription to the meta-events. |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
protected function initSetupCalls() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
// @var \Tidal\WampWatch\Subscription\Collection |
56
|
|
|
$collection = $this->getMetaSubscriptionCollection(); |
57
|
|
|
|
58
|
|
|
$collection->addSubscription(self::REGISTRATION_CREATE_TOPIC, $this->getSubscriptionHandler('create')); |
59
|
|
|
$collection->addSubscription(self::REGISTRATION_DELETE_TOPIC, $this->getSubscriptionHandler('delete')); |
60
|
|
|
$collection->addSubscription(self::REGISTRATION_REG_TOPIC, $this->getSubscriptionHandler('register')); |
61
|
|
|
$collection->addSubscription(self::REGISTRATION_UNREG_TOPIC, $this->getSubscriptionHandler('unregister')); |
62
|
|
|
|
63
|
|
|
$this->setInitialCall(self::REGISTRATION_LIST_TOPIC, $this->getSubscriptionIdRetrievalCallback()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function setList($list) |
67
|
|
|
{ |
68
|
|
|
$this->registrationIds = $list; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function getList() |
72
|
|
|
{ |
73
|
|
|
return $this->registrationIds; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.