@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | class StrictQuoteLine |
7 | 7 | { |
8 | 8 | |
9 | - private $preset=[ |
|
9 | + private $preset = [ |
|
10 | 10 | 'CSV'=>[ |
11 | 11 | 'EnclosureArray'=>'"', |
12 | 12 | 'EncodeEnclosure'=>'"', |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | 'TabEncode'=>true, |
33 | 33 | ], |
34 | 34 | ]; |
35 | - private $settings=[]; |
|
35 | + private $settings = []; |
|
36 | 36 | |
37 | 37 | public function __construct($format) |
38 | 38 | { |
39 | 39 | if (empty($this->preset[$format])) |
40 | 40 | { |
41 | - throw new QueryException("Unsupport format encode line:".$format); |
|
41 | + throw new QueryException("Unsupport format encode line:" . $format); |
|
42 | 42 | } |
43 | - $this->settings=$this->preset[$format]; |
|
43 | + $this->settings = $this->preset[$format]; |
|
44 | 44 | } |
45 | 45 | public function quoteRow($row) |
46 | 46 | { |
47 | - return implode($this->settings['Delimiter'],$this->quoteValue($row)); |
|
47 | + return implode($this->settings['Delimiter'], $this->quoteValue($row)); |
|
48 | 48 | } |
49 | 49 | public function quoteValue($row) |
50 | 50 | { |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | $encode = $this->settings['EncodeEnclosure']; |
54 | 54 | $encodeArray = $this->settings['EnclosureArray']; |
55 | 55 | $null = $this->settings['Null']; |
56 | - $tabEncode=$this->settings['TabEncode']; |
|
56 | + $tabEncode = $this->settings['TabEncode']; |
|
57 | 57 | |
58 | 58 | |
59 | - $quote = function ($value) use ($enclosure,$delimiter,$encode,$encodeArray,$null,$tabEncode) { |
|
59 | + $quote = function($value) use ($enclosure, $delimiter, $encode, $encodeArray, $null, $tabEncode) { |
|
60 | 60 | |
61 | 61 | |
62 | 62 | |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | if (is_string($value)) { |
76 | 76 | if ($tabEncode) |
77 | 77 | { |
78 | - return str_replace(["\t","\n"],['\\t','\\n'],$value); |
|
78 | + return str_replace(["\t", "\n"], ['\\t', '\\n'], $value); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | $value = strval($value); |
82 | - $value = preg_replace('/('.$enclosure_esc.'|'.$encode_esc.')/',$encode_esc.'\1', $value); |
|
82 | + $value = preg_replace('/(' . $enclosure_esc . '|' . $encode_esc . ')/', $encode_esc . '\1', $value); |
|
83 | 83 | return $enclosure . $value . $enclosure; |
84 | 84 | } |
85 | 85 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | // as in the TabSeparated format, and then the resulting string is output in InsertRow in double quotes. |
91 | 91 | $result_array = FormatLine::Insert($value); |
92 | 92 | |
93 | - return $encodeArray . '[' . $result_array . ']' .$encodeArray; |
|
93 | + return $encodeArray . '[' . $result_array . ']' . $encodeArray; |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | if (null === $value) { |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | * @var array |
10 | 10 | */ |
11 | - private static $strict=[]; |
|
11 | + private static $strict = []; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Format |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | { |
21 | 21 | if (empty(self::$strict[$format])) |
22 | 22 | { |
23 | - self::$strict[$format]=new StrictQuoteLine($format); |
|
23 | + self::$strict[$format] = new StrictQuoteLine($format); |
|
24 | 24 | } |
25 | 25 | return self::$strict[$format]; |
26 | 26 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | const FORMAT_TabSeparatedWithNames = 'TabSeparatedWithNames'; |
14 | 14 | const FORMAT_CSV = 'CSV'; |
15 | 15 | |
16 | - private $support_format=['TabSeparated','TabSeparatedWithNames','CSV']; |
|
16 | + private $support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV']; |
|
17 | 17 | /** |
18 | 18 | * @var string |
19 | 19 | */ |
@@ -22,19 +22,19 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @var string |
24 | 24 | */ |
25 | - private $format='CSV'; |
|
25 | + private $format = 'CSV'; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @var bool |
29 | 29 | */ |
30 | - private $gzip=false; |
|
30 | + private $gzip = false; |
|
31 | 31 | /** |
32 | 32 | * WriteToFile constructor. |
33 | 33 | * @param $file_name |
34 | 34 | * @param bool $overwrite |
35 | 35 | * @param null $format |
36 | 36 | */ |
37 | - public function __construct($file_name,$overwrite=true,$format=null) { |
|
37 | + public function __construct($file_name, $overwrite = true, $format = null) { |
|
38 | 38 | |
39 | 39 | |
40 | 40 | if (!$file_name) |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | throw new QueryException('Can`t delete: ' . $file_name); |
54 | 54 | } |
55 | 55 | } |
56 | - $dir=dirname($file_name); |
|
56 | + $dir = dirname($file_name); |
|
57 | 57 | if (!is_writable($dir)) |
58 | 58 | { |
59 | 59 | throw new QueryException('Can`t writable dir: ' . $dir); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | $this->setFormat($format); |
64 | 64 | } |
65 | - $this->file_name=$file_name; |
|
65 | + $this->file_name = $file_name; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function setGzip($flag) |
80 | 80 | { |
81 | - $this->gzip=$flag; |
|
81 | + $this->gzip = $flag; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function setFormat($format) |
88 | 88 | { |
89 | - if (!in_array($format,$this->support_format)) |
|
89 | + if (!in_array($format, $this->support_format)) |
|
90 | 90 | { |
91 | 91 | throw new QueryException('Unsupport format: ' . $format); |
92 | 92 | } |
93 | - $this->format=$format; |
|
93 | + $this->format = $format; |
|
94 | 94 | } |
95 | 95 | /** |
96 | 96 | * @return int |
@@ -19,21 +19,21 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @var array |
21 | 21 | */ |
22 | - private $degenerations=[]; |
|
22 | + private $degenerations = []; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Query constructor. |
26 | 26 | * @param $sql |
27 | 27 | * @param array $degenerations |
28 | 28 | */ |
29 | - public function __construct($sql,$degenerations=[]) |
|
29 | + public function __construct($sql, $degenerations = []) |
|
30 | 30 | { |
31 | 31 | if (!trim($sql)) |
32 | 32 | { |
33 | 33 | throw new QueryException('Empty Query'); |
34 | 34 | } |
35 | 35 | $this->sql = $sql; |
36 | - $this->degenerations=$degenerations; |
|
36 | + $this->degenerations = $degenerations; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -49,17 +49,17 @@ discard block |
||
49 | 49 | { |
50 | 50 | // FORMAT\s(\w)*$ |
51 | 51 | if (null === $this->format) return false; |
52 | - $supportFormats= |
|
52 | + $supportFormats = |
|
53 | 53 | "FORMAT\\s+TSV|FORMAT\\s+TSVRaw|FORMAT\\s+TSVWithNames|FORMAT\\s+TSVWithNamesAndTypes|FORMAT\\s+Vertical|FORMAT\\s+JSONCompact|FORMAT\\s+JSONEachRow|FORMAT\\s+TSKV|FORMAT\\s+TabSeparatedWithNames|FORMAT\\s+TabSeparatedWithNamesAndTypes|FORMAT\\s+TabSeparatedRaw|FORMAT\\s+BlockTabSeparated|FORMAT\\s+CSVWithNames|FORMAT\\s+CSV|FORMAT\\s+JSON|FORMAT\\s+TabSeparated"; |
54 | 54 | |
55 | - $matches=[]; |
|
56 | - if (preg_match_all('%('.$supportFormats.')%ius',$this->sql,$matches)){ |
|
55 | + $matches = []; |
|
56 | + if (preg_match_all('%(' . $supportFormats . ')%ius', $this->sql, $matches)) { |
|
57 | 57 | |
58 | 58 | // skip add "format json" |
59 | 59 | if (isset($matches[0])) |
60 | 60 | { |
61 | - $format=trim(str_ireplace('format','',$matches[0][0])); |
|
62 | - $this->format=$format; |
|
61 | + $format = trim(str_ireplace('format', '', $matches[0][0])); |
|
62 | + $this->format = $format; |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | foreach ($this->degenerations as $degeneration) |
94 | 94 | { |
95 | 95 | if ($degeneration instanceof \ClickHouseDB\Query\Degeneration) |
96 | - $this->sql=$degeneration->process($this->sql); |
|
96 | + $this->sql = $degeneration->process($this->sql); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | */ |
14 | 14 | public function bindParams(array $bindings) |
15 | 15 | { |
16 | - $this->bindings=[]; |
|
16 | + $this->bindings = []; |
|
17 | 17 | foreach ($bindings as $column => $value) { |
18 | 18 | $this->bindParam($column, $value); |
19 | 19 | } |
@@ -17,44 +17,44 @@ discard block |
||
17 | 17 | public function bindParams(array $bindings) |
18 | 18 | { |
19 | 19 | foreach ($bindings as $column => $value) { |
20 | - $this->bindings[$column]=$value; |
|
20 | + $this->bindings[$column] = $value; |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | 24 | |
25 | - static function __ifsets($matches,$markers,$else=false) |
|
25 | + static function __ifsets($matches, $markers, $else = false) |
|
26 | 26 | { |
27 | - $content_false=''; |
|
27 | + $content_false = ''; |
|
28 | 28 | |
29 | 29 | if ($else) |
30 | 30 | { |
31 | - list($condition, $preset ,$variable, $content_true, $content_false) = $matches; |
|
31 | + list($condition, $preset, $variable, $content_true, $content_false) = $matches; |
|
32 | 32 | } |
33 | 33 | else |
34 | 34 | { |
35 | - list($condition, $preset ,$variable, $content_true) = $matches; |
|
35 | + list($condition, $preset, $variable, $content_true) = $matches; |
|
36 | 36 | } |
37 | - $preset=strtolower($preset); |
|
37 | + $preset = strtolower($preset); |
|
38 | 38 | |
39 | - if ($preset=='set') |
|
39 | + if ($preset == 'set') |
|
40 | 40 | { |
41 | - return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true: $content_false; |
|
41 | + return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true : $content_false; |
|
42 | 42 | } |
43 | - if ($preset=='bool') |
|
43 | + if ($preset == 'bool') |
|
44 | 44 | { |
45 | - return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable]==true) |
|
45 | + return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable] == true) |
|
46 | 46 | ? $content_true |
47 | 47 | : $content_false; |
48 | 48 | } |
49 | - if ($preset=='string') |
|
49 | + if ($preset == 'string') |
|
50 | 50 | { |
51 | 51 | return (isset($markers[$variable]) && is_string($markers[$variable]) && strlen($markers[$variable])) |
52 | 52 | ? $content_true |
53 | 53 | : $content_false; |
54 | 54 | } |
55 | - if ($preset=='int') |
|
55 | + if ($preset == 'int') |
|
56 | 56 | { |
57 | - return (isset($markers[$variable]) && intval($markers[$variable])<>0 ) |
|
57 | + return (isset($markers[$variable]) && intval($markers[$variable]) <> 0) |
|
58 | 58 | ? $content_true |
59 | 59 | : $content_false; |
60 | 60 | } |
@@ -68,29 +68,29 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function process($sql) |
70 | 70 | { |
71 | - $markers=$this->bindings; |
|
71 | + $markers = $this->bindings; |
|
72 | 72 | |
73 | 73 | // 2. process if/else conditions |
74 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
74 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
75 | 75 | list($condition, $variable, $content_true, $content_false) = $matches; |
76 | 76 | |
77 | - return (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) ) ) |
|
77 | + return (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) |
|
78 | 78 | ? $content_true |
79 | 79 | : $content_false; |
80 | 80 | }, $sql); |
81 | 81 | |
82 | 82 | // 3. process if conditions |
83 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
83 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
84 | 84 | list($condition, $variable, $content) = $matches; |
85 | 85 | |
86 | - if (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) )) { |
|
86 | + if (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) { |
|
87 | 87 | return $content; |
88 | 88 | } |
89 | 89 | }, $sql); |
90 | 90 | |
91 | 91 | // 1. process if[set|int]/else conditions |
92 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) {return self::__ifsets($matches,$markers,true); }, $sql); |
|
93 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { return self::__ifsets($matches,$markers,false); }, $sql); |
|
92 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) {return self::__ifsets($matches, $markers, true); }, $sql); |
|
93 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { return self::__ifsets($matches, $markers, false); }, $sql); |
|
94 | 94 | |
95 | 95 | return $sql; |
96 | 96 | } |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | CURLOPT_SSL_VERIFYHOST => 0, |
110 | 110 | CURLOPT_SSL_VERIFYPEER => false, |
111 | 111 | CURLOPT_TIMEOUT => 10, |
112 | - CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
112 | + CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
113 | 113 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
114 | 114 | CURLOPT_MAXREDIRS => 10, |
115 | 115 | CURLOPT_HEADER => TRUE, |
116 | 116 | CURLOPT_FOLLOWLOCATION => TRUE, |
117 | - CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
118 | - CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
117 | + CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
118 | + CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
119 | 119 | CURLOPT_RETURNTRANSFER => TRUE, |
120 | 120 | CURLOPT_USERAGENT => 'smi2/PHPClickHouse/client', |
121 | 121 | ); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | } |
235 | 235 | public function setReadFunction($callback) |
236 | 236 | { |
237 | - $this->options[CURLOPT_READFUNCTION]=$callback; |
|
237 | + $this->options[CURLOPT_READFUNCTION] = $callback; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -352,9 +352,9 @@ discard block |
||
352 | 352 | |
353 | 353 | public function getHeaders() |
354 | 354 | { |
355 | - $head=[]; |
|
355 | + $head = []; |
|
356 | 356 | foreach ($this->headers as $key=>$value) |
357 | - $head[]= sprintf("%s: %s", $key, $value); |
|
357 | + $head[] = sprintf("%s: %s", $key, $value); |
|
358 | 358 | return $head; |
359 | 359 | } |
360 | 360 | |
@@ -628,8 +628,8 @@ discard block |
||
628 | 628 | throw new \Exception('setFunctionProgress not is_callable'); |
629 | 629 | } |
630 | 630 | |
631 | - $this->option(CURLOPT_NOPROGRESS,false); |
|
632 | - $this->option(CURLOPT_PROGRESSFUNCTION,$callback); // version 5.5.0 |
|
631 | + $this->option(CURLOPT_NOPROGRESS, false); |
|
632 | + $this->option(CURLOPT_PROGRESSFUNCTION, $callback); // version 5.5.0 |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | } |
693 | 693 | |
694 | 694 | if ($this->options[CURLOPT_VERBOSE]) { |
695 | - echo "\n-----------BODY REQUEST----------\n".$curl_opt[CURLOPT_POSTFIELDS]."\n------END--------\n"; |
|
695 | + echo "\n-----------BODY REQUEST----------\n" . $curl_opt[CURLOPT_POSTFIELDS] . "\n------END--------\n"; |
|
696 | 696 | } |
697 | 697 | curl_setopt_array($this->handle, $curl_opt); |
698 | 698 | return true; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function total_time() |
72 | 72 | { |
73 | - return round($this->_info['total_time'],3); |
|
73 | + return round($this->_info['total_time'], 3); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function starttransfer_time() |
80 | 80 | { |
81 | - return round($this->_info['starttransfer_time'],3); |
|
81 | + return round($this->_info['starttransfer_time'], 3); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function connect_time() |
88 | 88 | { |
89 | - return round($this->_info['connect_time'],3); |
|
89 | + return round($this->_info['connect_time'], 3); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function pretransfer_time() |
96 | 96 | { |
97 | - return round($this->_info['pretransfer_time'],3); |
|
97 | + return round($this->_info['pretransfer_time'], 3); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function rawDataOrJson($format) |
291 | 291 | { |
292 | - if (stripos($format,'json')!==false) |
|
292 | + if (stripos($format, 'json') !== false) |
|
293 | 293 | { |
294 | 294 | return $this->json(); |
295 | 295 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @var int |
44 | 44 | */ |
45 | - private $scanTimeOut=10; |
|
45 | + private $scanTimeOut = 10; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @var array |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @var array |
79 | 79 | */ |
80 | - private $_table_size_cache=[]; |
|
80 | + private $_table_size_cache = []; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Cluster constructor. |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | // @todo : rewrite total_replicas=1 если кластер без реплики , нужно проверять какой класте и сколько в нем реплик |
193 | 193 | // if ($replica['total_replicas']<2) {$ok=false;$this->error[]='total_replicas : '.json_encode($replica);} |
194 | - if ($this->softCheck ) |
|
194 | + if ($this->softCheck) |
|
195 | 195 | { |
196 | 196 | if (!$ok) break; |
197 | 197 | continue; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $statementsClusters[$node]->getRequest()->setDnsCache(0)->timeOut($this->scanTimeOut)->connectTimeOut($this->scanTimeOut); |
263 | 263 | } |
264 | 264 | $this->defaultClient()->executeAsync(); |
265 | - $tables=[]; |
|
265 | + $tables = []; |
|
266 | 266 | |
267 | 267 | foreach ($this->nodes as $node) { |
268 | 268 | |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | try { |
271 | 271 | $r = $statementsReplicas[$node]->rows(); |
272 | 272 | foreach ($r as $row) { |
273 | - $tables[$row['database']][$row['table']][$node] =$row; |
|
273 | + $tables[$row['database']][$row['table']][$node] = $row; |
|
274 | 274 | } |
275 | 275 | $result['replicas'][$node] = $r; |
276 | - } catch (\Exception $E) { |
|
276 | + }catch (\Exception $E) { |
|
277 | 277 | $result['replicas'][$node] = false; |
278 | 278 | $badNodes[$node] = $E->getMessage(); |
279 | 279 | $this->error[] = 'statementsReplicas:' . $E->getMessage(); |
280 | 280 | } |
281 | 281 | // --------------------------------------------------------------------------------------------------- |
282 | - $hosts=[]; |
|
282 | + $hosts = []; |
|
283 | 283 | |
284 | 284 | try { |
285 | 285 | $c = $statementsClusters[$node]->rows(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | ]; |
296 | 296 | } |
297 | 297 | |
298 | - } catch (\Exception $E) { |
|
298 | + }catch (\Exception $E) { |
|
299 | 299 | $result['clusters'][$node] = false; |
300 | 300 | |
301 | 301 | $this->error[] = 'clusters:' . $E->getMessage(); |
@@ -360,22 +360,22 @@ discard block |
||
360 | 360 | /** |
361 | 361 | * @return Client |
362 | 362 | */ |
363 | - public function clientLike($cluster,$ip_addr_like) |
|
363 | + public function clientLike($cluster, $ip_addr_like) |
|
364 | 364 | { |
365 | - $nodes_check=$this->nodes; |
|
366 | - $nodes=$this->getClusterNodes($cluster); |
|
367 | - $list_ips_need=explode(';',$ip_addr_like); |
|
368 | - $find=false; |
|
369 | - foreach($list_ips_need as $like) |
|
365 | + $nodes_check = $this->nodes; |
|
366 | + $nodes = $this->getClusterNodes($cluster); |
|
367 | + $list_ips_need = explode(';', $ip_addr_like); |
|
368 | + $find = false; |
|
369 | + foreach ($list_ips_need as $like) |
|
370 | 370 | { |
371 | 371 | foreach ($nodes as $node) |
372 | 372 | { |
373 | 373 | |
374 | - if (stripos($node,$like)!==false) |
|
374 | + if (stripos($node, $like) !== false) |
|
375 | 375 | { |
376 | - if (in_array($node,$nodes_check)) |
|
376 | + if (in_array($node, $nodes_check)) |
|
377 | 377 | { |
378 | - $find=$node; |
|
378 | + $find = $node; |
|
379 | 379 | } |
380 | 380 | else |
381 | 381 | { |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | } |
388 | 388 | if ($find) break; |
389 | 389 | } |
390 | - if (!$find){ |
|
391 | - $find=$nodes[0]; |
|
390 | + if (!$find) { |
|
391 | + $find = $nodes[0]; |
|
392 | 392 | } |
393 | 393 | return $this->client($find); |
394 | 394 | } |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | * |
463 | 463 | * @return array |
464 | 464 | */ |
465 | - public function getTables($resultDetail=false) |
|
465 | + public function getTables($resultDetail = false) |
|
466 | 466 | { |
467 | 467 | $this->connect(); |
468 | - $list=[]; |
|
468 | + $list = []; |
|
469 | 469 | foreach ($this->tables as $db_name=>$tables) |
470 | 470 | { |
471 | 471 | foreach ($tables as $table_name=>$nodes) |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | |
474 | 474 | if ($resultDetail) |
475 | 475 | { |
476 | - $list[$db_name.'.'.$table_name]=$nodes; |
|
476 | + $list[$db_name . '.' . $table_name] = $nodes; |
|
477 | 477 | } |
478 | 478 | else |
479 | 479 | { |
480 | - $list[$db_name.'.'.$table_name]=array_keys($nodes); |
|
480 | + $list[$db_name . '.' . $table_name] = array_keys($nodes); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | } |
@@ -493,24 +493,24 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function getSizeTable($database_table) |
495 | 495 | { |
496 | - $list=[]; |
|
497 | - $nodes=$this->getNodesByTable($database_table); |
|
496 | + $list = []; |
|
497 | + $nodes = $this->getNodesByTable($database_table); |
|
498 | 498 | // scan need node`s |
499 | 499 | foreach ($nodes as $node) |
500 | 500 | { |
501 | 501 | if (empty($this->_table_size_cache[$node])) |
502 | 502 | { |
503 | - $this->_table_size_cache[$node]=$this->client($node)->tablesSize(true); |
|
503 | + $this->_table_size_cache[$node] = $this->client($node)->tablesSize(true); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | - $sizes=[]; |
|
507 | + $sizes = []; |
|
508 | 508 | foreach ($this->_table_size_cache as $node=>$rows) |
509 | 509 | { |
510 | 510 | foreach ($rows as $row) |
511 | 511 | { |
512 | - $sizes[$row['database'].'.'.$row['table']][$node]=$row; |
|
513 | - @$sizes[$row['database'].'.'.$row['table']]['total']['sizebytes']+=$row['sizebytes']; |
|
512 | + $sizes[$row['database'] . '.' . $row['table']][$node] = $row; |
|
513 | + @$sizes[$row['database'] . '.' . $row['table']]['total']['sizebytes'] += $row['sizebytes']; |
|
514 | 514 | |
515 | 515 | |
516 | 516 | |
@@ -531,17 +531,17 @@ discard block |
||
531 | 531 | * @param $database_table |
532 | 532 | * @return array |
533 | 533 | */ |
534 | - public function truncateTable($database_table,$timeOut=2000) |
|
534 | + public function truncateTable($database_table, $timeOut = 2000) |
|
535 | 535 | { |
536 | - $out=[]; |
|
537 | - list($db,$table)=explode('.',$database_table); |
|
538 | - $nodes=$this->getMasterNodeForTable($database_table); |
|
536 | + $out = []; |
|
537 | + list($db, $table) = explode('.', $database_table); |
|
538 | + $nodes = $this->getMasterNodeForTable($database_table); |
|
539 | 539 | // scan need node`s |
540 | 540 | foreach ($nodes as $node) |
541 | 541 | { |
542 | - $def=$this->client($node)->getTimeout(); |
|
542 | + $def = $this->client($node)->getTimeout(); |
|
543 | 543 | $this->client($node)->database($db)->setTimeout($timeOut); |
544 | - $out[$node]=$this->client($node)->truncateTable($table); |
|
544 | + $out[$node] = $this->client($node)->truncateTable($table); |
|
545 | 545 | $this->client($node)->setTimeout($def); |
546 | 546 | } |
547 | 547 | return $out; |
@@ -555,15 +555,15 @@ discard block |
||
555 | 555 | */ |
556 | 556 | public function getMasterNodeForTable($database_table) |
557 | 557 | { |
558 | - $list=$this->getTables(true); |
|
558 | + $list = $this->getTables(true); |
|
559 | 559 | |
560 | 560 | if (empty($list[$database_table])) return []; |
561 | 561 | |
562 | 562 | |
563 | - $result=[]; |
|
563 | + $result = []; |
|
564 | 564 | foreach ($list[$database_table] as $node=>$row) |
565 | 565 | { |
566 | - if ($row['is_leader']) $result[]=$node; |
|
566 | + if ($row['is_leader']) $result[] = $node; |
|
567 | 567 | } |
568 | 568 | return $result; |
569 | 569 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | */ |
576 | 576 | public function getNodesByTable($database_table) |
577 | 577 | { |
578 | - $list=$this->getTables(); |
|
578 | + $list = $this->getTables(); |
|
579 | 579 | if (empty($list[$database_table])) { |
580 | 580 | throw new QueryException('Not find :' . $database_table); |
581 | 581 | } |