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

SwooleMySQLConnection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A tryAgainIfCausedByLostConnection() 0 9 3
A getDriverName() 0 3 1
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
}