@@ -23,32 +23,37 @@ public function __construct($uri, LoopInterface $loop, array $context = array())
2323 'unix ' => array (),
2424 );
2525
26+ $ server = $ this ->getServer ($ uri , $ loop , $ context );
27+ $ this ->server = $ server ;
28+
29+ $ that = $ this ;
30+ $ server ->on ('connection ' , function (ConnectionInterface $ conn ) use ($ that ) {
31+ $ that ->emit ('connection ' , array ($ conn ));
32+ });
33+ $ server ->on ('error ' , function (\Exception $ error ) use ($ that ) {
34+ $ that ->emit ('error ' , array ($ error ));
35+ });
36+ }
37+
38+ private function getServer ($ uri , $ loop , $ context ) {
2639 $ scheme = 'tcp ' ;
2740 $ pos = strpos ($ uri , ':// ' );
2841 if ($ pos !== false ) {
2942 $ scheme = substr ($ uri , 0 , $ pos );
3043 }
3144
3245 if ($ scheme === 'unix ' ) {
33- $ server = new UnixServer ($ uri , $ loop , $ context ['unix ' ]);
46+ return new UnixServer ($ uri , $ loop , $ context ['unix ' ]);
3447 }
35- else {
36- $ server = new TcpServer (str_replace ('tls:// ' , '' , $ uri ), $ loop , $ context ['tcp ' ]);
3748
38- if ($ scheme === 'tls ' ) {
39- $ server = new SecureServer ($ server , $ loop , $ context ['tls ' ]);
40- }
49+ $ server = new TcpServer (str_replace ('tls:// ' , '' , $ uri ), $ loop , $ context ['tcp ' ]);
50+
51+ if ($ scheme === 'tls ' ) {
52+ $ server = new SecureServer ($ server , $ loop , $ context ['tls ' ]);
4153 }
4254
43- $ this -> server = $ server ;
55+ return $ server ;
4456
45- $ that = $ this ;
46- $ server ->on ('connection ' , function (ConnectionInterface $ conn ) use ($ that ) {
47- $ that ->emit ('connection ' , array ($ conn ));
48- });
49- $ server ->on ('error ' , function (\Exception $ error ) use ($ that ) {
50- $ that ->emit ('error ' , array ($ error ));
51- });
5257 }
5358
5459 public function getAddress ()
0 commit comments