File tree Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Expand file tree Collapse file tree 5 files changed +36
-8
lines changed Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ will not have to wait for an actual underlying connection.
107
107
108
108
#### __ construct()
109
109
110
- The ` new MysqlClient(string $uri, ConnectorInterface $connector = null, LoopInterface $loop = null) ` constructor can be used to
110
+ The ` new MysqlClient(string $uri, ? ConnectorInterface $connector = null, ? LoopInterface $loop = null) ` constructor can be used to
111
111
create a new ` MysqlClient ` instance.
112
112
113
113
The ` $uri ` parameter must contain the database host, optional
Original file line number Diff line number Diff line change 7
7
"php" : " >=5.4.0" ,
8
8
"evenement/evenement" : " ^3.0 || ^2.1 || ^1.1" ,
9
9
"react/event-loop" : " ^1.2" ,
10
- "react/promise" : " ^3 || ^2.7" ,
10
+ "react/promise" : " ^3.2 || ^2.7" ,
11
11
"react/promise-stream" : " ^1.6" ,
12
- "react/promise-timer" : " ^1.9 " ,
13
- "react/socket" : " ^1.12 "
12
+ "react/promise-timer" : " ^1.11 " ,
13
+ "react/socket" : " ^1.16 "
14
14
},
15
15
"require-dev" : {
16
16
"phpunit/phpunit" : " ^9.6 || ^5.7 || ^4.8.36" ,
17
- "react/async" : " ^4 || ^3 || ^2"
17
+ "react/async" : " ^4.3 || ^3 || ^2"
18
18
},
19
19
"autoload" : {
20
20
"psr-4" : {
Original file line number Diff line number Diff line change @@ -60,8 +60,12 @@ class Factory
60
60
* @param ?LoopInterface $loop
61
61
* @param ?ConnectorInterface $connector
62
62
*/
63
- public function __construct (LoopInterface $ loop = null , ConnectorInterface $ connector = null )
63
+ public function __construct ($ loop = null , $ connector = null )
64
64
{
65
+ // manual type check to support legacy PHP < 7.1
66
+ assert ($ loop === null || $ loop instanceof LoopInterface);
67
+ assert ($ connector === null || $ connector instanceof ConnectorInterface);
68
+
65
69
$ this ->loop = $ loop ?: Loop::get ();
66
70
$ this ->connector = $ connector ?: new Connector ([], $ this ->loop );
67
71
}
Original file line number Diff line number Diff line change @@ -76,12 +76,24 @@ class MysqlClient extends EventEmitter
76
76
*/
77
77
private $ quitting = false ;
78
78
79
+ /**
80
+ * @param string $uri
81
+ * @param ?ConnectorInterface $connector
82
+ * @param ?LoopInterface $loop
83
+ */
79
84
public function __construct (
80
85
#[\SensitiveParameter]
81
86
$ uri ,
82
- ConnectorInterface $ connector = null ,
83
- LoopInterface $ loop = null
87
+ $ connector = null ,
88
+ $ loop = null
84
89
) {
90
+ if ($ connector !== null && !$ connector instanceof ConnectorInterface) { // manual type check to support legacy PHP < 7.1
91
+ throw new \InvalidArgumentException ('Argument #2 ($connector) expected null|React\Socket\ConnectorInterface ' );
92
+ }
93
+ if ($ loop !== null && !$ loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
94
+ throw new \InvalidArgumentException ('Argument #3 ($loop) expected null|React\EventLoop\LoopInterface ' );
95
+ }
96
+
85
97
$ this ->factory = new Factory ($ loop , $ connector );
86
98
$ this ->uri = $ uri ;
87
99
}
Original file line number Diff line number Diff line change @@ -56,6 +56,18 @@ public function testConstructWithConnectorAndLoopAssignsGivenConnectorAndLoop()
56
56
$ this ->assertSame ($ loop , $ ref ->getValue ($ factory ));
57
57
}
58
58
59
+ public function testContructorThrowsExceptionForInvalidConnector ()
60
+ {
61
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #2 ($connector) expected null|React\Socket\ConnectorInterface ' );
62
+ new MysqlClient ('localhost ' , 'connector ' );
63
+ }
64
+
65
+ public function testContructorThrowsExceptionForInvalidLoop ()
66
+ {
67
+ $ this ->setExpectedException ('InvalidArgumentException ' , 'Argument #3 ($loop) expected null|React\EventLoop\LoopInterface ' );
68
+ new MysqlClient ('localhost ' , null , 'loop ' );
69
+ }
70
+
59
71
public function testPingWillNotCloseConnectionWhenPendingConnectionFails ()
60
72
{
61
73
$ deferred = new Deferred ();
You can’t perform that action at this time.
0 commit comments