@@ -165,6 +165,9 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | + /** |
|
169 | + * @param string $message |
|
170 | + */ |
|
168 | 171 | public function debug($message) |
169 | 172 | { |
170 | 173 | if ($this->debug) |
@@ -426,6 +429,9 @@ discard block |
||
426 | 429 | $this->buffer .= $str; |
427 | 430 | } |
428 | 431 | |
432 | + /** |
|
433 | + * @param string $str |
|
434 | + */ |
|
429 | 435 | public function prepend($str) |
430 | 436 | { |
431 | 437 | $this->buffer = $str . substr($this->buffer, $this->bufferPos); |
@@ -448,11 +454,17 @@ discard block |
||
448 | 454 | return $buffer; |
449 | 455 | } |
450 | 456 | |
457 | + /** |
|
458 | + * @param integer $len |
|
459 | + */ |
|
451 | 460 | public function skip($len) |
452 | 461 | { |
453 | 462 | $this->bufferPos += $len; |
454 | 463 | } |
455 | 464 | |
465 | + /** |
|
466 | + * @param double $len |
|
467 | + */ |
|
456 | 468 | public function restBuffer($len) |
457 | 469 | { |
458 | 470 | if (strlen($this->buffer) === ($this->bufferPos+$len)) |
@@ -471,6 +483,9 @@ discard block |
||
471 | 483 | return strlen($this->buffer) - $this->bufferPos; |
472 | 484 | } |
473 | 485 | |
486 | + /** |
|
487 | + * @param string $what |
|
488 | + */ |
|
474 | 489 | public function search($what) |
475 | 490 | { |
476 | 491 | if (($p = strpos($this->buffer, $what, $this->bufferPos)) !== false) |
@@ -512,6 +527,9 @@ discard block |
||
512 | 527 | $this->debug('Auth packet sent'); |
513 | 528 | } |
514 | 529 | |
530 | + /** |
|
531 | + * @param string $scramble |
|
532 | + */ |
|
515 | 533 | public function getAuthToken($scramble, $password = '') |
516 | 534 | { |
517 | 535 | if ($password === '') |
@@ -526,6 +544,7 @@ discard block |
||
526 | 544 | /** |
527 | 545 | * Builds length-encoded BinSupport string |
528 | 546 | * @param string String |
547 | + * @param string $s |
|
529 | 548 | * @return string Resulting BinSupport string |
530 | 549 | */ |
531 | 550 | public function buildLenEncodedBinSupport($s) |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * @var int |
20 | 20 | */ |
21 | - const PHASE_INIT = 1; |
|
21 | + const PHASE_INIT = 1; |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @var int |
25 | 25 | */ |
26 | - const PHASE_AUTH_SENT = 2; |
|
26 | + const PHASE_AUTH_SENT = 2; |
|
27 | 27 | |
28 | 28 | /** |
29 | 29 | * @var int |
30 | 30 | */ |
31 | - const PHASE_AUTH_ERR = 3; |
|
31 | + const PHASE_AUTH_ERR = 3; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @var int |
@@ -38,17 +38,17 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @var int |
40 | 40 | */ |
41 | - const RS_STATE_HEADER = 0; |
|
41 | + const RS_STATE_HEADER = 0; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @var int |
45 | 45 | */ |
46 | - const RS_STATE_FIELD = 1; |
|
46 | + const RS_STATE_FIELD = 1; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @var int |
50 | 50 | */ |
51 | - const RS_STATE_ROW = 2; |
|
51 | + const RS_STATE_ROW = 2; |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @var int |
@@ -58,22 +58,22 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * @var int |
60 | 60 | */ |
61 | - const STATE_BODY = 1; |
|
61 | + const STATE_BODY = 1; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @var string |
65 | 65 | */ |
66 | - protected $user = 'root'; |
|
66 | + protected $user = 'root'; |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @var string |
70 | 70 | */ |
71 | - protected $pass = ''; |
|
71 | + protected $pass = ''; |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @var string |
75 | 75 | */ |
76 | - protected $dbname = ''; |
|
76 | + protected $dbname = ''; |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * @var CommandInterface |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | $this->executor = $executor; |
149 | 149 | $this->queue = new SplQueue($this); |
150 | 150 | $this->configure($config); |
151 | - $executor->on('new', [ $this, 'handleNewCommand' ]); |
|
151 | + $executor->on('new', [$this, 'handleNewCommand']); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | public function start() |
155 | 155 | { |
156 | - $this->stream->on('data', [ $this, 'handleData' ]); |
|
157 | - $this->stream->on('close', [ $this, 'handleClose' ]); |
|
156 | + $this->stream->on('data', [$this, 'handleData']); |
|
157 | + $this->stream->on('close', [$this, 'handleClose']); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | public function handleNewCommand() |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | } |
305 | 305 | else |
306 | 306 | { |
307 | - ++ $this->rsState; |
|
307 | + ++$this->rsState; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | //Data packet |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | $command = $this->queue->dequeue(); |
373 | 373 | $error = new Exception($this->errmsg, $this->errno); |
374 | 374 | $command->setError($error); |
375 | - $command->emit('error', [ $command, $error ]); |
|
375 | + $command->emit('error', [$command, $error]); |
|
376 | 376 | $this->errmsg = ''; |
377 | 377 | $this->errno = 0; |
378 | 378 | } |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | $command->resultRows = $this->resultRows; |
385 | 385 | $command->resultFields = $this->resultFields; |
386 | 386 | |
387 | - $command->emit('success', [ $command, $this->resultRows ]); |
|
387 | + $command->emit('success', [$command, $this->resultRows]); |
|
388 | 388 | |
389 | 389 | $this->rsState = self::RS_STATE_HEADER; |
390 | 390 | $this->resultRows = $this->resultFields = []; |
@@ -399,13 +399,13 @@ discard block |
||
399 | 399 | $command->warnCount = $this->warnCount; |
400 | 400 | $command->message = $this->message; |
401 | 401 | |
402 | - $command->emit('success', [ $command ]); |
|
402 | + $command->emit('success', [$command]); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | protected function onAuthenticated() |
406 | 406 | { |
407 | 407 | $command = $this->queue->dequeue(); |
408 | - $command->emit('success', [ $command, $this->connectOptions ]); |
|
408 | + $command->emit('success', [$command, $this->connectOptions]); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | protected function handleClose() |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $command = $this->queue->dequeue(); |
417 | 417 | if ($command->equals(Command::QUIT)) |
418 | 418 | { |
419 | - $command->emit('success', [ $command ]); |
|
419 | + $command->emit('success', [$command]); |
|
420 | 420 | } |
421 | 421 | } |
422 | 422 | } |
@@ -455,13 +455,13 @@ discard block |
||
455 | 455 | |
456 | 456 | public function restBuffer($len) |
457 | 457 | { |
458 | - if (strlen($this->buffer) === ($this->bufferPos+$len)) |
|
458 | + if (strlen($this->buffer) === ($this->bufferPos + $len)) |
|
459 | 459 | { |
460 | 460 | $this->buffer = ''; |
461 | 461 | } |
462 | 462 | else |
463 | 463 | { |
464 | - $this->buffer = substr($this->buffer,$this->bufferPos+$len); |
|
464 | + $this->buffer = substr($this->buffer, $this->bufferPos + $len); |
|
465 | 465 | } |
466 | 466 | $this->bufferPos = 0; |
467 | 467 | } |
@@ -89,7 +89,8 @@ |
||
89 | 89 | break; |
90 | 90 | case 'array': |
91 | 91 | $nvalue = []; |
92 | - foreach ($value as $v) { |
|
92 | + foreach ($value as $v) |
|
93 | + { |
|
93 | 94 | $nvalue[] = $this->resolveValueForSql($v); |
94 | 95 | } |
95 | 96 | $value = implode(',', $nvalue); |
@@ -141,7 +141,7 @@ |
||
141 | 141 | $params = array_values($this->params); |
142 | 142 | $size = count($params); |
143 | 143 | |
144 | - for ($i=0; $i<$size; $i++) |
|
144 | + for ($i = 0; $i < $size; $i++) |
|
145 | 145 | { |
146 | 146 | $sql = preg_replace('#' . $keys[$i] . '#', $this->resolveValueForSql($params[$i]), $sql, 1); |
147 | 147 | } |
@@ -267,7 +267,8 @@ |
||
267 | 267 | } |
268 | 268 | |
269 | 269 | public function buildPacket() |
270 | - {} |
|
270 | + { |
|
271 | +} |
|
271 | 272 | |
272 | 273 | public function getState($name, $default = null) |
273 | 274 | { |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | $query = new Query($sql, $sqlParams); |
64 | 64 | $command = new QueryCommand($this->database, $query); |
65 | 65 | |
66 | - $this->on('error', function ($trans, $err) use ($promise) { |
|
66 | + $this->on('error', function($trans, $err) use ($promise) { |
|
67 | 67 | return $promise->reject($err); |
68 | 68 | }); |
69 | - $this->on('success', function ($trans) use ($promise, $command) { |
|
69 | + $this->on('success', function($trans) use ($promise, $command) { |
|
70 | 70 | return $promise->resolve($command); |
71 | 71 | }); |
72 | 72 | |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | |
98 | 98 | $promise = new Promise(); |
99 | 99 | |
100 | - $this->on('error', function ($trans, $err) use ($promise) { |
|
100 | + $this->on('error', function($trans, $err) use ($promise) { |
|
101 | 101 | return $promise->reject($err); |
102 | 102 | }); |
103 | - $this->on('success', function ($trans) use ($promise) { |
|
103 | + $this->on('success', function($trans) use ($promise) { |
|
104 | 104 | return $promise->resolve(); |
105 | 105 | }); |
106 | 106 | |
107 | 107 | $this->open = false; |
108 | - $this->emit('commit', [ $this, $this->queue ]); |
|
108 | + $this->emit('commit', [$this, $this->queue]); |
|
109 | 109 | $this->queue = []; |
110 | 110 | |
111 | 111 | return $promise; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | $this->open = false; |
126 | - $this->emit('rollback', [ $this ]); |
|
126 | + $this->emit('rollback', [$this]); |
|
127 | 127 | $this->queue = []; |
128 | 128 | |
129 | 129 | return Promise::doResolve(); |
@@ -33,42 +33,42 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @var int |
35 | 35 | */ |
36 | - const STATE_INIT = 0; |
|
36 | + const STATE_INIT = 0; |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * @var int |
40 | 40 | */ |
41 | - const STATE_CONNECT_PENDING = 4; |
|
41 | + const STATE_CONNECT_PENDING = 4; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * @var int |
45 | 45 | */ |
46 | - const STATE_CONNECT_FAILED = 2; |
|
46 | + const STATE_CONNECT_FAILED = 2; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * @var int |
50 | 50 | */ |
51 | - const STATE_CONNECT_SUCCEEDED = 6; |
|
51 | + const STATE_CONNECT_SUCCEEDED = 6; |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @var int |
55 | 55 | */ |
56 | - const STATE_AUTH_PENDING = 5; |
|
56 | + const STATE_AUTH_PENDING = 5; |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @var int |
60 | 60 | */ |
61 | - const STATE_AUTH_FAILED = 3; |
|
61 | + const STATE_AUTH_FAILED = 3; |
|
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @var int |
65 | 65 | */ |
66 | - const STATE_AUTH_SUCCEEDED = 7; |
|
66 | + const STATE_AUTH_SUCCEEDED = 7; |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @var int |
70 | 70 | */ |
71 | - const STATE_DISCONNECT_PENDING = 8; |
|
71 | + const STATE_DISCONNECT_PENDING = 8; |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * @var int |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | $this->state = self::STATE_CONNECT_PENDING; |
180 | 180 | $config = $this->config; |
181 | 181 | |
182 | - $errorHandler = function ($command, $reason) use ($promise) { |
|
182 | + $errorHandler = function($command, $reason) use ($promise) { |
|
183 | 183 | $this->state = self::STATE_AUTH_FAILED; |
184 | 184 | return $promise->reject($reason); |
185 | 185 | }; |
186 | 186 | |
187 | - $connectedHandler = function ($command, $info) use ($promise) { |
|
187 | + $connectedHandler = function($command, $info) use ($promise) { |
|
188 | 188 | $this->state = self::STATE_AUTH_SUCCEEDED; |
189 | 189 | $this->serverInfo = $info; |
190 | 190 | return $promise->resolve($info); |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | ->then(function($stream) use ($config, $errorHandler, $connectedHandler) { |
196 | 196 | $this->stream = $stream; |
197 | 197 | |
198 | - $stream->on('error', [ $this, 'handleSocketError' ]); |
|
199 | - $stream->on('close', [ $this, 'handleSocketClose' ]); |
|
198 | + $stream->on('error', [$this, 'handleSocketError']); |
|
199 | + $stream->on('close', [$this, 'handleSocketClose']); |
|
200 | 200 | |
201 | 201 | $this->state = self::STATE_AUTH_PENDING; |
202 | 202 | $this->parser = new ProtocolParser($stream, $this->queue, $config); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | |
208 | 208 | $this->parser->start(); |
209 | 209 | }) |
210 | - ->done(null, [ $this, 'handleError' ]); |
|
210 | + ->done(null, [$this, 'handleError']); |
|
211 | 211 | |
212 | 212 | return $promise; |
213 | 213 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | ->doCommand(new QuitCommand($this)) |
228 | 228 | ->on('success', function() use($resolve) { |
229 | 229 | $this->state = self::STATE_DISCONNECT_SUCCEEDED; |
230 | - $this->emit('stop', [ $this ]); |
|
230 | + $this->emit('stop', [$this]); |
|
231 | 231 | $resolve($this); |
232 | 232 | }); |
233 | 233 | $this->state = self::STATE_DISCONNECT_PENDING; |
@@ -282,10 +282,10 @@ discard block |
||
282 | 282 | |
283 | 283 | $this->doCommand($command); |
284 | 284 | |
285 | - $command->on('error', function ($command, $err) use ($promise) { |
|
285 | + $command->on('error', function($command, $err) use ($promise) { |
|
286 | 286 | return $promise->reject($err); |
287 | 287 | }); |
288 | - $command->on('success', function ($command) use ($promise) { |
|
288 | + $command->on('success', function($command) use ($promise) { |
|
289 | 289 | return $promise->resolve($command); |
290 | 290 | }); |
291 | 291 | |
@@ -312,10 +312,10 @@ discard block |
||
312 | 312 | $promise = new Promise(); |
313 | 313 | |
314 | 314 | $command = $this->doCommand(new PingCommand($this)); |
315 | - $command->on('error', function ($command, $reason) use ($promise) { |
|
315 | + $command->on('error', function($command, $reason) use ($promise) { |
|
316 | 316 | return $promise->reject($reason); |
317 | 317 | }); |
318 | - $command->on('success', function () use ($promise) { |
|
318 | + $command->on('success', function() use ($promise) { |
|
319 | 319 | return $promise->resolve(); |
320 | 320 | }); |
321 | 321 | |
@@ -333,10 +333,10 @@ discard block |
||
333 | 333 | $trans->on('commit', function(TransactionInterface $trans, array $queue) { |
334 | 334 | $this->commitTransaction($queue)->then( |
335 | 335 | function() use($trans) { |
336 | - return $trans->emit('success', [ $trans ]); |
|
336 | + return $trans->emit('success', [$trans]); |
|
337 | 337 | }, |
338 | 338 | function($ex) use($trans) { |
339 | - return $trans->emit('error', [ $trans, $ex ]); |
|
339 | + return $trans->emit('error', [$trans, $ex]); |
|
340 | 340 | } |
341 | 341 | ); |
342 | 342 | $this->transBox->remove($trans); |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | $size = 0; |
375 | 375 | $sizeCap = count($queue); |
376 | 376 | |
377 | - for ($i=0; $i<$sizeCap; $i++) |
|
377 | + for ($i = 0; $i < $sizeCap; $i++) |
|
378 | 378 | { |
379 | 379 | $command = $this->doCommand($queue[$i]); |
380 | 380 | $command->on('error', function($command, $err) use(&$ex, $promise) { |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | */ |
417 | 417 | public function handleError($err) |
418 | 418 | { |
419 | - $this->emit('error', [ $this, $err ]); |
|
419 | + $this->emit('error', [$this, $err]); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | */ |
425 | 425 | public function handleSocketError($socket, $err) |
426 | 426 | { |
427 | - $this->emit('error', [ $this, $err ]); |
|
427 | + $this->emit('error', [$this, $err]); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | if ($this->state < self::STATE_DISCONNECT_PENDING) |
436 | 436 | { |
437 | 437 | $this->state = self::STATE_DISCONNECT_SUCCEEDED; |
438 | - $this->emit('error', [ $this, new RuntimeException('MySQL server has gone away!') ]); |
|
438 | + $this->emit('error', [$this, new RuntimeException('MySQL server has gone away!')]); |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 |