@@ -24,19 +24,19 @@ public function __construct(LoopInterface $loop, ConnectorInterface $connector =
2424 $ this ->connector = $ connector ;
2525 }
2626
27- public function createClient ($ address = null )
27+ public function createClient ($ url )
2828 {
29- try {
30- $ parts = $ this ->parseUrl ($ address );
31- } catch (\Exception $ e ) {
32- return Promise \reject ($ e );
29+ $ parts = parse_url ((strpos ($ url , ':// ' ) === false ? 'tcp:// ' : '' ) . $ url );
30+ if (!$ parts || !isset ($ parts ['scheme ' ], $ parts ['host ' ])) {
31+ return Promise \reject (new InvalidArgumentException ('Given URL " ' . $ url . '" can not be parsed ' ));
3332 }
3433
35- if (isset ($ parts ['scheme ' ]) && $ parts ['scheme ' ] !== 'tcp ' ) {
36- $ parts ['host ' ] = 'tls:// ' . $ parts ['host ' ];
34+ // use default port 5038
35+ if (!isset ($ parts ['port ' ])) {
36+ $ parts ['port ' ] = 5038 ;
3737 }
3838
39- $ promise = $ this ->connector ->connect ($ parts ['host ' ] . ': ' . $ parts ['port ' ])->then (function (ConnectionInterface $ stream ) {
39+ $ promise = $ this ->connector ->connect ($ parts ['scheme ' ] . ' :// ' . $ parts [ ' host ' ] . ': ' . $ parts ['port ' ])->then (function (ConnectionInterface $ stream ) {
4040 return new Client ($ stream );
4141 });
4242
@@ -58,25 +58,4 @@ function ($error) use ($client) {
5858
5959 return $ promise ;
6060 }
61-
62- private function parseUrl ($ target )
63- {
64- if ($ target === null ) {
65- $ target = 'tcp://127.0.0.1 ' ;
66- }
67- if (strpos ($ target , ':// ' ) === false ) {
68- $ target = 'tcp:// ' . $ target ;
69- }
70-
71- $ parts = parse_url ($ target );
72- if ($ parts === false || !isset ($ parts ['host ' ])) {
73- throw new InvalidArgumentException ('Given URL can not be parsed ' );
74- }
75-
76- if (!isset ($ parts ['port ' ])) {
77- $ parts ['port ' ] = '5038 ' ;
78- }
79-
80- return $ parts ;
81- }
8261}
0 commit comments