@@ -26,8 +26,8 @@ |
||
| 26 | 26 | |
| 27 | 27 | $options = new TS3Config($options); |
| 28 | 28 | |
| 29 | -$logger = new class() extends AbstractLogger{ |
|
| 30 | - public function log($level, $message, array $context = []){ |
|
| 29 | +$logger = new class() extends AbstractLogger { |
|
| 30 | + public function log($level, $message, array $context = []) { |
|
| 31 | 31 | echo sprintf('[%s][%s] %s', date('Y-m-d H:i:s'), substr($level, 0, 4), trim($message))."\n"; |
| 32 | 32 | } |
| 33 | 33 | }; |
@@ -43,17 +43,17 @@ |
||
| 43 | 43 | function ts3RenderChannels(array $channels, array $clients, int $cid = null, int $depth = null):string{ |
| 44 | 44 | $str = ''; |
| 45 | 45 | |
| 46 | - foreach($channels as $channel){ |
|
| 46 | + foreach ($channels as $channel) { |
|
| 47 | 47 | |
| 48 | - if($channel->pid === null){ |
|
| 48 | + if ($channel->pid === null) { |
|
| 49 | 49 | $depth = 0; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if($channel->pid === $cid){ |
|
| 52 | + if ($channel->pid === $cid) { |
|
| 53 | 53 | $str .= str_repeat(' ', $depth).$channel->channel_name."\n"; |
| 54 | 54 | |
| 55 | - foreach($clients as $client){ |
|
| 56 | - if($client->cid === $channel->cid){ |
|
| 55 | + foreach ($clients as $client) { |
|
| 56 | + if ($client->cid === $channel->cid) { |
|
| 57 | 57 | $str .= str_repeat(' ', $depth).' - '.$client->client_nickname."\n"; |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -10,7 +10,7 @@ |
||
| 10 | 10 | |
| 11 | 11 | namespace chillerlan\Teamspeak; |
| 12 | 12 | |
| 13 | -trait TS3ConfigTrait{ |
|
| 13 | +trait TS3ConfigTrait { |
|
| 14 | 14 | |
| 15 | 15 | protected string $host = 'localhost'; |
| 16 | 16 | protected int $port = 10011; |
@@ -19,6 +19,6 @@ |
||
| 19 | 19 | * @property string $query_user |
| 20 | 20 | * @property string $query_password |
| 21 | 21 | */ |
| 22 | -class TS3Config extends SettingsContainerAbstract{ |
|
| 22 | +class TS3Config extends SettingsContainerAbstract { |
|
| 23 | 23 | use TS3ConfigTrait; |
| 24 | 24 | } |
@@ -12,4 +12,4 @@ |
||
| 12 | 12 | |
| 13 | 13 | use Exception; |
| 14 | 14 | |
| 15 | -class TS3ClientException extends Exception{} |
|
| 15 | +class TS3ClientException extends Exception {} |
|
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @property array $data |
| 21 | 21 | * @property \stdClass $error |
| 22 | 22 | */ |
| 23 | -final class TS3Response{ |
|
| 23 | +final class TS3Response { |
|
| 24 | 24 | |
| 25 | 25 | private string $commandline; |
| 26 | 26 | private array $commandlist = []; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * TS3Response constructor. |
| 33 | 33 | */ |
| 34 | - public function __construct(string $command, string $raw){ |
|
| 34 | + public function __construct(string $command, string $raw) { |
|
| 35 | 35 | $this->commandline = $command; |
| 36 | 36 | $this->raw = $raw; |
| 37 | 37 | |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | /** |
| 46 | 46 | * @return mixed|null |
| 47 | 47 | */ |
| 48 | - public function __get(string $property){ |
|
| 48 | + public function __get(string $property) { |
|
| 49 | 49 | |
| 50 | - if(property_exists($this, $property)){ |
|
| 50 | + if (property_exists($this, $property)) { |
|
| 51 | 51 | return $this->{$property}; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $this->commandlist = array_map(fn($c) => trim($c, "\r\n\t- "), explode(' ', trim($this->commandline))); |
| 62 | 62 | $this->data = array_map(fn($d) => trim($d), explode("\n", trim($this->raw))); |
| 63 | 63 | |
| 64 | - if(preg_match('/^(:?error id=)(?P<id>[\d]+)(:? msg=)(?P<msg>.*)$/isU', array_pop($this->data), $match) > 0){ |
|
| 64 | + if (preg_match('/^(:?error id=)(?P<id>[\d]+)(:? msg=)(?P<msg>.*)$/isU', array_pop($this->data), $match) > 0) { |
|
| 65 | 65 | $this->error->id = (int)$match['id']; |
| 66 | 66 | $this->error->msg = $match['msg']; |
| 67 | 67 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | /** |
| 72 | 72 | * @return \stdClass[]|\stdClass |
| 73 | 73 | */ |
| 74 | - public function parseList(){ |
|
| 74 | + public function parseList() { |
|
| 75 | 75 | return self::parse_list($this->data[0] ?? ''); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | $str = explode(' ', $str); |
| 89 | 89 | $r = new stdClass; |
| 90 | 90 | |
| 91 | - foreach($str as $pair){ |
|
| 91 | + foreach ($str as $pair) { |
|
| 92 | 92 | $kv = explode('=', $pair); |
| 93 | 93 | $val = isset($kv[1]) && !empty($kv[1]) ? self::unescape($kv[1]) : null; |
| 94 | 94 | |
| 95 | - if(is_numeric($val)){ |
|
| 95 | + if (is_numeric($val)) { |
|
| 96 | 96 | $val += 0; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | * |
| 112 | 112 | * @return \stdClass[]|\stdClass |
| 113 | 113 | */ |
| 114 | - public static function parse_list(string $str){ |
|
| 114 | + public static function parse_list(string $str) { |
|
| 115 | 115 | |
| 116 | - if(strpos($str, '|') !== false){ |
|
| 116 | + if (strpos($str, '|') !== false) { |
|
| 117 | 117 | $str = explode('|', $str); |
| 118 | 118 | $arr = []; |
| 119 | 119 | |
| 120 | - foreach($str as $line){ |
|
| 120 | + foreach ($str as $line) { |
|
| 121 | 121 | $arr[] = self::parse_kv($line); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | use function fclose, fsockopen, fwrite, is_resource, restore_error_handler, |
| 18 | 18 | set_error_handler, stream_get_contents, stream_set_timeout, trim; |
| 19 | 19 | |
| 20 | -class TS3Client implements LoggerAwareInterface{ |
|
| 20 | +class TS3Client implements LoggerAwareInterface { |
|
| 21 | 21 | use LoggerAwareTrait; |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param \chillerlan\Settings\SettingsContainerInterface $config |
| 37 | 37 | * @param \Psr\Log\LoggerInterface|null $logger |
| 38 | 38 | */ |
| 39 | - public function __construct(SettingsContainerInterface $config, LoggerInterface $logger = null){ |
|
| 39 | + public function __construct(SettingsContainerInterface $config, LoggerInterface $logger = null) { |
|
| 40 | 40 | $this->config = $config; |
| 41 | 41 | $this->logger = $logger ?? new NullLogger; |
| 42 | 42 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | /** |
| 45 | 45 | * |
| 46 | 46 | */ |
| 47 | - public function __destruct(){ |
|
| 47 | + public function __destruct() { |
|
| 48 | 48 | $this->disconnect(); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,19 +53,19 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function connect():TS3Client{ |
| 55 | 55 | |
| 56 | - if(is_resource($this->socket)){ |
|
| 56 | + if (is_resource($this->socket)) { |
|
| 57 | 57 | return $this; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** @phan-suppress-next-line PhanTypeMismatchArgumentInternal stupid inconsistent callables... */ |
| 61 | - set_error_handler(function($severity, $msg, $file, $line){ |
|
| 61 | + set_error_handler(function($severity, $msg, $file, $line) { |
|
| 62 | 62 | throw new ErrorException($msg, 0, $severity, $file, $line); |
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | - try{ |
|
| 65 | + try { |
|
| 66 | 66 | $this->socket = fsockopen($this->config->host, $this->config->port); |
| 67 | 67 | } |
| 68 | - catch(Throwable $e){ |
|
| 68 | + catch (Throwable $e) { |
|
| 69 | 69 | throw new TS3ClientException('could not connect: #'.$e->getMessage()); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function disconnect():TS3Client{ |
| 85 | 85 | |
| 86 | - if(is_resource($this->socket)){ |
|
| 86 | + if (is_resource($this->socket)) { |
|
| 87 | 87 | $this->send('logout'); |
| 88 | 88 | $this->send('quit'); |
| 89 | 89 | |
@@ -105,17 +105,17 @@ discard block |
||
| 105 | 105 | public function send(string $command):TS3Response{ |
| 106 | 106 | $this->logger->debug('command: '.$command); |
| 107 | 107 | |
| 108 | - if(!$this->socket){ |
|
| 108 | + if (!$this->socket) { |
|
| 109 | 109 | throw new TS3ClientException('not connected'); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $command = trim($command); |
| 113 | 113 | |
| 114 | - if(empty($command)){ |
|
| 114 | + if (empty($command)) { |
|
| 115 | 115 | throw new TS3ClientException('empty command'); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if(fwrite($this->socket, $command."\n") !== false){ |
|
| 118 | + if (fwrite($this->socket, $command."\n") !== false) { |
|
| 119 | 119 | $response = stream_get_contents($this->socket); |
| 120 | 120 | |
| 121 | 121 | $this->logger->debug('response: '.$response); |
@@ -64,8 +64,7 @@ |
||
| 64 | 64 | |
| 65 | 65 | try{ |
| 66 | 66 | $this->socket = fsockopen($this->config->host, $this->config->port); |
| 67 | - } |
|
| 68 | - catch(Throwable $e){ |
|
| 67 | + } catch(Throwable $e){ |
|
| 69 | 68 | throw new TS3ClientException('could not connect: #'.$e->getMessage()); |
| 70 | 69 | } |
| 71 | 70 | |