@@ -84,6 +84,9 @@ discard block |
||
84 | 84 | |
85 | 85 | protected $queue; |
86 | 86 | |
87 | + /** |
|
88 | + * @param \Dazzle\MySQL\Executor $executor |
|
89 | + */ |
|
87 | 90 | public function __construct($stream, $executor) |
88 | 91 | { |
89 | 92 | $this->stream = $stream; |
@@ -105,6 +108,9 @@ discard block |
||
105 | 108 | } |
106 | 109 | } |
107 | 110 | |
111 | + /** |
|
112 | + * @param string $message |
|
113 | + */ |
|
108 | 114 | public function debug($message) |
109 | 115 | { |
110 | 116 | if ($this->debug) { |
@@ -343,6 +349,9 @@ discard block |
||
343 | 349 | $this->buffer .= $str; |
344 | 350 | } |
345 | 351 | |
352 | + /** |
|
353 | + * @param string $str |
|
354 | + */ |
|
346 | 355 | public function prepend($str) |
347 | 356 | { |
348 | 357 | $this->buffer = $str . substr($this->buffer, $this->bufferPos); |
@@ -363,11 +372,17 @@ discard block |
||
363 | 372 | return $buffer; |
364 | 373 | } |
365 | 374 | |
375 | + /** |
|
376 | + * @param integer $len |
|
377 | + */ |
|
366 | 378 | public function skip($len) |
367 | 379 | { |
368 | 380 | $this->bufferPos += $len; |
369 | 381 | } |
370 | 382 | |
383 | + /** |
|
384 | + * @param double $len |
|
385 | + */ |
|
371 | 386 | public function restBuffer($len) |
372 | 387 | { |
373 | 388 | if(strlen($this->buffer) === ($this->bufferPos+$len)){ |
@@ -383,6 +398,9 @@ discard block |
||
383 | 398 | return strlen($this->buffer) - $this->bufferPos; |
384 | 399 | } |
385 | 400 | |
401 | + /** |
|
402 | + * @param string $what |
|
403 | + */ |
|
386 | 404 | public function search($what) |
387 | 405 | { |
388 | 406 | if (($p = strpos($this->buffer, $what, $this->bufferPos)) !== false) { |
@@ -421,6 +439,9 @@ discard block |
||
421 | 439 | $this->debug('Auth packet sent'); |
422 | 440 | } |
423 | 441 | |
442 | + /** |
|
443 | + * @param string $scramble |
|
444 | + */ |
|
424 | 445 | public function getAuthToken($scramble, $password = '') |
425 | 446 | { |
426 | 447 | if ($password === '') { |
@@ -434,6 +455,7 @@ discard block |
||
434 | 455 | /** |
435 | 456 | * Builds length-encoded BinarySupport string |
436 | 457 | * @param string String |
458 | + * @param string $s |
|
437 | 459 | * @return string Resulting BinarySupport string |
438 | 460 | */ |
439 | 461 | public function buildLenEncodedBinarySupport($s) |
@@ -499,6 +521,9 @@ discard block |
||
499 | 521 | return $this->read($l); |
500 | 522 | } |
501 | 523 | |
524 | + /** |
|
525 | + * @param string $packet |
|
526 | + */ |
|
502 | 527 | public function sendPacket($packet) |
503 | 528 | { |
504 | 529 | return $this->stream->write(BinarySupport::int2bytes(3, strlen($packet), true) . chr($this->seq++) . $packet); |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | |
95 | 95 | public function start() |
96 | 96 | { |
97 | - $this->stream->on('data', [ $this, 'handleData' ]); |
|
98 | - $this->stream->on('close', [ $this, 'handleClose' ]); |
|
97 | + $this->stream->on('data', [$this, 'handleData']); |
|
98 | + $this->stream->on('close', [$this, 'handleClose']); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | public function handleNewCommand() |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | $this->nextRequest(); |
231 | 231 | $this->onResultDone(); |
232 | 232 | } else { |
233 | - ++ $this->rsState; |
|
233 | + ++$this->rsState; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | } else { //Data packet |
@@ -370,10 +370,10 @@ discard block |
||
370 | 370 | |
371 | 371 | public function restBuffer($len) |
372 | 372 | { |
373 | - if(strlen($this->buffer) === ($this->bufferPos+$len)){ |
|
373 | + if (strlen($this->buffer) === ($this->bufferPos + $len)) { |
|
374 | 374 | $this->buffer = ''; |
375 | - }else{ |
|
376 | - $this->buffer = substr($this->buffer,$this->bufferPos+$len); |
|
375 | + } else { |
|
376 | + $this->buffer = substr($this->buffer, $this->bufferPos + $len); |
|
377 | 377 | } |
378 | 378 | $this->bufferPos = 0; |
379 | 379 | } |
@@ -100,14 +100,16 @@ discard block |
||
100 | 100 | |
101 | 101 | public function handleNewCommand() |
102 | 102 | { |
103 | - if ($this->queue->count() <= 0) { |
|
103 | + if ($this->queue->count() <= 0) |
|
104 | + { |
|
104 | 105 | $this->nextRequest(); |
105 | 106 | } |
106 | 107 | } |
107 | 108 | |
108 | 109 | public function debug($message) |
109 | 110 | { |
110 | - if ($this->debug) { |
|
111 | + if ($this->debug) |
|
112 | + { |
|
111 | 113 | $bt = debug_backtrace(); |
112 | 114 | $caller = array_shift($bt); |
113 | 115 | printf("[DEBUG] <%s:%d> %s\n", $caller['class'], $caller['line'], $message); |
@@ -116,8 +118,10 @@ discard block |
||
116 | 118 | |
117 | 119 | public function setOptions($options) |
118 | 120 | { |
119 | - foreach ($options as $option => $value) { |
|
120 | - if (property_exists($this, $option)) { |
|
121 | + foreach ($options as $option => $value) |
|
122 | + { |
|
123 | + if (property_exists($this, $option)) |
|
124 | + { |
|
121 | 125 | $this->$option = $value; |
122 | 126 | } |
123 | 127 | } |
@@ -127,8 +131,10 @@ discard block |
||
127 | 131 | { |
128 | 132 | $this->append($data); |
129 | 133 | packet: |
130 | - if ($this->state === self::STATE_STANDBY) { |
|
131 | - if ($this->length() < 4) { |
|
134 | + if ($this->state === self::STATE_STANDBY) |
|
135 | + { |
|
136 | + if ($this->length() < 4) |
|
137 | + { |
|
132 | 138 | return; |
133 | 139 | } |
134 | 140 | |
@@ -139,17 +145,21 @@ discard block |
||
139 | 145 | } |
140 | 146 | |
141 | 147 | $len = $this->length(); |
142 | - if ($len < $this->pctSize) { |
|
148 | + if ($len < $this->pctSize) |
|
149 | + { |
|
143 | 150 | $this->debug('Buffer not enouth, return'); |
144 | 151 | return; |
145 | 152 | } |
146 | 153 | $this->state = self::STATE_STANDBY; |
147 | 154 | //$this->stream->bufferSize = 4; |
148 | - if ($this->phase === 0) { |
|
155 | + if ($this->phase === 0) |
|
156 | + { |
|
149 | 157 | $this->phase = self::PHASE_GOT_INIT; |
150 | 158 | $this->protocalVersion = ord($this->read(1)); |
151 | 159 | $this->debug(sprintf("Protocol Version: %d", $this->protocalVersion)); |
152 | - if ($this->protocalVersion === 0xFF) { //error |
|
160 | + if ($this->protocalVersion === 0xFF) |
|
161 | + { |
|
162 | +//error |
|
153 | 163 | $fieldCount = $this->protocalVersion; |
154 | 164 | $this->protocalVersion = 0; |
155 | 165 | printf("Error:\n"); |
@@ -157,13 +167,15 @@ discard block |
||
157 | 167 | $this->rsState = self::RS_STATE_HEADER; |
158 | 168 | $this->resultFields = []; |
159 | 169 | $this->resultRows = []; |
160 | - if ($this->phase === self::PHASE_AUTH_SENT || $this->phase === self::PHASE_GOT_INIT) { |
|
170 | + if ($this->phase === self::PHASE_AUTH_SENT || $this->phase === self::PHASE_GOT_INIT) |
|
171 | + { |
|
161 | 172 | $this->phase = self::PHASE_AUTH_ERR; |
162 | 173 | } |
163 | 174 | |
164 | 175 | goto field; |
165 | 176 | } |
166 | - if (($p = $this->search("\x00")) === false) { |
|
177 | + if (($p = $this->search("\x00")) === false) |
|
178 | + { |
|
167 | 179 | printf("Finish\n"); |
168 | 180 | //finish |
169 | 181 | return; |
@@ -181,10 +193,13 @@ discard block |
||
181 | 193 | $this->scramble .= $restScramble; |
182 | 194 | |
183 | 195 | $this->nextRequest(true); |
184 | - } else { |
|
196 | + } |
|
197 | + else |
|
198 | + { |
|
185 | 199 | $fieldCount = ord($this->read(1)); |
186 | 200 | field: |
187 | - if ($fieldCount === 0xFF) { |
|
201 | + if ($fieldCount === 0xFF) |
|
202 | + { |
|
188 | 203 | //error packet |
189 | 204 | $u = unpack('v', $this->read(2)); |
190 | 205 | $this->errno = $u[1]; |
@@ -194,11 +209,15 @@ discard block |
||
194 | 209 | |
195 | 210 | $this->nextRequest(); |
196 | 211 | $this->onError(); |
197 | - } elseif ($fieldCount === 0x00) { //OK Packet Empty |
|
212 | + } |
|
213 | + elseif ($fieldCount === 0x00) |
|
214 | + { |
|
215 | +//OK Packet Empty |
|
198 | 216 | $this->debug('Ok Packet'); |
199 | 217 | |
200 | 218 | $isAuthenticated = false; |
201 | - if ($this->phase === self::PHASE_AUTH_SENT) { |
|
219 | + if ($this->phase === self::PHASE_AUTH_SENT) |
|
220 | + { |
|
202 | 221 | $this->phase = self::PHASE_HANDSHAKED; |
203 | 222 | $isAuthenticated = true; |
204 | 223 | } |
@@ -214,35 +233,50 @@ discard block |
||
214 | 233 | |
215 | 234 | $this->message = $this->read($this->pctSize - $len + $this->length()); |
216 | 235 | |
217 | - if ($isAuthenticated) { |
|
236 | + if ($isAuthenticated) |
|
237 | + { |
|
218 | 238 | $this->onAuthenticated(); |
219 | - } else { |
|
239 | + } |
|
240 | + else |
|
241 | + { |
|
220 | 242 | $this->onSuccess(); |
221 | 243 | } |
222 | 244 | $this->debug(sprintf("AffectedRows: %d, InsertId: %d, WarnCount:%d", $this->affectedRows, $this->insertId, $this->warnCount)); |
223 | 245 | $this->nextRequest(); |
224 | 246 | |
225 | - } elseif ($fieldCount === 0xFE) { //EOF Packet |
|
247 | + } |
|
248 | + elseif ($fieldCount === 0xFE) |
|
249 | + { |
|
250 | +//EOF Packet |
|
226 | 251 | $this->debug('EOF Packet'); |
227 | - if ($this->rsState === self::RS_STATE_ROW) { |
|
252 | + if ($this->rsState === self::RS_STATE_ROW) |
|
253 | + { |
|
228 | 254 | $this->debug('result done'); |
229 | 255 | |
230 | 256 | $this->nextRequest(); |
231 | 257 | $this->onResultDone(); |
232 | - } else { |
|
258 | + } |
|
259 | + else |
|
260 | + { |
|
233 | 261 | ++ $this->rsState; |
234 | 262 | } |
235 | 263 | |
236 | - } else { //Data packet |
|
264 | + } |
|
265 | + else |
|
266 | + { |
|
267 | +//Data packet |
|
237 | 268 | $this->debug('Data Packet'); |
238 | 269 | $this->prepend(chr($fieldCount)); |
239 | 270 | |
240 | - if ($this->rsState === self::RS_STATE_HEADER) { |
|
271 | + if ($this->rsState === self::RS_STATE_HEADER) |
|
272 | + { |
|
241 | 273 | $this->debug('Header packet of Data packet'); |
242 | 274 | $extra = $this->parseEncodedBinarySupport(); |
243 | 275 | //var_dump($extra); |
244 | 276 | $this->rsState = self::RS_STATE_FIELD; |
245 | - } elseif ($this->rsState === self::RS_STATE_FIELD) { |
|
277 | + } |
|
278 | + elseif ($this->rsState === self::RS_STATE_FIELD) |
|
279 | + { |
|
246 | 280 | $this->debug('Field packet of Data packet'); |
247 | 281 | $field = [ |
248 | 282 | 'catalog' => $this->parseEncodedString(), |
@@ -268,10 +302,13 @@ discard block |
||
268 | 302 | //var_dump($field); |
269 | 303 | $this->resultFields[] = $field; |
270 | 304 | |
271 | - } elseif ($this->rsState === self::RS_STATE_ROW) { |
|
305 | + } |
|
306 | + elseif ($this->rsState === self::RS_STATE_ROW) |
|
307 | + { |
|
272 | 308 | $this->debug('Row packet of Data packet'); |
273 | 309 | $row = []; |
274 | - for ($i = 0, $nf = sizeof($this->resultFields); $i < $nf; ++$i) { |
|
310 | + for ($i = 0, $nf = sizeof($this->resultFields); $i < $nf; ++$i) |
|
311 | + { |
|
275 | 312 | $row[$this->resultFields[$i]['name']] = $this->parseEncodedString(); |
276 | 313 | } |
277 | 314 | $this->resultRows[] = $row; |
@@ -310,7 +347,8 @@ discard block |
||
310 | 347 | protected function onSuccess() |
311 | 348 | { |
312 | 349 | $command = $this->queue->dequeue(); |
313 | - if ($command->equals(Command::QUERY)) { |
|
350 | + if ($command->equals(Command::QUERY)) |
|
351 | + { |
|
314 | 352 | $command->affectedRows = $this->affectedRows; |
315 | 353 | $command->insertId = $this->insertId; |
316 | 354 | $command->warnCount = $this->warnCount; |
@@ -328,9 +366,11 @@ discard block |
||
328 | 366 | protected function handleClose() |
329 | 367 | { |
330 | 368 | $this->emit('close'); |
331 | - if ($this->queue->count()) { |
|
369 | + if ($this->queue->count()) |
|
370 | + { |
|
332 | 371 | $command = $this->queue->dequeue(); |
333 | - if ($command->equals(Command::QUIT)) { |
|
372 | + if ($command->equals(Command::QUIT)) |
|
373 | + { |
|
334 | 374 | $command->emit('success'); |
335 | 375 | } |
336 | 376 | } |
@@ -351,12 +391,14 @@ discard block |
||
351 | 391 | |
352 | 392 | public function read($len, $skiplen = 0) |
353 | 393 | { |
354 | - if (strlen($this->buffer) - $this->bufferPos - $len - $skiplen < 0) { |
|
394 | + if (strlen($this->buffer) - $this->bufferPos - $len - $skiplen < 0) |
|
395 | + { |
|
355 | 396 | throw new \LogicException('Logic Error'); |
356 | 397 | } |
357 | 398 | $buffer = substr($this->buffer, $this->bufferPos, $len); |
358 | 399 | $this->bufferPos += $len; |
359 | - if ($skiplen) { |
|
400 | + if ($skiplen) |
|
401 | + { |
|
360 | 402 | $this->bufferPos += $skiplen; |
361 | 403 | } |
362 | 404 | |
@@ -370,9 +412,12 @@ discard block |
||
370 | 412 | |
371 | 413 | public function restBuffer($len) |
372 | 414 | { |
373 | - if(strlen($this->buffer) === ($this->bufferPos+$len)){ |
|
415 | + if(strlen($this->buffer) === ($this->bufferPos+$len)) |
|
416 | + { |
|
374 | 417 | $this->buffer = ''; |
375 | - }else{ |
|
418 | + } |
|
419 | + else |
|
420 | + { |
|
376 | 421 | $this->buffer = substr($this->buffer,$this->bufferPos+$len); |
377 | 422 | } |
378 | 423 | $this->bufferPos = 0; |
@@ -385,7 +430,8 @@ discard block |
||
385 | 430 | |
386 | 431 | public function search($what) |
387 | 432 | { |
388 | - if (($p = strpos($this->buffer, $what, $this->bufferPos)) !== false) { |
|
433 | + if (($p = strpos($this->buffer, $what, $this->bufferPos)) !== false) |
|
434 | + { |
|
389 | 435 | return $p - $this->bufferPos; |
390 | 436 | } |
391 | 437 | |
@@ -395,7 +441,8 @@ discard block |
||
395 | 441 | |
396 | 442 | public function authenticate() |
397 | 443 | { |
398 | - if ($this->phase !== self::PHASE_GOT_INIT) { |
|
444 | + if ($this->phase !== self::PHASE_GOT_INIT) |
|
445 | + { |
|
399 | 446 | return; |
400 | 447 | } |
401 | 448 | $this->phase = self::PHASE_AUTH_SENT; |
@@ -423,7 +470,8 @@ discard block |
||
423 | 470 | |
424 | 471 | public function getAuthToken($scramble, $password = '') |
425 | 472 | { |
426 | - if ($password === '') { |
|
473 | + if ($password === '') |
|
474 | + { |
|
427 | 475 | return "\x00"; |
428 | 476 | } |
429 | 477 | $token = sha1($scramble . sha1($hash1 = sha1($password, true), true), true) ^ $hash1; |
@@ -438,21 +486,25 @@ discard block |
||
438 | 486 | */ |
439 | 487 | public function buildLenEncodedBinarySupport($s) |
440 | 488 | { |
441 | - if ($s === null) { |
|
489 | + if ($s === null) |
|
490 | + { |
|
442 | 491 | return "\251"; |
443 | 492 | } |
444 | 493 | |
445 | 494 | $l = strlen($s); |
446 | 495 | |
447 | - if ($l <= 250) { |
|
496 | + if ($l <= 250) |
|
497 | + { |
|
448 | 498 | return chr($l) . $s; |
449 | 499 | } |
450 | 500 | |
451 | - if ($l <= 0xFFFF) { |
|
501 | + if ($l <= 0xFFFF) |
|
502 | + { |
|
452 | 503 | return "\252" . BinarySupport::int2bytes(2, true) . $s; |
453 | 504 | } |
454 | 505 | |
455 | - if ($l <= 0xFFFFFF) { |
|
506 | + if ($l <= 0xFFFFFF) |
|
507 | + { |
|
456 | 508 | return "\254" . BinarySupport::int2bytes(3, true) . $s; |
457 | 509 | } |
458 | 510 | |
@@ -466,19 +518,24 @@ discard block |
||
466 | 518 | public function parseEncodedBinarySupport() |
467 | 519 | { |
468 | 520 | $f = ord($this->read(1)); |
469 | - if ($f <= 250) { |
|
521 | + if ($f <= 250) |
|
522 | + { |
|
470 | 523 | return $f; |
471 | 524 | } |
472 | - if ($f === 251) { |
|
525 | + if ($f === 251) |
|
526 | + { |
|
473 | 527 | return null; |
474 | 528 | } |
475 | - if ($f === 255) { |
|
529 | + if ($f === 255) |
|
530 | + { |
|
476 | 531 | return false; |
477 | 532 | } |
478 | - if ($f === 252) { |
|
533 | + if ($f === 252) |
|
534 | + { |
|
479 | 535 | return BinarySupport::bytes2int($this->read(2), true); |
480 | 536 | } |
481 | - if ($f === 253) { |
|
537 | + if ($f === 253) |
|
538 | + { |
|
482 | 539 | return BinarySupport::bytes2int($this->read(3), true); |
483 | 540 | } |
484 | 541 | |
@@ -492,7 +549,8 @@ discard block |
||
492 | 549 | public function parseEncodedString() |
493 | 550 | { |
494 | 551 | $l = $this->parseEncodedBinarySupport(); |
495 | - if (($l === null) || ($l === false)) { |
|
552 | + if (($l === null) || ($l === false)) |
|
553 | + { |
|
496 | 554 | return $l; |
497 | 555 | } |
498 | 556 | |
@@ -506,15 +564,20 @@ discard block |
||
506 | 564 | |
507 | 565 | protected function nextRequest($isHandshake = false) |
508 | 566 | { |
509 | - if (!$isHandshake && $this->phase != self::PHASE_HANDSHAKED) { |
|
567 | + if (!$isHandshake && $this->phase != self::PHASE_HANDSHAKED) |
|
568 | + { |
|
510 | 569 | return false; |
511 | 570 | } |
512 | - if (!$this->executor->isIdle()) { |
|
571 | + if (!$this->executor->isIdle()) |
|
572 | + { |
|
513 | 573 | $command = $this->executor->dequeue(); |
514 | 574 | $this->queue->enqueue($command); |
515 | - if ($command->equals(Command::INIT_AUTHENTICATE)) { |
|
575 | + if ($command->equals(Command::INIT_AUTHENTICATE)) |
|
576 | + { |
|
516 | 577 | $this->authenticate(); |
517 | - } else { |
|
578 | + } |
|
579 | + else |
|
580 | + { |
|
518 | 581 | $this->seq = 0; |
519 | 582 | $this->sendPacket(chr($command->getID()) . $command->getSql()); |
520 | 583 | } |
@@ -382,6 +382,7 @@ |
||
382 | 382 | |
383 | 383 | /** |
384 | 384 | * @see BinarySupport::int2bytes |
385 | + * @param integer $bytes |
|
385 | 386 | */ |
386 | 387 | public static function i2b($bytes, $int = 0, $l = false) |
387 | 388 | { |
@@ -20,7 +20,8 @@ discard block |
||
20 | 20 | { |
21 | 21 | $r .= chr(strlen($e[$i])) . $e[$i]; |
22 | 22 | } |
23 | - if (static::binarySubstr($r, -1) !== "\x00") { |
|
23 | + if (static::binarySubstr($r, -1) !== "\x00") |
|
24 | + { |
|
24 | 25 | $r .= "\x00"; |
25 | 26 | } |
26 | 27 | return $r; |
@@ -40,7 +41,8 @@ discard block |
||
40 | 41 | { |
41 | 42 | $l = ord($data[0]); |
42 | 43 | |
43 | - if ($l >= 192) { |
|
44 | + if ($l >= 192) |
|
45 | + { |
|
44 | 46 | $pos = static::bytes2int(chr($l - 192) . static::binarySubstr($data, 1, 1)); |
45 | 47 | $data = static::binarySubstr($data, 2); |
46 | 48 | $ref = static::binarySubstr($orig, $pos); |
@@ -51,7 +53,8 @@ discard block |
||
51 | 53 | $p = substr($data, 1, $l); |
52 | 54 | $str .= $p . (($l !== 0) ? '.' : ''); |
53 | 55 | $data = substr($data, $l + 1); |
54 | - if ($l === 0) { |
|
56 | + if ($l === 0) |
|
57 | + { |
|
55 | 58 | break; |
56 | 59 | } |
57 | 60 | } |
@@ -68,7 +71,8 @@ discard block |
||
68 | 71 | public static function LV($str, $len = 1, $lrev = false) |
69 | 72 | { |
70 | 73 | $l = static::i2b($len, strlen($str)); |
71 | - if ($lrev) { |
|
74 | + if ($lrev) |
|
75 | + { |
|
72 | 76 | $l = strrev($l); |
73 | 77 | } |
74 | 78 | return $l . $str; |
@@ -216,7 +220,8 @@ discard block |
||
216 | 220 | { |
217 | 221 | $r = static::binarySubstr($p, 0, 2); |
218 | 222 | $p = static::binarySubstr($p, 2); |
219 | - if ($l) { |
|
223 | + if ($l) |
|
224 | + { |
|
220 | 225 | $r = strrev($r); |
221 | 226 | } |
222 | 227 | return $r; |
@@ -262,7 +267,8 @@ discard block |
||
262 | 267 | public static function getStrQWord(&$p, $l = false) |
263 | 268 | { |
264 | 269 | $r = static::binarySubstr($p, 0, 8); |
265 | - if ($l) { |
|
270 | + if ($l) |
|
271 | + { |
|
266 | 272 | $r = strrev($r); |
267 | 273 | } |
268 | 274 | $p = static::binarySubstr($p, 8); |
@@ -279,7 +285,8 @@ discard block |
||
279 | 285 | public static function getString(&$str) |
280 | 286 | { |
281 | 287 | $p = strpos($str, "\x00"); |
282 | - if ($p === false) { |
|
288 | + if ($p === false) |
|
289 | + { |
|
283 | 290 | return ''; |
284 | 291 | } |
285 | 292 | $r = static::binarySubstr($str, 0, $p); |
@@ -302,19 +309,26 @@ discard block |
||
302 | 309 | $s = static::b2i(static::binarySubstr($p, 0, $l), !!$lrev); |
303 | 310 | $p = static::binarySubstr($p, $l); |
304 | 311 | |
305 | - if ($s == 0) { |
|
312 | + if ($s == 0) |
|
313 | + { |
|
306 | 314 | return ''; |
307 | 315 | } |
308 | 316 | |
309 | 317 | $r = ''; |
310 | 318 | |
311 | - if (strlen($p) < $s) { |
|
319 | + if (strlen($p) < $s) |
|
320 | + { |
|
312 | 321 | echo("getLV error: buf length (" . strlen($p) . "): " . Debug::exportBytes($p) . ", must be >= string length (" . $s . ")\n"); |
313 | 322 | |
314 | - } else if ($nul) { |
|
315 | - if ($p{$s - 1} != "\x00") { |
|
323 | + } |
|
324 | + else if ($nul) |
|
325 | + { |
|
326 | + if ($p{$s - 1} != "\x00") |
|
327 | + { |
|
316 | 328 | echo("getLV error: Wrong end of NUL-string (" . Debug::exportBytes($p{$s - 1}) . "), len " . $s . "\n"); |
317 | - } else { |
|
329 | + } |
|
330 | + else |
|
331 | + { |
|
318 | 332 | $d = $s - 1; |
319 | 333 | if ($d < 0) |
320 | 334 | { |
@@ -324,7 +338,9 @@ discard block |
||
324 | 338 | $p = static::binarySubstr($p, $s); |
325 | 339 | } |
326 | 340 | |
327 | - } else { |
|
341 | + } |
|
342 | + else |
|
343 | + { |
|
328 | 344 | $r = static::binarySubstr($p, 0, $s); |
329 | 345 | $p = static::binarySubstr($p, $s); |
330 | 346 | } |
@@ -344,11 +360,15 @@ discard block |
||
344 | 360 | { |
345 | 361 | $hexstr = dechex($int); |
346 | 362 | |
347 | - if ($len === null) { |
|
348 | - if (strlen($hexstr) % 2) { |
|
363 | + if ($len === null) |
|
364 | + { |
|
365 | + if (strlen($hexstr) % 2) |
|
366 | + { |
|
349 | 367 | $hexstr = "0" . $hexstr; |
350 | 368 | } |
351 | - } else { |
|
369 | + } |
|
370 | + else |
|
371 | + { |
|
352 | 372 | $hexstr = str_repeat('0', $len * 2 - strlen($hexstr)) . $hexstr; |
353 | 373 | } |
354 | 374 | |
@@ -397,7 +417,8 @@ discard block |
||
397 | 417 | */ |
398 | 418 | public static function bytes2int($str, $l = false) |
399 | 419 | { |
400 | - if ($l) { |
|
420 | + if ($l) |
|
421 | + { |
|
401 | 422 | $str = strrev($str); |
402 | 423 | } |
403 | 424 | |
@@ -437,7 +458,8 @@ discard block |
||
437 | 458 | { |
438 | 459 | $r .= chr((int) bindec(static::binarySubstr($bitmap, $i * 8, 8))); |
439 | 460 | } |
440 | - if ($checkLen && (strlen($r) != $checkLen)) { |
|
461 | + if ($checkLen && (strlen($r) != $checkLen)) |
|
462 | + { |
|
441 | 463 | throw new Exception('Warning! Bitmap incorrect.'); |
442 | 464 | } |
443 | 465 | |
@@ -465,13 +487,17 @@ discard block |
||
465 | 487 | */ |
466 | 488 | protected static function binarySubstr($s, $p, $len = null) |
467 | 489 | { |
468 | - if ($len === null) { |
|
490 | + if ($len === null) |
|
491 | + { |
|
469 | 492 | $ret = substr($s, $p); |
470 | - } else { |
|
493 | + } |
|
494 | + else |
|
495 | + { |
|
471 | 496 | $ret = substr($s, $p, $len); |
472 | 497 | } |
473 | 498 | |
474 | - if ($ret === false) { |
|
499 | + if ($ret === false) |
|
500 | + { |
|
475 | 501 | $ret = ''; |
476 | 502 | } |
477 | 503 |
@@ -44,7 +44,6 @@ |
||
44 | 44 | /** |
45 | 45 | * Binding params for the query, mutiple arguments support. |
46 | 46 | * |
47 | - * @param mixed $param |
|
48 | 47 | * @return Query |
49 | 48 | */ |
50 | 49 | public function bindParams() |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | public function bindParams() |
51 | 51 | { |
52 | 52 | $this->sqlPrepared = null; |
53 | - $this->params = func_get_args(); |
|
53 | + $this->params = func_get_args(); |
|
54 | 54 | |
55 | 55 | return $this; |
56 | 56 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function bindParamsFromArray(array $params) |
59 | 59 | { |
60 | 60 | $this->sqlPrepared = null; |
61 | - $this->params = $params; |
|
61 | + $this->params = $params; |
|
62 | 62 | |
63 | 63 | return $this; |
64 | 64 | } |
@@ -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); |
@@ -12,7 +12,8 @@ |
||
12 | 12 | } |
13 | 13 | |
14 | 14 | public function buildPacket() |
15 | - {} |
|
15 | + { |
|
16 | +} |
|
16 | 17 | |
17 | 18 | public function getSql() |
18 | 19 | { |
@@ -20,5 +20,6 @@ |
||
20 | 20 | * @inheritDoc |
21 | 21 | */ |
22 | 22 | public function buildPacket() |
23 | - {} |
|
23 | + { |
|
24 | +} |
|
24 | 25 | } |
@@ -20,7 +20,8 @@ |
||
20 | 20 | * @inheritDoc |
21 | 21 | */ |
22 | 22 | public function buildPacket() |
23 | - {} |
|
23 | + { |
|
24 | +} |
|
24 | 25 | |
25 | 26 | /** |
26 | 27 | * @override |
@@ -24,7 +24,7 @@ |
||
24 | 24 | |
25 | 25 | public function setQuery($query) |
26 | 26 | { |
27 | - if (! $query instanceof Query) |
|
27 | + if (!$query instanceof Query) |
|
28 | 28 | { |
29 | 29 | $query = new Query($query); |
30 | 30 | } |
@@ -43,5 +43,6 @@ |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | public function buildPacket() |
46 | - {} |
|
46 | + { |
|
47 | +} |
|
47 | 48 | } |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | throw new Exception('Not Implemented'); |
109 | 109 | } |
110 | 110 | |
111 | - $errorHandler = function ($reason) use ($args) { |
|
111 | + $errorHandler = function($reason) use ($args) { |
|
112 | 112 | $this->state = self::STATE_AUTH_FAILED; |
113 | 113 | $args[0]($reason, $this); |
114 | 114 | }; |
115 | 115 | |
116 | - $connectedHandler = function ($serverOptions) use ($args) { |
|
116 | + $connectedHandler = function($serverOptions) use ($args) { |
|
117 | 117 | $this->state = self::STATE_AUTH_SUCCEEDED; |
118 | 118 | $this->serverOptions = $serverOptions; |
119 | 119 | $args[0](null, $this); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | |
122 | 122 | $this |
123 | 123 | ->connect() |
124 | - ->then(function ($stream) use (&$streamRef, $options, $errorHandler, $connectedHandler) { |
|
124 | + ->then(function($stream) use (&$streamRef, $options, $errorHandler, $connectedHandler) { |
|
125 | 125 | $streamRef = $stream; |
126 | 126 | |
127 | - $stream->on('error', [ $this, 'handleConnectionError' ]); |
|
128 | - $stream->on('close', [ $this, 'handleConnectionClosed' ]); |
|
127 | + $stream->on('error', [$this, 'handleConnectionError']); |
|
128 | + $stream->on('close', [$this, 'handleConnectionClosed']); |
|
129 | 129 | |
130 | 130 | $parser = $this->parser = new ProtocolParser($stream, $this->executor); |
131 | 131 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | //$parser->on('close', $closeHandler); |
139 | 139 | $parser->start(); |
140 | 140 | |
141 | - }, [ $this, 'handleConnectionError' ]); |
|
141 | + }, [$this, 'handleConnectionError']); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | /** |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | ->doCommand(new QuitCommand($this)) |
152 | 152 | ->on('success', function() { |
153 | 153 | $this->state = self::STATE_STOPPED; |
154 | - $this->emit('end', [ $this ]); |
|
155 | - $this->emit('close', [ $this ]); |
|
154 | + $this->emit('end', [$this]); |
|
155 | + $this->emit('close', [$this]); |
|
156 | 156 | }); |
157 | 157 | $this->state = self::STATE_CLOSEING; |
158 | 158 | } |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | $query->bindParamsFromArray($args); |
192 | 192 | $this->doCommand($command); |
193 | 193 | |
194 | - $command->on('results', function ($rows, $command) use ($callback) { |
|
194 | + $command->on('results', function($rows, $command) use ($callback) { |
|
195 | 195 | $callback($command, $this); |
196 | 196 | }); |
197 | - $command->on('error', function ($err, $command) use ($callback) { |
|
197 | + $command->on('error', function($err, $command) use ($callback) { |
|
198 | 198 | $callback($command, $this); |
199 | 199 | }); |
200 | - $command->on('success', function ($command) use ($callback) { |
|
200 | + $command->on('success', function($command) use ($callback) { |
|
201 | 201 | $callback($command, $this); |
202 | 202 | }); |
203 | 203 | } |
@@ -209,10 +209,10 @@ discard block |
||
209 | 209 | throw new InvalidArgumentException('Callback is not a valid callable'); |
210 | 210 | } |
211 | 211 | $this->doCommand(new PingCommand($this)) |
212 | - ->on('error', function ($reason) use ($callback) { |
|
212 | + ->on('error', function($reason) use ($callback) { |
|
213 | 213 | $callback($reason, $this); |
214 | 214 | }) |
215 | - ->on('success', function () use ($callback) { |
|
215 | + ->on('success', function() use ($callback) { |
|
216 | 216 | $callback(null, $this); |
217 | 217 | }); |
218 | 218 | } |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | |
247 | 247 | public function handleConnectionError($err) |
248 | 248 | { |
249 | - $this->emit('error', [ $err, $this ]); |
|
249 | + $this->emit('error', [$err, $this]); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | public function handleConnectionClosed() |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | if ($this->state < self::STATE_CLOSEING) |
255 | 255 | { |
256 | 256 | $this->state = self::STATE_STOPPED; |
257 | - $this->emit('error', [ new RuntimeException('mysql server has gone away'), $this ]); |
|
257 | + $this->emit('error', [new RuntimeException('mysql server has gone away'), $this]); |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 |
@@ -104,7 +104,8 @@ |
||
104 | 104 | $streamRef = $this->stream; |
105 | 105 | $args = func_get_args(); |
106 | 106 | |
107 | - if (!$args) { |
|
107 | + if (!$args) |
|
108 | + { |
|
108 | 109 | throw new Exception('Not Implemented'); |
109 | 110 | } |
110 | 111 |