@@ -14,6 +14,6 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __toString() |
| 16 | 16 | { |
| 17 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 17 | + return __CLASS__.": [{$this->code}]: {$this->message}\n"; |
|
| 18 | 18 | } |
| 19 | 19 | } |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __toString() |
| 16 | 16 | { |
| 17 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 17 | + return __CLASS__.": [{$this->code}]: {$this->message}\n"; |
|
| 18 | 18 | } |
| 19 | 19 | } |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | { |
| 15 | 15 | public function __toString() |
| 16 | 16 | { |
| 17 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 17 | + return __CLASS__.": [{$this->code}]: {$this->message}\n"; |
|
| 18 | 18 | } |
| 19 | 19 | } |
@@ -97,9 +97,9 @@ discard block |
||
| 97 | 97 | * @var array |
| 98 | 98 | */ |
| 99 | 99 | private $validNamespaces = [ |
| 100 | - 'miot-spec', // 小米定义的规范 |
|
| 101 | - 'miot-spec-v2', // 小米定义的规范版本2 |
|
| 102 | - 'bluetooth-spec', // 蓝牙联盟定义的规范 |
|
| 100 | + 'miot-spec', // 小米定义的规范 |
|
| 101 | + 'miot-spec-v2', // 小米定义的规范版本2 |
|
| 102 | + 'bluetooth-spec', // 蓝牙联盟定义的规范 |
|
| 103 | 103 | ]; |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | * @var array |
| 123 | 123 | */ |
| 124 | 124 | private $validTypes = [ |
| 125 | - 'property', // 属性 |
|
| 126 | - 'action', // 方法 |
|
| 127 | - 'event', // 事件 |
|
| 128 | - 'service', // 服务 |
|
| 129 | - 'device', // 设备 |
|
| 125 | + 'property', // 属性 |
|
| 126 | + 'action', // 方法 |
|
| 127 | + 'event', // 事件 |
|
| 128 | + 'service', // 服务 |
|
| 129 | + 'device', // 设备 |
|
| 130 | 130 | ]; |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -410,14 +410,14 @@ discard block |
||
| 410 | 410 | $baseUrn = ''; |
| 411 | 411 | |
| 412 | 412 | foreach ($this->baseColumns as $column) { |
| 413 | - $fncName = 'get' . ucfirst( |
|
| 414 | - preg_replace_callback('/_([a-zA-Z])/', function ($match) { |
|
| 413 | + $fncName = 'get'.ucfirst( |
|
| 414 | + preg_replace_callback('/_([a-zA-Z])/', function($match) { |
|
| 415 | 415 | return strtoupper($match[1]); |
| 416 | 416 | }, $column) |
| 417 | 417 | ); |
| 418 | 418 | |
| 419 | 419 | if (method_exists($this, $fncName) && $this->{$fncName}()) { |
| 420 | - $baseUrn .= $this->delimiter . $this->{$fncName}(); |
|
| 420 | + $baseUrn .= $this->delimiter.$this->{$fncName}(); |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | |
@@ -444,14 +444,14 @@ discard block |
||
| 444 | 444 | $expression = ''; |
| 445 | 445 | |
| 446 | 446 | foreach ($this->columns as $column) { |
| 447 | - $fncName = 'get' . ucfirst( |
|
| 448 | - preg_replace_callback('/_([a-zA-Z])/', function ($match) { |
|
| 447 | + $fncName = 'get'.ucfirst( |
|
| 448 | + preg_replace_callback('/_([a-zA-Z])/', function($match) { |
|
| 449 | 449 | return strtoupper($match[1]); |
| 450 | 450 | }, $column) |
| 451 | 451 | ); |
| 452 | 452 | |
| 453 | 453 | if (method_exists($this, $fncName) && $this->{$fncName}()) { |
| 454 | - $expression .= $this->delimiter . $this->{$fncName}(); |
|
| 454 | + $expression .= $this->delimiter.$this->{$fncName}(); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | $parses = explode($this->delimiter, $this->original); |
| 471 | 471 | |
| 472 | 472 | foreach ($this->columns as $index => $column) { |
| 473 | - $fncName = 'set' . ucfirst( |
|
| 474 | - preg_replace_callback('/_([a-zA-Z])/', function ($match) { |
|
| 473 | + $fncName = 'set'.ucfirst( |
|
| 474 | + preg_replace_callback('/_([a-zA-Z])/', function($match) { |
|
| 475 | 475 | return strtoupper($match[1]); |
| 476 | 476 | }, $column) |
| 477 | 477 | ); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public static function properties() |
| 68 | 68 | { |
| 69 | - $file = self::SPEC . DIRECTORY_SEPARATOR . self::PROPERTIES; |
|
| 69 | + $file = self::SPEC.DIRECTORY_SEPARATOR.self::PROPERTIES; |
|
| 70 | 70 | |
| 71 | 71 | return self::__instances($file); |
| 72 | 72 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public static function actions() |
| 80 | 80 | { |
| 81 | - $file = self::SPEC . DIRECTORY_SEPARATOR . self::ACTIONS; |
|
| 81 | + $file = self::SPEC.DIRECTORY_SEPARATOR.self::ACTIONS; |
|
| 82 | 82 | |
| 83 | 83 | return self::__instances($file); |
| 84 | 84 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public static function events() |
| 92 | 92 | { |
| 93 | - $file = self::SPEC . DIRECTORY_SEPARATOR . self::EVENTS; |
|
| 93 | + $file = self::SPEC.DIRECTORY_SEPARATOR.self::EVENTS; |
|
| 94 | 94 | |
| 95 | 95 | return self::__instances($file); |
| 96 | 96 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public static function services() |
| 104 | 104 | { |
| 105 | - $file = self::SPEC . DIRECTORY_SEPARATOR . self::SERVICES; |
|
| 105 | + $file = self::SPEC.DIRECTORY_SEPARATOR.self::SERVICES; |
|
| 106 | 106 | |
| 107 | 107 | return self::__instances($file); |
| 108 | 108 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public static function devices() |
| 116 | 116 | { |
| 117 | - $file = self::SPEC . DIRECTORY_SEPARATOR . self::DEVICES; |
|
| 117 | + $file = self::SPEC.DIRECTORY_SEPARATOR.self::DEVICES; |
|
| 118 | 118 | |
| 119 | 119 | return self::__instances($file); |
| 120 | 120 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public static function instance($type) |
| 128 | 128 | { |
| 129 | - $file = self::INSTANCE . DIRECTORY_SEPARATOR . $type; |
|
| 129 | + $file = self::INSTANCE.DIRECTORY_SEPARATOR.$type; |
|
| 130 | 130 | $uri = self::INSTANCE; |
| 131 | 131 | $params = [ |
| 132 | 132 | 'type' => $type, |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | public static function property($type) |
| 146 | 146 | { |
| 147 | 147 | $type = self::getBaseType($type); |
| 148 | - $file = self::PROPERTY . DIRECTORY_SEPARATOR . $type; |
|
| 149 | - $uri = self::SPEC . DIRECTORY_SEPARATOR . self::PROPERTY; |
|
| 148 | + $file = self::PROPERTY.DIRECTORY_SEPARATOR.$type; |
|
| 149 | + $uri = self::SPEC.DIRECTORY_SEPARATOR.self::PROPERTY; |
|
| 150 | 150 | $params = [ |
| 151 | 151 | 'type' => $type, |
| 152 | 152 | ]; |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | public static function action($type) |
| 165 | 165 | { |
| 166 | 166 | $type = self::getBaseType($type); |
| 167 | - $file = self::ACTION . DIRECTORY_SEPARATOR . $type; |
|
| 168 | - $uri = self::SPEC . DIRECTORY_SEPARATOR . self::ACTION; |
|
| 167 | + $file = self::ACTION.DIRECTORY_SEPARATOR.$type; |
|
| 168 | + $uri = self::SPEC.DIRECTORY_SEPARATOR.self::ACTION; |
|
| 169 | 169 | $params = [ |
| 170 | 170 | 'type' => $type, |
| 171 | 171 | ]; |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | public static function event($type) |
| 184 | 184 | { |
| 185 | 185 | $type = self::getBaseType($type); |
| 186 | - $file = self::EVENT . DIRECTORY_SEPARATOR . $type; |
|
| 187 | - $uri = self::SPEC . DIRECTORY_SEPARATOR . self::EVENT; |
|
| 186 | + $file = self::EVENT.DIRECTORY_SEPARATOR.$type; |
|
| 187 | + $uri = self::SPEC.DIRECTORY_SEPARATOR.self::EVENT; |
|
| 188 | 188 | $params = [ |
| 189 | 189 | 'type' => $type, |
| 190 | 190 | ]; |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | public static function service($type) |
| 203 | 203 | { |
| 204 | 204 | $type = self::getBaseType($type); |
| 205 | - $file = self::SERVICE . DIRECTORY_SEPARATOR . $type; |
|
| 206 | - $uri = self::SPEC . DIRECTORY_SEPARATOR . self::SERVICE; |
|
| 205 | + $file = self::SERVICE.DIRECTORY_SEPARATOR.$type; |
|
| 206 | + $uri = self::SPEC.DIRECTORY_SEPARATOR.self::SERVICE; |
|
| 207 | 207 | $params = [ |
| 208 | 208 | 'type' => $type, |
| 209 | 209 | ]; |
@@ -221,8 +221,8 @@ discard block |
||
| 221 | 221 | public static function device($type) |
| 222 | 222 | { |
| 223 | 223 | $type = self::getBaseType($type); |
| 224 | - $file = self::DEVICE . DIRECTORY_SEPARATOR . $type; |
|
| 225 | - $uri = self::SPEC . DIRECTORY_SEPARATOR . self::DEVICE; |
|
| 224 | + $file = self::DEVICE.DIRECTORY_SEPARATOR.$type; |
|
| 225 | + $uri = self::SPEC.DIRECTORY_SEPARATOR.self::DEVICE; |
|
| 226 | 226 | $params = [ |
| 227 | 227 | 'type' => $type, |
| 228 | 228 | ]; |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | { |
| 301 | 301 | $http = new Request( |
| 302 | 302 | self::$host, |
| 303 | - '/' . self::$namespaces . '/' . $uri, |
|
| 303 | + '/'.self::$namespaces.'/'.$uri, |
|
| 304 | 304 | self::$prot, |
| 305 | 305 | true, |
| 306 | 306 | self::$timeout |
@@ -132,7 +132,7 @@ |
||
| 132 | 132 | foreach ($services as $index => $service) { |
| 133 | 133 | if (!empty($this->getPropertiesNode($index))) { |
| 134 | 134 | foreach ($this->getPropertiesNode($index) as $i => $item) { |
| 135 | - $propertiesNodes[($index . '.' . $i)] = $item; |
|
| 135 | + $propertiesNodes[($index.'.'.$i)] = $item; |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | // Set additional headers. |
| 310 | 310 | $headers = []; |
| 311 | 311 | foreach ($this->headers as $name => $val) { |
| 312 | - $headers[] = $name . ': ' . $val; |
|
| 312 | + $headers[] = $name.': '.$val; |
|
| 313 | 313 | } |
| 314 | 314 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
| 315 | 315 | // Do stuff it it's HTTPS/SSL. |
@@ -326,13 +326,13 @@ discard block |
||
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | // Build and set URL. |
| 329 | - $url = $protocol . '://' . $host . $uri . $query; |
|
| 329 | + $url = $protocol.'://'.$host.$uri.$query; |
|
| 330 | 330 | curl_setopt($ch, CURLOPT_URL, $url); |
| 331 | 331 | curl_setopt($ch, CURLOPT_PORT, $port); |
| 332 | 332 | // Add any authentication to the request. |
| 333 | 333 | // Currently supports only HTTP Basic Auth. |
| 334 | 334 | if ($this->useBasicAuth === true) { |
| 335 | - curl_setopt($ch, CURLOPT_USERPWD, $this->authUsername . ':' . $this->authPassword); |
|
| 335 | + curl_setopt($ch, CURLOPT_USERPWD, $this->authUsername.':'.$this->authPassword); |
|
| 336 | 336 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
| 337 | 337 | } |
| 338 | 338 | // Execute! |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | if (!is_string($val)) { |
| 366 | 366 | $val = json_encode($val); |
| 367 | 367 | } |
| 368 | - $dataArray[] = urlencode($key) . '=' . urlencode($val); |
|
| 368 | + $dataArray[] = urlencode($key).'='.urlencode($val); |
|
| 369 | 369 | } |
| 370 | 370 | } |
| 371 | 371 | |
@@ -415,15 +415,15 @@ discard block |
||
| 415 | 415 | if ($this->useBasicAuth === true) { |
| 416 | 416 | $this->setHeader( |
| 417 | 417 | 'Authorization', |
| 418 | - 'Basic ' . base64_encode($this->authUsername . ':' . $this->authPassword) |
|
| 418 | + 'Basic '.base64_encode($this->authUsername.':'.$this->authPassword) |
|
| 419 | 419 | ); |
| 420 | 420 | } |
| 421 | 421 | $headers = $this->headers; |
| 422 | 422 | $req = ''; |
| 423 | - $req .= $type . ' ' . $uri . (isset($get_data) ? '?' . $get_data : '') . ' HTTP/' . $HTTPVersion . $crlf; |
|
| 424 | - $req .= 'Host: ' . $host . $crlf; |
|
| 423 | + $req .= $type.' '.$uri.(isset($get_data) ? '?'.$get_data : '').' HTTP/'.$HTTPVersion.$crlf; |
|
| 424 | + $req .= 'Host: '.$host.$crlf; |
|
| 425 | 425 | foreach ($headers as $header => $content) { |
| 426 | - $req .= $header . ': ' . $content . $crlf; |
|
| 426 | + $req .= $header.': '.$content.$crlf; |
|
| 427 | 427 | } |
| 428 | 428 | $req .= $crlf; |
| 429 | 429 | if ($type === 'POST') { |
@@ -433,14 +433,14 @@ discard block |
||
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | // Construct hostname. |
| 436 | - $fsock_host = ($port == 443 ? 'ssl://' : '') . $host; |
|
| 436 | + $fsock_host = ($port == 443 ? 'ssl://' : '').$host; |
|
| 437 | 437 | |
| 438 | 438 | // Open socket. |
| 439 | 439 | $httpreq = @fsockopen($fsock_host, $port, $errno, $errstr, 30); |
| 440 | 440 | |
| 441 | 441 | // Handle an error. |
| 442 | 442 | if (!$httpreq) { |
| 443 | - $this->error = $errno . ': ' . $errstr; |
|
| 443 | + $this->error = $errno.': '.$errstr; |
|
| 444 | 444 | |
| 445 | 445 | return false; |
| 446 | 446 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | // Extract the headers and the responseText. |
| 457 | - list($headers, $responseText) = explode($crlf . $crlf, $rsp); |
|
| 457 | + list($headers, $responseText) = explode($crlf.$crlf, $rsp); |
|
| 458 | 458 | |
| 459 | 459 | // Store the finalized response. |
| 460 | 460 | $this->response = $rsp; |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | if (is_null($lastError)) { |
| 49 | 49 | return $array; |
| 50 | 50 | } else { |
| 51 | - throw new JsonException($lastError['message'] . ' ' . $file); |
|
| 51 | + throw new JsonException($lastError['message'].' '.$file); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | if (!mkdir($path, 0755, true)) { |
| 69 | 69 | $message = 'Could not create directory in'; |
| 70 | 70 | |
| 71 | - throw new JsonException($message . ' ' . $path); |
|
| 71 | + throw new JsonException($message.' '.$path); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | if (file_put_contents($file, $json) === false) { |
| 88 | 88 | $message = 'Could not create file in'; |
| 89 | 89 | |
| 90 | - throw new JsonException($message . ' ' . $file); |
|
| 90 | + throw new JsonException($message.' '.$file); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | try { |
| 30 | 30 | $file = str_replace(':', '_', $file); |
| 31 | - $items = JsonLoader::fileToArray(self::getCacheDir() . $file . self::SUFFIX); |
|
| 31 | + $items = JsonLoader::fileToArray(self::getCacheDir().$file.self::SUFFIX); |
|
| 32 | 32 | |
| 33 | 33 | if (!empty($items) && !isset($items['error-code'])) { |
| 34 | 34 | return self::make($items); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | try { |
| 54 | 54 | $file = str_replace(':', '_', $file); |
| 55 | - $items = JsonLoader::dataToFile($data, self::getCacheDir() . $file . self::SUFFIX); |
|
| 55 | + $items = JsonLoader::dataToFile($data, self::getCacheDir().$file.self::SUFFIX); |
|
| 56 | 56 | if (!empty($items) && !isset($items['error-code'])) { |
| 57 | 57 | return self::make($items); |
| 58 | 58 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | try { |
| 77 | 77 | $file = str_replace(':', '_', $file); |
| 78 | - $items = JsonLoader::arrayToFile($array, self::getCacheDir() . $file . self::SUFFIX); |
|
| 78 | + $items = JsonLoader::arrayToFile($array, self::getCacheDir().$file.self::SUFFIX); |
|
| 79 | 79 | if (!empty($items) && !isset($items['error-code'])) { |
| 80 | 80 | return self::make($items); |
| 81 | 81 | } |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public static function getCacheDir() |
| 95 | 95 | { |
| 96 | - return dirname(dirname(dirname(__DIR__))) . |
|
| 97 | - DIRECTORY_SEPARATOR . |
|
| 98 | - self::CACHE_DIR . |
|
| 96 | + return dirname(dirname(dirname(__DIR__))). |
|
| 97 | + DIRECTORY_SEPARATOR. |
|
| 98 | + self::CACHE_DIR. |
|
| 99 | 99 | DIRECTORY_SEPARATOR; |
| 100 | 100 | } |
| 101 | 101 | } |