1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 Fabian Grutschus. All rights reserved. |
5
|
|
|
* |
6
|
|
|
* Redistribution and use in source and binary forms, with or without modification, |
7
|
|
|
* are permitted provided that the following conditions are met: |
8
|
|
|
* |
9
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this |
10
|
|
|
* list of conditions and the following disclaimer. |
11
|
|
|
* |
12
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, |
13
|
|
|
* this list of conditions and the following disclaimer in the documentation |
14
|
|
|
* and/or other materials provided with the distribution. |
15
|
|
|
* |
16
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
20
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26
|
|
|
* |
27
|
|
|
* The views and conclusions contained in the software and documentation are those |
28
|
|
|
* of the authors and should not be interpreted as representing official policies, |
29
|
|
|
* either expressed or implied, of the copyright holders. |
30
|
|
|
* |
31
|
|
|
* @author Fabian Grutschus <[email protected]> |
32
|
|
|
* @copyright 2014 Fabian Grutschus. All rights reserved. |
33
|
|
|
* @license BSD |
34
|
|
|
* @link http://github.com/fabiang/xmpp |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
namespace Fabiang\Xmpp\Protocol; |
38
|
|
|
|
39
|
|
|
use Fabiang\Xmpp\Options; |
40
|
|
|
use Fabiang\Xmpp\EventListener\EventListenerInterface; |
41
|
|
|
use Fabiang\Xmpp\Event\EventManagerInterface; |
42
|
|
|
use Fabiang\Xmpp\Event\EventManager; |
43
|
|
|
use Fabiang\Xmpp\EventListener\Stream\Stream; |
44
|
|
|
use Fabiang\Xmpp\EventListener\Stream\StreamError; |
45
|
|
|
use Fabiang\Xmpp\EventListener\Stream\StartTls; |
46
|
|
|
use Fabiang\Xmpp\EventListener\Stream\Authentication; |
47
|
|
|
use Fabiang\Xmpp\EventListener\Stream\Bind; |
48
|
|
|
use Fabiang\Xmpp\EventListener\Stream\Session; |
49
|
|
|
use Fabiang\Xmpp\EventListener\Stream\Roster as RosterListener; |
50
|
|
|
use Fabiang\Xmpp\EventListener\Stream\Register as RegisterListener; |
51
|
|
|
use Fabiang\Xmpp\EventListener\Stream\BlockedUsers as BlockedUsersListener; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Default Protocol implementation. |
55
|
|
|
* |
56
|
|
|
* @package Xmpp\Protocol |
57
|
|
|
*/ |
58
|
|
|
class DefaultImplementation implements ImplementationInterface |
59
|
|
|
{ |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Options. |
63
|
|
|
* |
64
|
|
|
* @var Options |
65
|
|
|
*/ |
66
|
|
|
protected $options; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Eventmanager. |
70
|
|
|
* |
71
|
|
|
* @var EventManagerInterface |
72
|
|
|
*/ |
73
|
|
|
protected $events; |
74
|
|
|
|
75
|
|
|
/** |
76
|
3 |
|
* {@inheritDoc} |
77
|
|
|
*/ |
78
|
3 |
|
public function register() |
79
|
3 |
|
{ |
80
|
3 |
|
$this->registerListener(new Stream); |
81
|
3 |
|
$this->registerListener(new StreamError); |
82
|
3 |
|
$this->registerListener(new StartTls); |
83
|
3 |
|
$this->registerListener(new Authentication); |
84
|
3 |
|
$this->registerListener(new Bind); |
85
|
3 |
|
$this->registerListener(new Session); |
86
|
|
|
$this->registerListener(new RosterListener); |
87
|
|
|
$this->registerListener(new RegisterListener); |
88
|
|
|
$this->registerListener(new BlockedUsersListener); |
89
|
|
|
} |
90
|
3 |
|
|
91
|
|
|
/** |
92
|
3 |
|
* {@inheritDoc} |
93
|
|
|
*/ |
94
|
3 |
|
public function registerListener(EventListenerInterface $eventListener) |
95
|
3 |
|
{ |
96
|
3 |
|
$connection = $this->getOptions()->getConnection(); |
97
|
|
|
|
98
|
3 |
|
$eventListener->setEventManager($this->getEventManager()) |
99
|
3 |
|
->setOptions($this->getOptions()) |
100
|
|
|
->attachEvents(); |
101
|
|
|
|
102
|
|
|
$connection->addListener($eventListener); |
103
|
|
|
} |
104
|
3 |
|
|
105
|
|
|
/** |
106
|
3 |
|
* {@inheritDoc} |
107
|
|
|
*/ |
108
|
|
|
public function getOptions() |
109
|
|
|
{ |
110
|
|
|
return $this->options; |
111
|
|
|
} |
112
|
3 |
|
|
113
|
|
|
/** |
114
|
3 |
|
* {@inheritDoc} |
115
|
3 |
|
*/ |
116
|
|
|
public function setOptions(Options $options) |
117
|
|
|
{ |
118
|
|
|
$this->options = $options; |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
3 |
|
|
122
|
|
|
/** |
123
|
3 |
|
* {@inheritDoc} |
124
|
3 |
|
*/ |
125
|
3 |
|
public function getEventManager() |
126
|
|
|
{ |
127
|
3 |
|
if (null === $this->events) { |
128
|
|
|
$this->setEventManager(new EventManager()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return $this->events; |
132
|
|
|
} |
133
|
3 |
|
|
134
|
|
|
/** |
135
|
3 |
|
* {@inheritDoc} |
136
|
3 |
|
*/ |
137
|
|
|
public function setEventManager(EventManagerInterface $events) |
138
|
|
|
{ |
139
|
|
|
$this->events = $events; |
140
|
|
|
return $this; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|