Completed
Push — master ( 19729f...c9ac63 )
by Biao
04:04
created

tryAgainIfCausedByLostConnection()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hhxsv5\LaravelS\Illuminate\Database;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Database\QueryException;
7
use Illuminate\Database\MySqlConnection;
8
9
class SwooleMySQLConnection extends MySqlConnection
10
{
11
    /**
12
     * The active swoole mysql connection.
13
     *
14
     * @var SwoolePDO
15
     */
16
    protected $pdo;
17
18
    /**
19
     * The active swoole mysql used for reads.
20
     *
21
     * @var SwoolePDO
22
     */
23
    protected $readPdo;
24
25
    public function getDriverName()
26
    {
27
        return 'Swoole Coroutine MySQL';
28
    }
29
30
    protected function tryAgainIfCausedByLostConnection(QueryException $e, $query, $bindings, \Closure $callback)
31
    {
32
        if ($this->causedByLostConnection($e->getPrevious()) || Str::contains($e->getMessage(), 'is closed')) {
33
            $this->reconnect();
34
35
            return $this->runQueryCallback($query, $bindings, $callback);
36
        }
37
38
        throw $e;
39
    }
40
}