forked from bashkarev/clickhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SocketException.php
41 lines (35 loc) · 887 Bytes
/
SocketException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* @copyright Copyright (c) 2017 Dmitry Bashkarev
* @license https://github.com/bashkarev/clickhouse/blob/master/LICENSE
* @link https://github.com/bashkarev/clickhouse#readme
*/
namespace bashkarev\clickhouse;
use yii\db\Exception;
/**
* @author Dmitry Bashkarev <dmitry@bashkarev.com>
*/
class SocketException extends Exception
{
/**
* @inheritdoc
*/
public function __construct($message, $errorInfo = [], $code = 0, \Exception $previous = null)
{
if ($code === 0) {
$code = $this->parseCode($message);
}
parent::__construct($message, $errorInfo, $code, $previous);
}
/**
* @param $message
* @return int
*/
protected function parseCode($message)
{
if (preg_match('/errno=(\d+)/', $message, $out)) {
return (int)$out[1];
}
return 0;
}
}