|
@@ -89,7 +89,7 @@ discard block |
|
|
block discarded – undo |
|
89
|
89
|
$this->buildMessageProcessor(); |
|
90
|
90
|
|
|
91
|
91
|
// Some optimization |
|
92
|
|
- \gc_enable(); // As the process never stops, the garbage collector will be usefull, you may need to call it manually sometimes for performance purpose |
|
|
92
|
+ \gc_enable(); // As the process never stops, the garbage collector will be usefull, you may need to call it manually sometimes for performance purpose |
|
93
|
93
|
\set_time_limit(0); // It's by default on most server for cli apps but better be sure of that fact |
|
94
|
94
|
} |
|
95
|
95
|
|
|
@@ -99,13 +99,13 @@ discard block |
|
|
block discarded – undo |
|
99
|
99
|
*/ |
|
100
|
100
|
public function setMessageHandler($messageHandler, $uri = '*') |
|
101
|
101
|
{ |
|
102
|
|
- if (!$messageHandler instanceof MessageHandlerInterface && !\is_string($messageHandler)) { |
|
|
102
|
+ if (!$messageHandler instanceof MessageHandlerInterface && !\is_string($messageHandler)) { |
|
103
|
103
|
throw new \InvalidArgumentException('The message handler must be an instance of MessageHandlerInterface or a string.'); |
|
104
|
104
|
} |
|
105
|
105
|
if (\is_string($messageHandler)) { |
|
106
|
106
|
try { |
|
107
|
107
|
$reflection = new \ReflectionClass($messageHandler); |
|
108
|
|
- if(!$reflection->implementsInterface('Nekland\Woketo\Message\MessageHandlerInterface')) { |
|
|
108
|
+ if (!$reflection->implementsInterface('Nekland\Woketo\Message\MessageHandlerInterface')) { |
|
109
|
109
|
throw new \InvalidArgumentException('The messageHandler must implement MessageHandlerInterface'); |
|
110
|
110
|
} |
|
111
|
111
|
} catch (\ReflectionException $e) { |
|
@@ -124,7 +124,7 @@ discard block |
|
|
block discarded – undo |
|
124
|
124
|
$this->loop = \React\EventLoop\Factory::create(); |
|
125
|
125
|
|
|
126
|
126
|
$socket = new \React\Socket\Server($this->loop); |
|
127
|
|
- $socket->on('connection', function ($socketStream) { |
|
|
127
|
+ $socket->on('connection', function($socketStream) { |
|
128
|
128
|
$this->onNewConnection($socketStream); |
|
129
|
129
|
}); |
|
130
|
130
|
$socket->listen($this->port); |
|
@@ -139,7 +139,7 @@ discard block |
|
|
block discarded – undo |
|
139
|
139
|
*/ |
|
140
|
140
|
private function onNewConnection(ConnectionInterface $socketStream) |
|
141
|
141
|
{ |
|
142
|
|
- $connection = new Connection($socketStream, function ($uri, Connection $connection) { |
|
|
142
|
+ $connection = new Connection($socketStream, function($uri, Connection $connection) { |
|
143
|
143
|
return $this->getMessageHandler($uri, $connection); |
|
144
|
144
|
}, $this->loop, $this->messageProcessor); |
|
145
|
145
|
|