diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef8514b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/.idea/ +/vendor/ +/dist/server.json diff --git a/dist/rawbt.phar b/dist/rawbt.phar new file mode 100644 index 0000000..c089560 Binary files /dev/null and b/dist/rawbt.phar differ diff --git a/src/server.php b/src/server.php index f47cbd7..2cecedd 100644 --- a/src/server.php +++ b/src/server.php @@ -1,8 +1,17 @@ getData(); echo '> Received request ', "\n"; - $toprint = $data['message']; - $toprint = str_replace("intent:base64,","",$toprint); - $toprint = str_replace("#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;","",$toprint); - $toprint = base64_decode($toprint); + $toprint = $data['message']; + $toprint = str_replace("intent:base64,", "", $toprint); + $toprint = str_replace("#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;", "", $toprint); + $toprint = base64_decode($toprint); - $conf = Config::load('server.json'); + $conf = Config::load('server.json'); - if ($conf->get('PrintConnector.Type') == 'Network') { - set_time_limit($conf->get('PrintConnector.Params.timeout',10)+10); - $connector = new NetworkPrintConnector($conf->get('PrintConnector.Params.ip','127.0.0.1'),$conf->get('PrintConnector.Params.port',9100),$conf->get('PrintConnector.Params.timeout',10)); - } elseif ($conf->get('PrintConnector.Type') == 'Uri') { - $connector = UriPrintConnector::get($conf->get('PrintConnector.Params.uri','tcp://127.0.0.1:9100')); - } elseif ($conf->get('PrintConnector.Type') == 'Cups') { - $connector = CupsPrintConnector::get($conf->get('PrintConnector.Params.dest')); - } elseif ($conf->get('PrintConnector.Type') == 'File') { - $connector = CupsPrintConnector::get($conf->get('PrintConnector.Params.filename')); - } else { - // $conf->get('PrintConnector.Type') == 'Windows' - $connector = new WindowsPrintConnector($conf->get('PrintConnector.Params.dest','LPT1')); - } - $connector -> write($toprint); - $connector -> finalize(); + if ($conf->get('PrintConnector.Type') == 'Network') { + set_time_limit($conf->get('PrintConnector.Params.timeout', 10) + 10); + $connector = new NetworkPrintConnector($conf->get('PrintConnector.Params.ip', '127.0.0.1'), $conf->get('PrintConnector.Params.port', 9100), $conf->get('PrintConnector.Params.timeout', 10)); + } elseif ($conf->get('PrintConnector.Type') == 'Uri') { + $connector = UriPrintConnector::get($conf->get('PrintConnector.Params.uri', 'tcp://127.0.0.1:9100')); + } elseif ($conf->get('PrintConnector.Type') == 'Cups') { + $connector = new CupsPrintConnector($conf->get('PrintConnector.Params.dest')); + } elseif ($conf->get('PrintConnector.Type') == 'File') { + $connector = new FilePrintConnector($conf->get('PrintConnector.Params.filename')); + } else { // 'Windows' + $connector = new WindowsPrintConnector($conf->get('PrintConnector.Params.dest', 'LPT1')); + } + $connector->write($toprint); + $connector->finalize(); echo '> Done print task ', "\n"; return; }); @@ -65,7 +73,6 @@ } catch (Exception $e) { echo '> Error occurred, server stopped. ', $e->getMessage(), "\n"; } - } catch (Exception $e) { echo '> Error: ', $e->getMessage(), "\n"; }