88
99namespace PocketIO ;
1010
11- use Psr \Log \NullLogger ;
12- use Psr \Log \LoggerInterface ;
1311use PocketIO \Exception \SocketException ;
1412
1513/**
@@ -21,19 +19,14 @@ class Client
2119 /** @var EngineInterface */
2220 private EngineInterface $ engine ;
2321
24- /** @var LoggerInterface */
25- private $ logger ;
26-
2722 private bool $ isConnected = false ;
2823
2924 /**
3025 * @param EngineInterface $engine
31- * @param LoggerInterface|null $logger
3226 */
33- public function __construct (EngineInterface $ engine, LoggerInterface $ logger = null )
27+ public function __construct (EngineInterface $ engine )
3428 {
3529 $ this ->engine = $ engine ;
36- $ this ->logger = $ logger ?: new NullLogger ;
3730 }
3831
3932 public function __destruct ()
@@ -49,21 +42,13 @@ public function __destruct()
4942 * Connects to the websocket
5043 *
5144 * @return $this
45+ * @throws SocketException
5246 */
5347 public function initialize (): Client
5448 {
55- try {
56- $ this ->logger ->debug ('Connecting to the websocket ' );
57- $ this ->engine ->connect ();
58- $ this ->logger ->debug ('Connected to the server ' );
59-
60- $ this ->isConnected = true ;
61- } catch (SocketException $ e ) {
62- $ this ->logger ->error ('Could not connect to the server ' , ['exception ' => $ e ]);
63-
64- throw $ e ;
65- }
6649
50+ $ this ->engine ->connect ();
51+ $ this ->isConnected = true ;
6752 return $ this ;
6853 }
6954
@@ -74,7 +59,6 @@ public function initialize(): Client
7459 */
7560 public function read (): string
7661 {
77- $ this ->logger ->debug ('Reading a new message from the socket ' );
7862 return $ this ->engine ->read ();
7963 }
8064
@@ -88,7 +72,6 @@ public function read(): string
8872 */
8973 public function emit (string $ event , array $ args ): Client
9074 {
91- $ this ->logger ->debug ('Sending a new message ' , ['event ' => $ event , 'args ' => $ args ]);
9275 $ this ->engine ->emit ($ event , $ args );
9376
9477 return $ this ;
@@ -102,7 +85,6 @@ public function emit(string $event, array $args): Client
10285 */
10386 public function of ($ namespace ): Client
10487 {
105- $ this ->logger ->debug ('Setting the namespace ' , ['namespace ' => $ namespace ]);
10688 $ this ->engine ->of ($ namespace );
10789
10890 return $ this ;
@@ -115,7 +97,6 @@ public function of($namespace): Client
11597 */
11698 public function close (): Client
11799 {
118- $ this ->logger ->debug ('Closing the connection to the websocket ' );
119100 $ this ->engine ->close ();
120101
121102 $ this ->isConnected = false ;
0 commit comments