@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | * @param array $params |
29 | 29 | * @return Response |
30 | 30 | */ |
31 | - public function execute(Request $request, $params=[]) |
|
31 | + public function execute(Request $request, $params = []) |
|
32 | 32 | { |
33 | 33 | $connection = $this->getConnection(); |
34 | 34 | //@todo add persistent |
35 | 35 | //@todo add custom headers |
36 | 36 | $conn = $this->_getCurlConnection($connection->getConfig('persistent')); |
37 | - $url = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort(); |
|
37 | + $url = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort(); |
|
38 | 38 | $endpoint = $request->getPath(); |
39 | 39 | $url .= $endpoint; |
40 | - $url = $this->setupURI($url,$request->getQuery()); |
|
40 | + $url = $this->setupURI($url, $request->getQuery()); |
|
41 | 41 | |
42 | 42 | curl_setopt($conn, CURLOPT_URL, $url); |
43 | 43 | curl_setopt($conn, CURLOPT_TIMEOUT, $connection->getTimeout()); |
@@ -47,32 +47,32 @@ discard block |
||
47 | 47 | $method = $request->getMethod(); |
48 | 48 | $headers = $connection->getHeaders(); |
49 | 49 | $headers[] = sprintf('Content-Type: %s', $request->getContentType()); |
50 | - if(!empty($data)) { |
|
50 | + if (!empty($data)) { |
|
51 | 51 | if (is_array($data)) { |
52 | 52 | $content = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
53 | 53 | } else { |
54 | 54 | $content = $data; |
55 | 55 | } |
56 | 56 | curl_setopt($conn, CURLOPT_POSTFIELDS, $content); |
57 | - }else{ |
|
57 | + } else { |
|
58 | 58 | curl_setopt($conn, CURLOPT_POSTFIELDS, ''); |
59 | 59 | } |
60 | 60 | curl_setopt($conn, CURLOPT_CUSTOMREQUEST, $method); |
61 | 61 | curl_setopt($conn, CURLOPT_HTTPHEADER, $headers); |
62 | 62 | |
63 | - if($connection->getConnectTimeout()>0) { |
|
63 | + if ($connection->getConnectTimeout() > 0) { |
|
64 | 64 | curl_setopt($conn, CURLOPT_CONNECTTIMEOUT, $connection->getConnectTimeout()); |
65 | 65 | } |
66 | 66 | |
67 | - if($connection->getConfig('username') !== null && $connection->getConfig('password') !== null) { |
|
67 | + if ($connection->getConfig('username') !== null && $connection->getConfig('password') !== null) { |
|
68 | 68 | curl_setopt($conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
69 | - curl_setopt($conn, CURLOPT_USERPWD, $connection->getConfig('username').":".$connection->getConfig('password')); |
|
69 | + curl_setopt($conn, CURLOPT_USERPWD, $connection->getConfig('username') . ":" . $connection->getConfig('password')); |
|
70 | 70 | } |
71 | - if($connection->getConfig('proxy') !== null) { |
|
71 | + if ($connection->getConfig('proxy') !== null) { |
|
72 | 72 | curl_setopt($conn, CURLOPT_PROXY, $connection->getConfig('proxy')); |
73 | 73 | } |
74 | - if(!empty($connection->getConfig('curl'))) { |
|
75 | - foreach($connection->getConfig('curl') as $k=>$v) { |
|
74 | + if (!empty($connection->getConfig('curl'))) { |
|
75 | + foreach ($connection->getConfig('curl') as $k=>$v) { |
|
76 | 76 | curl_setopt($conn, $k, $v); |
77 | 77 | } |
78 | 78 | |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | $responseString = \ob_get_clean(); |
84 | 84 | $end = microtime(true); |
85 | 85 | $errorno = curl_errno($conn); |
86 | - $status = curl_getinfo($conn,CURLINFO_HTTP_CODE); |
|
87 | - if(isset($params['responseClass'])) { |
|
86 | + $status = curl_getinfo($conn, CURLINFO_HTTP_CODE); |
|
87 | + if (isset($params['responseClass'])) { |
|
88 | 88 | $responseClass = $params['responseClass']; |
89 | - $response = new $responseClass($responseString,$status); |
|
90 | - }else{ |
|
91 | - $response = new Response($responseString,$status); |
|
89 | + $response = new $responseClass($responseString, $status); |
|
90 | + } else { |
|
91 | + $response = new Response($responseString, $status); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | $time = $end-$start; |
@@ -99,27 +99,27 @@ discard block |
||
99 | 99 | 'body' => $request->getBody() |
100 | 100 | ]); |
101 | 101 | //hard error |
102 | - if($errorno>0) { |
|
102 | + if ($errorno > 0) { |
|
103 | 103 | $error = curl_error($conn); |
104 | 104 | self::$_curl = false; |
105 | - throw new ConnectionException($error,$request); |
|
105 | + throw new ConnectionException($error, $request); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
109 | - $this->_logger->debug('Request body:',[ |
|
109 | + $this->_logger->debug('Request body:', [ |
|
110 | 110 | 'connection' => $connection->getConfig(), |
111 | 111 | 'payload'=> $request->getBody() |
112 | 112 | ]); |
113 | - $this->_logger->info('Request:',[ |
|
113 | + $this->_logger->info('Request:', [ |
|
114 | 114 | 'url' => $url, |
115 | 115 | 'status' => $status, |
116 | 116 | 'time' => $time |
117 | 117 | ] |
118 | 118 | ); |
119 | - $this->_logger->debug('Response body:',[json_decode($responseString,true)]); |
|
119 | + $this->_logger->debug('Response body:', [json_decode($responseString, true)]); |
|
120 | 120 | //soft error |
121 | - if($response->hasError()) { |
|
122 | - $this->_logger->error('Response error:',[$response->getError()]); |
|
121 | + if ($response->hasError()) { |
|
122 | + $this->_logger->error('Response error:', [$response->getError()]); |
|
123 | 123 | throw new ResponseException($request, $response); |
124 | 124 | } |
125 | 125 | return $response; |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | * @param bool $persistent |
130 | 130 | * @return false|resource |
131 | 131 | */ |
132 | - protected function _getCurlConnection(bool $persistent=true) |
|
132 | + protected function _getCurlConnection(bool $persistent = true) |
|
133 | 133 | { |
134 | - if(!$persistent || !self::$_curl) { |
|
134 | + if (!$persistent || !self::$_curl) { |
|
135 | 135 | self::$_curl = curl_init(); |
136 | 136 | } |
137 | 137 | return self::$_curl; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public function getTransportHandler(LoggerInterface $logger) |
175 | 175 | { |
176 | - return Transport::create($this->getTransport(), $this,$logger); |
|
176 | + return Transport::create($this->getTransport(), $this, $logger); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -192,9 +192,9 @@ discard block |
||
192 | 192 | * @param string|null |
193 | 193 | * @return mixed|null |
194 | 194 | */ |
195 | - public function getConfig($key = null) |
|
195 | + public function getConfig($key = null) |
|
196 | 196 | { |
197 | - if($key === null) { |
|
197 | + if ($key === null) { |
|
198 | 198 | return $this->config; |
199 | 199 | } |
200 | 200 | return $this->config[$key] ?? null; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | { |
23 | 23 | if (isset($this->_index)) { |
24 | 24 | $columns = []; |
25 | - if(isset($params['columns'] )) { |
|
25 | + if (isset($params['columns'])) { |
|
26 | 26 | foreach ($params['columns'] as $name => $settings) { |
27 | 27 | $column = $name . ' ' . $settings['type']; |
28 | 28 | if (isset($settings['options']) && count($settings['options']) > 0) { |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | } |
33 | 33 | } |
34 | 34 | $options = ""; |
35 | - if(isset($params['settings'] )) { |
|
36 | - foreach($params['settings'] as $name=>$value) { |
|
37 | - $options.=" ".$name." = ".$value; |
|
35 | + if (isset($params['settings'])) { |
|
36 | + foreach ($params['settings'] as $name=>$value) { |
|
37 | + $options .= " " . $name . " = " . $value; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | } |
41 | - return parent::setBody(['query' => "CREATE TABLE ".$this->_index. |
|
42 | - (count($columns)>0?"(".implode(",",$columns).")":" ") |
|
41 | + return parent::setBody(['query' => "CREATE TABLE " . $this->_index . |
|
42 | + (count($columns) > 0 ? "(" . implode(",", $columns) . ")" : " ") |
|
43 | 43 | .$options]); |
44 | 44 | } |
45 | 45 | throw new RuntimeException('Index name is missing.'); |
@@ -15,8 +15,8 @@ |
||
15 | 15 | |
16 | 16 | public function setBody($params = null) |
17 | 17 | { |
18 | - if(isset($params['name'], $params['type']) && $params['library']) { |
|
19 | - return parent::setBody(['query' => "CREATE PLUGIN " . $params['name']." TYPE ".strtoupper($params['type']). " SONAME ".$params['library']]); |
|
18 | + if (isset($params['name'], $params['type']) && $params['library']) { |
|
19 | + return parent::setBody(['query' => "CREATE PLUGIN " . $params['name'] . " TYPE " . strtoupper($params['type']) . " SONAME " . $params['library']]); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | throw new RuntimeException('Incomplete request for /nodes/createplugin'); |
@@ -12,14 +12,14 @@ |
||
12 | 12 | { |
13 | 13 | $response = parent::getResponse(); |
14 | 14 | |
15 | - if(isset($response['columns'], $response['data'])) |
|
15 | + if (isset($response['columns'], $response['data'])) |
|
16 | 16 | { |
17 | - $data=[]; |
|
18 | - $names = array_walk($response['columns'], static function(&$value, $key) {$value= array_keys($value)[0];}); |
|
19 | - foreach($response['data'] as $property) { |
|
20 | - if(count($response['columns'])>2) { |
|
17 | + $data = []; |
|
18 | + $names = array_walk($response['columns'], static function(&$value, $key) {$value = array_keys($value)[0]; }); |
|
19 | + foreach ($response['data'] as $property) { |
|
20 | + if (count($response['columns']) > 2) { |
|
21 | 21 | $data[array_shift($property)] = $property; |
22 | - }else{ |
|
22 | + } else { |
|
23 | 23 | $data[$property[$response['columns'][0]]] = $property[$response['columns'][1]]; |
24 | 24 | } |
25 | 25 | } |