From 3509f77cd06fa6f6c3f5916153855a8a9e27bb53 Mon Sep 17 00:00:00 2001 From: oNeDaL Date: Thu, 14 Dec 2017 10:37:37 +0100 Subject: [PATCH 01/16] Set SMB2 as default highest allowed protocol --- .../PrintConnectors/WindowsPrintConnector.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php index 21ef982e..28d6f806 100644 --- a/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php @@ -193,7 +193,7 @@ protected function finalizeLinux($data) if ($this -> userPassword == null) { // No password $command = sprintf( - "smbclient %s -U %s -c %s -N", + "smbclient %s -U %s -c %s -N -m SMB2", escapeshellarg($device), escapeshellarg($user), escapeshellarg("print -") @@ -202,14 +202,14 @@ protected function finalizeLinux($data) } else { // With password $command = sprintf( - "smbclient %s %s -U %s -c %s", + "smbclient %s %s -U %s -c %s -m SMB2", escapeshellarg($device), escapeshellarg($this -> userPassword), escapeshellarg($user), escapeshellarg("print -") ); $redactedCommand = sprintf( - "smbclient %s %s -U %s -c %s", + "smbclient %s %s -U %s -c %s -m SMB2", escapeshellarg($device), escapeshellarg("*****"), escapeshellarg($user), @@ -219,7 +219,7 @@ protected function finalizeLinux($data) } else { // No authentication information at all $command = sprintf( - "smbclient %s -c %s -N", + "smbclient %s -c %s -N -m SMB2", escapeshellarg($device), escapeshellarg("print -") ); @@ -242,7 +242,7 @@ protected function finalizeMac($data) { throw new Exception("Mac printing not implemented."); } - + /** * Send data to printer -- platform-specific Windows code. * @@ -298,7 +298,7 @@ protected function finalizeWin($data) } } } - + /** * @return string Current platform. Separated out for testing purposes. */ @@ -312,7 +312,7 @@ protected function getCurrentPlatform() } return self::PLATFORM_LINUX; } - + /* (non-PHPdoc) * @see PrintConnector::read() */ @@ -321,7 +321,7 @@ public function read($len) /* Two-way communication is not supported */ return false; } - + /** * Run a command, pass it data, and retrieve its return value, standard output, and standard error. * @@ -359,7 +359,7 @@ protected function runCommand($command, &$outputStr, &$errorStr, $inputStr = nul return -1; } } - + /** * Copy a file. Separated out so that nothing is actually printed during test runs. * @@ -371,7 +371,7 @@ protected function runCopy($from, $to) { return copy($from, $to); } - + /** * Write data to a file. Separated out so that nothing is actually printed during test runs. * From 748e6a01653c71b8cd00adb0bb06aeb81fd5a093 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 01:40:52 +1100 Subject: [PATCH 02/16] add UriPrintConnector from evsar3 #314 --- .../PrintConnectors/UriPrintConnector.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php diff --git a/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php new file mode 100644 index 00000000..31813290 --- /dev/null +++ b/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php @@ -0,0 +1,50 @@ + Date: Tue, 13 Mar 2018 01:56:02 +1100 Subject: [PATCH 03/16] readme updates --- .travis.yml | 1 + README.md | 21 ++------------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index bd9dc206..234e0c8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ php: - 5.6 - 7.0 - 7.1 + - 7.2 - nightly matrix: diff --git a/README.md b/README.md index a39520c7..e7ea8048 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ require __DIR__ . '/vendor/mike42/escpos-php/autoload.php'; To maintain compatibility with as many systems as possible, this driver has few hard dependencies: -- PHP 5.3 or above +- PHP 5.4 or above. - `mbstring` extension, since the driver accepts UTF-8 encoding. It is also suggested that you install either `imagick` or `gd`, so that you can @@ -531,7 +531,7 @@ This code is MIT licensed, and you are encouraged to contribute any modification For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP exensions, and install `composer`. -The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.3, 5.4, 5.5, 5.7, 7, and HHVM. Earlier versions of PHP are not supported. +The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.4, 5.5, 5.6, 7.0, 7.2 and 7.2. Earlier versions of PHP are not supported in current releases. Fetch a copy of this code and load dependencies with composer: @@ -552,20 +552,3 @@ The developer docs are build with [doxygen](https://github.com/doxygen/doxygen). make -C doc clean && make -C doc Pull requests and bug reports welcome. - - - - From 73ec3f836e31a23f1eee5b4ccc477f752a1e5a14 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 02:04:33 +1100 Subject: [PATCH 04/16] update composer versions --- composer.json | 10 +- composer.lock | 310 +++++++++++++++++++++++++++++++------------------- 2 files changed, 200 insertions(+), 120 deletions(-) diff --git a/composer.json b/composer.json index 748580e8..ebdebf0a 100644 --- a/composer.json +++ b/composer.json @@ -13,11 +13,11 @@ ], "config": { "platform": { - "php": "5.3.9" + "php": "5.4.0" } }, "require": { - "php": ">=5.3.9", + "php": ">=5.4.0", "ext-mbstring": "*" }, "suggest": { @@ -26,9 +26,9 @@ "ext-gd": "Used for image printing if present." }, "require-dev": { - "phpunit/phpunit": "4.8.*", - "squizlabs/php_codesniffer": "2.*", - "guzzlehttp/guzzle": "~3.0|~4.0|~5.0|~6.0" + "phpunit/phpunit": "^4.8", + "squizlabs/php_codesniffer": "^3.2", + "guzzlehttp/guzzle": "^5.3" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 904398ba..d46bbc79 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "f82cf379d65648780f0850a73ee82785", - "content-hash": "cb289372c4f0093b1fe9d3d78442cb3f", + "content-hash": "0094775b67f67bc65c1ff4aebb0fd065", "packages": [], "packages-dev": [ { @@ -60,70 +59,35 @@ "constructor", "instantiate" ], - "time": "2015-06-14 21:17:01" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "v3.8.1", + "version": "5.3.2", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba" + "reference": "f9acb4761844317e626a32259205bec1f1bc60d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/4de0618a01b34aa1c8c33a3f13f396dcd3882eba", - "reference": "4de0618a01b34aa1c8c33a3f13f396dcd3882eba", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f9acb4761844317e626a32259205bec1f1bc60d2", + "reference": "f9acb4761844317e626a32259205bec1f1bc60d2", "shasum": "" }, "require": { - "ext-curl": "*", - "php": ">=5.3.3", - "symfony/event-dispatcher": ">=2.1" - }, - "replace": { - "guzzle/batch": "self.version", - "guzzle/cache": "self.version", - "guzzle/common": "self.version", - "guzzle/http": "self.version", - "guzzle/inflection": "self.version", - "guzzle/iterator": "self.version", - "guzzle/log": "self.version", - "guzzle/parser": "self.version", - "guzzle/plugin": "self.version", - "guzzle/plugin-async": "self.version", - "guzzle/plugin-backoff": "self.version", - "guzzle/plugin-cache": "self.version", - "guzzle/plugin-cookie": "self.version", - "guzzle/plugin-curlauth": "self.version", - "guzzle/plugin-error-response": "self.version", - "guzzle/plugin-history": "self.version", - "guzzle/plugin-log": "self.version", - "guzzle/plugin-md5": "self.version", - "guzzle/plugin-mock": "self.version", - "guzzle/plugin-oauth": "self.version", - "guzzle/service": "self.version", - "guzzle/stream": "self.version" + "guzzlehttp/ringphp": "^1.1", + "php": ">=5.4.0", + "react/promise": "^2.2" }, "require-dev": { - "doctrine/cache": "*", - "monolog/monolog": "1.*", - "phpunit/phpunit": "3.7.*", - "psr/log": "1.0.*", - "symfony/class-loader": "*", - "zendframework/zend-cache": "<2.3", - "zendframework/zend-log": "<2.3" + "ext-curl": "*", + "phpunit/phpunit": "^4.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.8-dev" - } - }, "autoload": { - "psr-0": { - "Guzzle": "src/", - "Guzzle\\Tests": "tests/" + "psr-4": { + "GuzzleHttp\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -135,10 +99,6 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" - }, - { - "name": "Guzzle Community", - "homepage": "https://github.com/guzzle/guzzle/contributors" } ], "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", @@ -152,7 +112,108 @@ "rest", "web service" ], - "time": "2014-01-28 22:29:15" + "time": "2018-01-15T07:18:01+00:00" + }, + { + "name": "guzzlehttp/ringphp", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/RingPHP.git", + "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", + "shasum": "" + }, + "require": { + "guzzlehttp/streams": "~3.0", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", + "time": "2015-05-20T03:37:09+00:00" + }, + { + "name": "guzzlehttp/streams", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/streams.git", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple abstraction over streams of data", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "time": "2014-10-12T19:18:40+00:00" }, { "name": "phpdocumentor/reflection-docblock", @@ -201,7 +262,7 @@ "email": "mike.vanriel@naenius.com" } ], - "time": "2015-02-03 12:10:50" + "time": "2015-02-03T12:10:50+00:00" }, { "name": "phpspec/prophecy", @@ -264,7 +325,7 @@ "spy", "stub" ], - "time": "2017-03-02 20:05:34" + "time": "2017-03-02T20:05:34+00:00" }, { "name": "phpunit/php-code-coverage", @@ -326,7 +387,7 @@ "testing", "xunit" ], - "time": "2015-10-06 15:47:00" + "time": "2015-10-06T15:47:00+00:00" }, { "name": "phpunit/php-file-iterator", @@ -373,7 +434,7 @@ "filesystem", "iterator" ], - "time": "2016-10-03 07:40:28" + "time": "2016-10-03T07:40:28+00:00" }, { "name": "phpunit/php-text-template", @@ -414,7 +475,7 @@ "keywords": [ "template" ], - "time": "2015-06-21 13:50:34" + "time": "2015-06-21T13:50:34+00:00" }, { "name": "phpunit/php-timer", @@ -463,7 +524,7 @@ "keywords": [ "timer" ], - "time": "2017-02-26 11:10:40" + "time": "2017-02-26T11:10:40+00:00" }, { "name": "phpunit/php-token-stream", @@ -512,20 +573,20 @@ "keywords": [ "tokenizer" ], - "time": "2017-02-27 10:12:30" + "time": "2017-02-27T10:12:30+00:00" }, { "name": "phpunit/phpunit", - "version": "4.8.35", + "version": "4.8.36", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "791b1a67c25af50e230f841ee7a9c6eba507dc87" + "reference": "46023de9a91eec7dfb06cc56cb4e260017298517" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/791b1a67c25af50e230f841ee7a9c6eba507dc87", - "reference": "791b1a67c25af50e230f841ee7a9c6eba507dc87", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517", + "reference": "46023de9a91eec7dfb06cc56cb4e260017298517", "shasum": "" }, "require": { @@ -584,7 +645,7 @@ "testing", "xunit" ], - "time": "2017-02-06 05:18:07" + "time": "2017-06-21T08:07:12+00:00" }, { "name": "phpunit/phpunit-mock-objects", @@ -640,7 +701,53 @@ "mock", "xunit" ], - "time": "2015-10-02 06:51:40" + "time": "2015-10-02T06:51:40+00:00" + }, + { + "name": "react/promise", + "version": "v2.5.1", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "62785ae604c8d69725d693eb370e1d67e94c4053" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/62785ae604c8d69725d693eb370e1d67e94c4053", + "reference": "62785ae604c8d69725d693eb370e1d67e94c4053", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2017-03-25T12:08:31+00:00" }, { "name": "sebastian/comparator", @@ -704,7 +811,7 @@ "compare", "equality" ], - "time": "2017-01-29 09:50:25" + "time": "2017-01-29T09:50:25+00:00" }, { "name": "sebastian/diff", @@ -756,7 +863,7 @@ "keywords": [ "diff" ], - "time": "2015-12-08 07:14:41" + "time": "2015-12-08T07:14:41+00:00" }, { "name": "sebastian/environment", @@ -806,7 +913,7 @@ "environment", "hhvm" ], - "time": "2016-08-18 05:49:44" + "time": "2016-08-18T05:49:44+00:00" }, { "name": "sebastian/exporter", @@ -873,7 +980,7 @@ "export", "exporter" ], - "time": "2016-06-17 09:04:28" + "time": "2016-06-17T09:04:28+00:00" }, { "name": "sebastian/global-state", @@ -924,7 +1031,7 @@ "keywords": [ "global state" ], - "time": "2015-10-12 03:26:01" + "time": "2015-10-12T03:26:01+00:00" }, { "name": "sebastian/recursion-context", @@ -977,7 +1084,7 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-10-03 07:41:43" + "time": "2016-10-03T07:41:43+00:00" }, { "name": "sebastian/version", @@ -1012,68 +1119,41 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21 13:59:46" + "time": "2015-06-21T13:59:46+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "2.8.1", + "version": "3.2.3", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d" + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", - "reference": "d7cf0d894e8aa4c73712ee4a331cc1eaa37cdc7d", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", + "reference": "4842476c434e375f9d3182ff7b89059583aa8b27", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.1.2" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -1090,7 +1170,7 @@ "phpcs", "standards" ], - "time": "2017-03-01 22:17:45" + "time": "2018-02-20T21:35:23+00:00" }, { "name": "symfony/event-dispatcher", @@ -1150,7 +1230,7 @@ ], "description": "Symfony EventDispatcher Component", "homepage": "https://symfony.com", - "time": "2017-02-21 08:33:48" + "time": "2017-02-21T08:33:48+00:00" }, { "name": "symfony/yaml", @@ -1199,7 +1279,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2017-03-01 18:13:50" + "time": "2017-03-01T18:13:50+00:00" } ], "aliases": [], @@ -1208,11 +1288,11 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.3.9", + "php": ">=5.4.0", "ext-mbstring": "*" }, "platform-dev": [], "platform-overrides": { - "php": "5.3.9" + "php": "5.4.0" } } From 21007022444989f923d22bcfceb0f85f840ac22d Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 02:47:46 +1100 Subject: [PATCH 05/16] new phpcs fixes --- src/Mike42/Escpos/ImagickEscposImage.php | 6 +++--- src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php | 4 ++-- src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Mike42/Escpos/ImagickEscposImage.php b/src/Mike42/Escpos/ImagickEscposImage.php index d7fe0fcd..d8b33434 100644 --- a/src/Mike42/Escpos/ImagickEscposImage.php +++ b/src/Mike42/Escpos/ImagickEscposImage.php @@ -217,9 +217,9 @@ public static function loadPdf($pdfFile, $pageWidth = 550) throw new Exception(__FUNCTION__ . " requires imagick extension."); } /* - * Load first page at very low density (resolution), to figure out what - * density to use to achieve $pageWidth - */ + * Load first page at very low density (resolution), to figure out what + * density to use to achieve $pageWidth + */ try { $image = new \Imagick(); $testRes = 2; // Test resolution diff --git a/src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php b/src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php index 441c1a56..283bcdf8 100644 --- a/src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php @@ -55,8 +55,8 @@ public function finalize() } /* (non-PHPdoc) - * @see PrintConnector::read() - */ + * @see PrintConnector::read() + */ public function read($len) { return fread($this -> fp, $len); diff --git a/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php index 21ef982e..d0b5597c 100644 --- a/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php @@ -314,8 +314,8 @@ protected function getCurrentPlatform() } /* (non-PHPdoc) - * @see PrintConnector::read() - */ + * @see PrintConnector::read() + */ public function read($len) { /* Two-way communication is not supported */ From 4e12466bdf245ffe00c02364d71450bf6bf50085 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 02:48:24 +1100 Subject: [PATCH 06/16] breaking change to ensure that PHP 5.3 users stick with escpos-php 1.x or upgrade their PHP: array() -> [] --- src/Mike42/Escpos/CapabilityProfile.php | 6 +++--- src/Mike42/Escpos/EscposImage.php | 8 ++++---- src/Mike42/Escpos/ImagickEscposImage.php | 6 +++--- src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php | 10 +++++----- .../Escpos/PrintConnectors/ApiPrintConnector.php | 2 +- .../Escpos/PrintConnectors/DummyPrintConnector.php | 2 +- .../Escpos/PrintConnectors/WindowsPrintConnector.php | 12 ++++++------ src/Mike42/Escpos/Printer.php | 12 ++++++------ 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Mike42/Escpos/CapabilityProfile.php b/src/Mike42/Escpos/CapabilityProfile.php index 6182b8ac..25695a49 100644 --- a/src/Mike42/Escpos/CapabilityProfile.php +++ b/src/Mike42/Escpos/CapabilityProfile.php @@ -126,7 +126,7 @@ protected function __construct($profileId, array $profileData) $this->fonts = $profileData['fonts']; $this->media = $profileData['media']; // More complex fields that are loaded into custom objects - $this->codePages = array(); + $this->codePages = []; $this->codePageCacheKey = md5(json_encode($profileData['codePages'])); foreach ($profileData['codePages'] as $k => $v) { $this->codePages[$k] = new CodePage($v, self::$encodings[$v]); @@ -334,10 +334,10 @@ public static function suggestNearest($input, array $choices, $num) protected static function suggestProfileName($profileName) { $suggestions = self::suggestNearest($profileName, array_keys(self::$profiles), 3); - $alwaysSuggest = array( + $alwaysSuggest = [ 'simple', 'default' - ); + ]; foreach ($alwaysSuggest as $item) { if (array_search($item, $suggestions) === false) { array_push($suggestions, $item); diff --git a/src/Mike42/Escpos/EscposImage.php b/src/Mike42/Escpos/EscposImage.php index 4aec0d7e..20da9c8a 100644 --- a/src/Mike42/Escpos/EscposImage.php +++ b/src/Mike42/Escpos/EscposImage.php @@ -59,7 +59,7 @@ abstract class EscposImage * @var string $imgColumnData * Cached column-format data to avoid re-computation */ - private $imgColumnData = array(); + private $imgColumnData = []; /** * @var array:string $imgRasterData @@ -313,7 +313,7 @@ private function getRasterFormat() */ private function getColumnFormat($highDensity) { - $out = array(); + $out = []; $i = 0; while (($line = $this -> getColumnFormatLine($i, $highDensity)) !== null) { $out[] = $line; @@ -422,7 +422,7 @@ public static function isImagickLoaded() public static function load( $filename, $allow_optimisations = true, - array $preferred = array('imagick', 'gd', 'native') + array $preferred = ['imagick', 'gd', 'native'] ) { /* Fail early if file is not readble */ if (!file_exists($filename) || !is_readable($filename)) { @@ -444,7 +444,7 @@ public static function load( } return new \Mike42\Escpos\GdEscposImage($filename, $allow_optimisations); } elseif ($implemetnation === 'native') { - if (!in_array($ext, array('wbmp', 'pbm', 'bmp'))) { + if (!in_array($ext, ['wbmp', 'pbm', 'bmp'])) { // Pure PHP is fastest way to generate raster output from wbmp and pbm formats. continue; } diff --git a/src/Mike42/Escpos/ImagickEscposImage.php b/src/Mike42/Escpos/ImagickEscposImage.php index d8b33434..49cec670 100644 --- a/src/Mike42/Escpos/ImagickEscposImage.php +++ b/src/Mike42/Escpos/ImagickEscposImage.php @@ -113,7 +113,7 @@ private function getColumnFormatFromImage(Imagick $im, $lineHeight) $imgWidth = $im->getimagewidth(); if ($imgWidth == $lineHeight) { // Return glob of this panel - return array($this -> getRasterBlobFromImage($im)); + return [$this -> getRasterBlobFromImage($im)]; } elseif ($imgWidth > $lineHeight) { // Calculations $slicesLeft = ceil($imgWidth / $lineHeight / 2); @@ -133,7 +133,7 @@ private function getColumnFormatFromImage(Imagick $im, $lineHeight) } else { /* Image is smaller than full width */ $im -> extentimage($lineHeight, $im -> getimageheight(), 0, 0); - return array($this -> getRasterBlobFromImage($im)); + return [$this -> getRasterBlobFromImage($im)]; } } @@ -235,7 +235,7 @@ public static function loadPdf($pdfFile, $pageWidth = 550) $image -> readImage($pdfFile); $pages = $image -> getNumberImages(); /* Convert images to Escpos objects */ - $ret = array(); + $ret = []; for ($i = 0; $i < $pages; $i++) { $image -> setIteratorIndex($i); $ep = new ImagickEscposImage(); diff --git a/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php b/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php index bf4a586f..30bf50e3 100644 --- a/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php +++ b/src/Mike42/Escpos/PrintBuffers/EscposPrintBuffer.php @@ -198,11 +198,11 @@ private function loadAvailableCharacters() } /* Generate conversion tables */ - $encode = array(); - $available = array(); + $encode = []; + $available = []; foreach ($supportedCodePages as $num => $codePage) { - $encode[$num] = array(); + $encode[$num] = []; if (!$codePage -> isEncodable()) { continue; } @@ -213,7 +213,7 @@ private function loadAvailableCharacters() continue; } if (!isset($available[$utf8])) { - $available[$utf8] = array(); + $available[$utf8] = []; } $available[$utf8][$num] = true; $encode[$num][$utf8] = chr($char); @@ -221,7 +221,7 @@ private function loadAvailableCharacters() } /* Use generated data */ - $dataArray = array("available" => $available, "encode" => $encode, "key" => $cacheKey); + $dataArray = ["available" => $available, "encode" => $encode, "key" => $cacheKey]; $this -> available = $dataArray["available"]; $this -> encode = $dataArray["encode"]; $cacheData = serialize($dataArray); diff --git a/src/Mike42/Escpos/PrintConnectors/ApiPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/ApiPrintConnector.php index 0db54b37..893a4858 100644 --- a/src/Mike42/Escpos/PrintConnectors/ApiPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/ApiPrintConnector.php @@ -36,7 +36,7 @@ class ApiPrintConnector implements PrintConnector */ public function __construct($host, $printerId, $apiToken) { - $this->httpClient = new Client(array('base_uri' => $host)); + $this->httpClient = new Client(['base_uri' => $host]); $this->printerId = $printerId; $this->apiToken = $apiToken; diff --git a/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php index 28d5d9e3..b3ad68c7 100644 --- a/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php @@ -34,7 +34,7 @@ final class DummyPrintConnector implements PrintConnector */ public function __construct() { - $this -> buffer = array(); + $this -> buffer = []; } public function __destruct() diff --git a/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php index d0b5597c..e9511a68 100644 --- a/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/WindowsPrintConnector.php @@ -155,7 +155,7 @@ public function __construct($dest) throw new BadMethodCallException("Printer '" . $dest . "' is not a valid " . "printer name. Use local port (LPT1, COM1, etc) or smb://computer/printer notation."); } - $this -> buffer = array(); + $this -> buffer = []; } public function __destruct() @@ -333,11 +333,11 @@ public function read($len) */ protected function runCommand($command, &$outputStr, &$errorStr, $inputStr = null) { - $descriptors = array( - 0 => array("pipe", "r"), - 1 => array("pipe", "w"), - 2 => array("pipe", "w"), - ); + $descriptors = [ + 0 => ["pipe", "r"], + 1 => ["pipe", "w"], + 2 => ["pipe", "w"], + ]; $process = proc_open($command, $descriptors, $fd); if (is_resource($process)) { /* Write to input */ diff --git a/src/Mike42/Escpos/Printer.php b/src/Mike42/Escpos/Printer.php index bddddc0f..206d966b 100644 --- a/src/Mike42/Escpos/Printer.php +++ b/src/Mike42/Escpos/Printer.php @@ -399,7 +399,7 @@ public function barcode($content, $type = Printer::BARCODE_CODE39) self::validateStringRegex($content, __FUNCTION__, "/^[0-9]{11,12}$/", "UPCA barcode content"); break; case self::BARCODE_UPCE: - self::validateIntegerMulti($len, array(array(6, 8), array(11, 12)), __FUNCTION__, "UPCE barcode content length"); + self::validateIntegerMulti($len, [[6, 8], [11, 12]], __FUNCTION__, "UPCE barcode content length"); self::validateStringRegex($content, __FUNCTION__, "/^([0-9]{6,8}|[0-9]{11,12})$/", "UPCE barcode content"); break; case self::BARCODE_JAN13: @@ -458,7 +458,7 @@ public function bitImage(EscposImage $img, $size = Printer::IMG_DEFAULT) { self::validateInteger($size, 0, 3, __FUNCTION__); $rasterData = $img -> toRasterFormat(); - $header = Printer::dataHeader(array($img -> getWidthBytes(), $img -> getHeight()), true); + $header = Printer::dataHeader([$img -> getWidthBytes(), $img -> getHeight()], true); $this -> connector -> write(self::GS . "v0" . chr($size) . $header); $this -> connector -> write($rasterData); } @@ -484,7 +484,7 @@ public function bitImageColumnFormat(EscposImage $img, $size = Printer::IMG_DEFA // Header and density code (0, 1, 32, 33) re-used for every line $densityCode = ($highDensityHorizontal ? 1 : 0) + ($highDensityVertical ? 32 : 0); $colFormatData = $img -> toColumnFormat($highDensityVertical); - $header = Printer::dataHeader(array($img -> getWidth()), true); + $header = Printer::dataHeader([$img -> getWidth()], true); foreach ($colFormatData as $line) { // Print each line, double density etc for printing are set here also $this -> connector -> write(self::ESC . "*" . chr($densityCode) . $header . $line); @@ -613,7 +613,7 @@ public function graphics(EscposImage $img, $size = Printer::IMG_DEFAULT) { self::validateInteger($size, 0, 3, __FUNCTION__); $rasterData = $img -> toRasterFormat(); - $imgHeader = Printer::dataHeader(array($img -> getWidth(), $img -> getHeight()), true); + $imgHeader = Printer::dataHeader([$img -> getWidth(), $img -> getHeight()], true); $tone = '0'; $colors = '1'; $xm = (($size & self::IMG_DOUBLE_WIDTH) == Printer::IMG_DOUBLE_WIDTH) ? chr(2) : chr(1); @@ -1061,7 +1061,7 @@ protected function wrapperSendGraphicsData($m, $fn, $data = '') */ protected static function dataHeader(array $inputs, $long = true) { - $outp = array(); + $outp = []; foreach ($inputs as $input) { if ($long) { $outp[] = Printer::intLowHigh($input, 2); @@ -1135,7 +1135,7 @@ protected static function validateFloat($test, $min, $max, $source, $argument = */ protected static function validateInteger($test, $min, $max, $source, $argument = "Argument") { - self::validateIntegerMulti($test, array(array($min, $max)), $source, $argument); + self::validateIntegerMulti($test, [[$min, $max]], $source, $argument); } /** From 74407f6bfcb348551c9784fdac5d9f3348e1b393 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 09:23:27 +1100 Subject: [PATCH 07/16] update expected output of smbclient usage in WindowsPrintConnectorTest --- test/unit/WindowsPrintConnectorTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/WindowsPrintConnectorTest.php b/test/unit/WindowsPrintConnectorTest.php index 92e82ee6..038c9c20 100644 --- a/test/unit/WindowsPrintConnectorTest.php +++ b/test/unit/WindowsPrintConnectorTest.php @@ -176,7 +176,7 @@ public function testSharedPrinterLinux() $connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); $connector -> expects($this -> once()) -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -c \'print -\' -N')); + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -c \'print -\' -N -m SMB2')); $connector -> expects($this -> exactly(0)) -> method('runCopy'); $connector -> expects($this -> exactly(0)) @@ -189,7 +189,7 @@ public function testSharedPrinterLinuxUsername() $connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); $connector -> expects($this -> once()) -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'bob\' -c \'print -\' -N')); + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'bob\' -c \'print -\' -N -m SMB2')); $connector -> expects($this -> exactly(0)) -> method('runCopy'); $connector -> expects($this -> exactly(0)) @@ -202,7 +202,7 @@ public function testSharedPrinterLinuxUsernameDomain() $connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_LINUX); $connector -> expects($this -> once()) -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'home\\bob\' -c \'print -\' -N')); + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'home\\bob\' -c \'print -\' -N -m SMB2')); $connector -> expects($this -> exactly(0)) -> method('runCopy'); $connector -> expects($this -> exactly(0)) @@ -215,7 +215,7 @@ public function testSharedPrinterLinuxUsernamePassword() $connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX); $connector -> expects($this -> once()) -> method('runCommand') - -> with($this -> equalTo('smbclient \'//example-pc/Printer\' \'secret\' -U \'bob\' -c \'print -\'')); + -> with($this -> equalTo('smbclient \'//example-pc/Printer\' \'secret\' -U \'bob\' -c \'print -\' -m SMB2')); $connector -> expects($this -> exactly(0)) -> method('runCopy'); $connector -> expects($this -> exactly(0)) From e8d9b967f2d94a2616122ca6f5a3be6933907a55 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 10:06:50 +1100 Subject: [PATCH 08/16] update printer list & sort: closes #528 #527 #517 #499 #487 #483 #472 #463 #296 #276 --- README.md | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e7ea8048..59bd0d41 100644 --- a/README.md +++ b/README.md @@ -67,30 +67,35 @@ This driver is known to work with the following OS/interface combinations: ### Printers Many thermal receipt printers support ESC/POS to some degree. This driver has been known to work with: +- 3nStrat POS-08 - AURES ODP-333 - AURES ODP-500 +- Bematech-4200-TH - Bixolon SRP-350III +- Black Copper BC-85AC - Citizen CBM1000-II - Citizen CT-S310II +- Dapper-Geyi Q583P - Daruma DR800 - EPOS TEP 220M -- Epson TM-T88II -- Epson TM-T88III -- Epson TM-T88IV -- Epson TM-T88V -- Epson TM-T70 -- Epson TM-T82II +- Epson EU-T332C +- Epson FX-890 (requires `feedForm()` to release paper). - Epson TM-T20 - Epson TM-T20II +- Epson TM-T70 - Epson TM-T70II - Epson TM-T81 +- Epson TM-T82II +- Epson TM-T88II +- Epson TM-T88III +- Epson TM-T88IV +- Epson TM-T88V - Epson TM-U220 - Epson TM-U295 (requires `release()` to release slip). - Epson TM-U590 and TM-U590P -- Epson FX-890 (requires `feedForm()` to release paper). - Equal (EQ-IT-001) POS-58 -- Excelvan HOP-E58 - Excelvan HOP-E200 +- Excelvan HOP-E58 - Excelvan HOP-E801 - Excelvan ZJ-8220 - Gainscha GP-5890x (Also marketed as EC Line 5890x) @@ -100,28 +105,34 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be - Metapace T-1 - Metapace T-25 - Nexa PX700 +- Nyear NP100 - Okipos 80 Plus III - Orient BTP-R580 - P-822D - P85A-401 (make unknown) - Rongta RP326US - Rongta RP58-U +- Senor TP-100 - SEYPOS PRP-300 (Also marketed as TYSSO PRP-300) +- Sicar POS-80 - Silicon SP-201 / RP80USE +- SPRT SP-POS88V +- Star BSC10 - Star TSP100 ECO - Star TSP100III FuturePRNT - Star TSP-650 - Star TUP-592 -- SPRT SP-POS88V +- Venus V248T - Xprinter F-900 +- Xprinter XP-58 Series +- Xprinter XP-80C +- Xprinter XP-90 - XPrinter XP-Q20011 - Xprinter XP-Q800 -- Xprinter XP-80C -- Venus V248T - Zjiang NT-58H - Zjiang ZJ-5870 -- Zjiang ZJ-5890T (Marketed as POS 5890T) - Zjiang ZJ-5890K +- Zjiang ZJ-5890T (Marketed as POS 5890T) If you use any other printer with this code, please [let us know](https://github.com/mike42/escpos-php/issues/new) so that it can be added to the list. From 7e3c3a34a464c6d6b243aa3f4223fa25ee27a05c Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 11:12:13 +1100 Subject: [PATCH 09/16] refactor UriPrintConnector & add tests --- CONTRIBUTORS.md | 1 + .../PrintConnectors/UriPrintConnector.php | 66 ++++++++----------- test/unit/UriPrintConnectorTest.php | 59 +++++++++++++++++ 3 files changed, 89 insertions(+), 37 deletions(-) create mode 100644 test/unit/UriPrintConnectorTest.php diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1212d0b2..12f3acf9 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -11,6 +11,7 @@ Main repository: [mike42/escpos-php](https://github.com/mike42/escpos-php) ([onl - [matiasgaston](https://github.com/matiasgaston) - [Mike Stivala](https://github.com/brndwgn) - [Nicholas Long](https://github.com/longsview) +- [Evandro Araújo](https://github.com/evsar3) Via fork: [wdoyle/EpsonESCPOS-PHP](https://github.com/wdoyle/EpsonESCPOS-PHP): diff --git a/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php index 31813290..88d5dc56 100644 --- a/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/UriPrintConnector.php @@ -1,50 +1,42 @@ , + * incorporating modifications by others. See CONTRIBUTORS.md for a full list. + * + * This software is distributed under the terms of the MIT license. See LICENSE.md + * for details. + */ + class UriPrintConnector { const URI_ASSEMBLER_PATTERN = "~^(.+):/{2}(.+?)(?::(\d{1,4}))?$~"; public static function get($uri) { - $allowed_protocols = array("file", "tcp", "ipp", "smb", "usb", "com", "lpt"); - + // Parse URI $is_uri = preg_match(self::URI_ASSEMBLER_PATTERN, $uri, $uri_parts); - - if ($is_uri === 1) { - $protocol = $uri_parts[1]; - $printer = $uri_parts[2]; - $port = isset($uri_parts[3]) ? $uri_parts[3] : 9100; - - if (in_array($protocol, $allowed_protocols)) { - switch ($protocol) { - case "file": - return new FilePrintConnector($printer); - break; - - case "tcp": - return new NetworkPrintConnector($printer, $port); - break; - - case "ipp": - return new CupsPrintConnector($printer); - break; - - case "smb": - return new WindowsPrintConnector($uri); - break; - - case "usb": - case "com": - case "lpt": - return new WindowsPrintConnector($printer); - break; - } - } else { - throw new \Exception("Connector protocol not supported: {$protocol}"); - } - } else { - throw new \Exception("Malformed connector URI: {$uri}"); + if ($is_uri !== 1) { + throw new \InvalidArgumentException("Malformed connector URI: {$uri}"); + } + // Extract parts + $protocol = $uri_parts[1]; + $printer = $uri_parts[2]; + $port = isset($uri_parts[3]) ? $uri_parts[3] : 9100; + // Initialise the most applicable print connector + switch ($protocol) { + case "file": + return new FilePrintConnector($printer); + case "tcp": + return new NetworkPrintConnector($printer, $port); + case "smb": + return new WindowsPrintConnector($uri); } + // Fallthrough + throw new \InvalidArgumentException("URI sheme is not supported: {$protocol}://"); } } diff --git a/test/unit/UriPrintConnectorTest.php b/test/unit/UriPrintConnectorTest.php new file mode 100644 index 00000000..715dd8d7 --- /dev/null +++ b/test/unit/UriPrintConnectorTest.php @@ -0,0 +1,59 @@ + write("AAA"); + $connector -> finalize(); + $this -> assertEquals("AAA", file_get_contents($filename)); + $this -> assertEquals('Mike42\Escpos\PrintConnectors\FilePrintConnector', get_class($connector)); + unlink($filename); + } + + /** + * @expectedException PHPUnit_Framework_Error + * @expectedExceptionMessage not finalized + */ + public function testSmb() + { + $connector = UriPrintConnector::get("smb://windows/printer"); + $this -> assertEquals('Mike42\Escpos\PrintConnectors\WindowsPrintConnector', get_class($connector)); + // We expect that this will throw an exception, we can't + // realistically print to a real printer in this test though... :) + $connector -> __destruct(); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Malformed connector URI + */ + public function testBadUri() + { + $connector = UriPrintConnector::get("foooooo"); + } + + /** + * @expectedException Exception + * @expectedExceptionMessage Connection refused + */ + public function testNetwork() + { + // Port should be closed so we can catch an error and move on + $connector = UriPrintConnector::get("tcp://localhost:45987/"); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage URI sheme is not supported: ldap:// + */ + public function testUnsupportedUri() + { + // Try to print to something silly + $connector = UriPrintConnector::get("ldap://host:1234/"); + } +} From 13979f9cae0ff5df7e05b09383c6640145d5c586 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 11:39:50 +1100 Subject: [PATCH 10/16] try another hhvm build --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 234e0c8d..9ae2af2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,13 @@ php: - 7.1 - 7.2 - nightly + - hhvm-3.21 + - hhvm-nightly matrix: allow_failures: - php: nightly + - php: hhvm-nightly before_install: - sudo apt-get -qq update From 95e8f75f18c595997055b734abfeb68b7718a2bf Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 11:49:10 +1100 Subject: [PATCH 11/16] remove pecl imagick install from hhvm builds --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9ae2af2d..04ffb652 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ install: before_script: # Install 'imagick' plugin - - printf "\n" | pecl install imagick + - bash -c 'if [[ $TRAVIS_PHP_VERSION != hhvm* ]]; then printf "\n" | pecl install imagick; fi' # Directory for coverage report - mkdir -p build/logs/ From 447dff0b96b47e56d2e12a77f441d57380bfa422 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 11:58:55 +1100 Subject: [PATCH 12/16] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59bd0d41..5753afe0 100644 --- a/README.md +++ b/README.md @@ -542,7 +542,7 @@ This code is MIT licensed, and you are encouraged to contribute any modification For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP exensions, and install `composer`. -The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.4, 5.5, 5.6, 7.0, 7.2 and 7.2. Earlier versions of PHP are not supported in current releases. +The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.4, 5.5, 5.6, 7.0, 7.1 and 7.2, plus the latest LTS version of HHVM, 3.21. Older versions of PHP are not supported in current releases. Fetch a copy of this code and load dependencies with composer: From 3b4894f7032ec03c33c6a3e8874f933b8cc7dee1 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 12:46:57 +1100 Subject: [PATCH 13/16] Improve test > 80% coverage ahead of new release --- .../PrintConnectors/DummyPrintConnector.php | 4 + test/unit/AuresCustomerDisplayTest.php | 76 ++++++++++++++++++ test/unit/ImagickEscposImageTest.php | 12 ++- test/unit/resources/black_white_tall.png | Bin 0 -> 162 bytes 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 test/unit/AuresCustomerDisplayTest.php create mode 100644 test/unit/resources/black_white_tall.png diff --git a/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php index b3ad68c7..c3763233 100644 --- a/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php @@ -37,6 +37,10 @@ public function __construct() $this -> buffer = []; } + public function clear() { + $this -> buffer = []; + } + public function __destruct() { if ($this -> buffer !== null) { diff --git a/test/unit/AuresCustomerDisplayTest.php b/test/unit/AuresCustomerDisplayTest.php new file mode 100644 index 00000000..c0f803af --- /dev/null +++ b/test/unit/AuresCustomerDisplayTest.php @@ -0,0 +1,76 @@ + outputConnector = new DummyPrintConnector(); + $profile = CapabilityProfile::load('OCD-300'); + $this -> printer = new AuresCustomerDisplay($this -> outputConnector, $profile); + } + + protected function checkOutput($expected = null) + { + /* Check those output strings */ + $outp = $this -> outputConnector -> getData(); + if ($expected === null) { + echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n"; + } + $this -> assertEquals($expected, $outp); + } + + protected function tearDown() + { + $this -> outputConnector -> finalize(); + } + + public function testInitializeOutput() + { + $this -> checkOutput("\x02\x05C1\x03\x1b@\x1bt\x00\x1f\x02"); + } + + public function testselectTextScrollMode() { + $this -> outputConnector -> clear(); + $this -> printer -> selectTextScrollMode(AuresCustomerDisplay::TEXT_OVERWRITE); + $this -> checkOutput("\x1f\x01"); + } + + public function testClear() { + $this -> outputConnector -> clear(); + $this -> printer -> clear(); + $this -> checkOutput("\x0c"); + } + + public function testShowFirmwareVersion() { + $this -> outputConnector -> clear(); + $this -> printer -> showFirmwareVersion(); + $this -> checkOutput("\x02\x05V\x01\x03"); + } + + public function testSelfTest() { + $this -> outputConnector -> clear(); + $this -> printer -> selfTest(); + $this -> checkOutput("\x02\x05D\x08\x03"); + } + + public function testShowLogo() { + $this -> outputConnector -> clear(); + $this -> printer -> showLogo(); + $this -> checkOutput("\x02\xfcU\xaaU\xaa"); + } + + public function testTest() { + $this -> outputConnector -> clear(); + // Handling of line-endings differs to regular printers, need to use \r\n + $this -> printer -> text("Hello\nWorld\n"); + $this -> checkOutput("Hello\x0d\x0aWorld\x0d\x0a"); + } +} \ No newline at end of file diff --git a/test/unit/ImagickEscposImageTest.php b/test/unit/ImagickEscposImageTest.php index d848b285..76831f76 100644 --- a/test/unit/ImagickEscposImageTest.php +++ b/test/unit/ImagickEscposImageTest.php @@ -52,7 +52,17 @@ public function testImagickBlackWhite() $this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80")); } } - + + /** + * @medium + */ + public function testImagickBlackWhiteTall() + { + // We're very interested in correct column format chopping here at 8 pixels + $this -> loadAndCheckImg('black_white_tall.png', 2, 16, + "\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\x00\x00\x00\x00\x00\x00\x00\x00", array("\xff\xff", "\x00\x00")); + } + /** * @medium */ diff --git a/test/unit/resources/black_white_tall.png b/test/unit/resources/black_white_tall.png new file mode 100644 index 0000000000000000000000000000000000000000..7e0869dcbed532acfd38204f6539d22d93b515ef GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^Oh7Ea0U|e_vV07rI14-?iy0WWg+Z8+Vb&Z8pdfpR zr>`sfBW7Mkas6JV#5+JC+02lL66gHf+|;}hAeVu`xhOTUBsE2$JhLQ2!QIn0AVn{g z9Vjm0>Eal|aXmRff#2ZY|NrwF8yh(fDbHhKSlq|V+q`4SH;`seS3j3^P6 Date: Tue, 13 Mar 2018 12:53:53 +1100 Subject: [PATCH 14/16] phpcbf fix --- src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php b/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php index c3763233..fffebce5 100644 --- a/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php +++ b/src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php @@ -37,7 +37,8 @@ public function __construct() $this -> buffer = []; } - public function clear() { + public function clear() + { $this -> buffer = []; } From 127b812224ac7045faa148d28c4cd31789258f30 Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 13:50:45 +1100 Subject: [PATCH 15/16] Update supported PHP versions in CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7b6d5588..326e1d09 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -42,7 +42,7 @@ This project uses the [PSR-2 standard](https://github.com/php-fig/fig-standards/ ## Testing and CI -The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.3, 5.4, 5.5, 5.7, 7, and HHVM. Earlier versions of PHP are not supported. +The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.4, 5.5, 5.6, 7.0, 7.1 and 7.2, plus the latest LTS version of HHVM, 3.21. Older versions of PHP are not supported in current releases. For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP exensions, and install `composer`. From 87c50bbd50673224bd8a759260897b538cdc3e6c Mon Sep 17 00:00:00 2001 From: Michael Billington Date: Tue, 13 Mar 2018 13:56:11 +1100 Subject: [PATCH 16/16] Update capabilities DB --- src/Mike42/Escpos/resources/capabilities.json | 159 +++++++++++++++++- 1 file changed, 155 insertions(+), 4 deletions(-) diff --git a/src/Mike42/Escpos/resources/capabilities.json b/src/Mike42/Escpos/resources/capabilities.json index fc545ea3..1081f4fe 100644 --- a/src/Mike42/Escpos/resources/capabilities.json +++ b/src/Mike42/Escpos/resources/capabilities.json @@ -286,6 +286,115 @@ } }, "profiles": { + "NT-5890K": { + "codePages": { + "0": "CP437", + "1": "CP932", + "2": "CP850", + "3": "CP860", + "4": "CP863", + "5": "CP865", + "6": "Unknown", + "7": "Unknown", + "8": "Unknown", + "9": "Unknown", + "10": "Unknown", + "16": "CP1252", + "17": "CP866", + "18": "CP852", + "19": "CP858", + "20": "Unknown", + "21": "Unknown", + "22": "Unknown", + "23": "Unknown", + "24": "CP747", + "25": "CP1257", + "27": "CP1258", + "28": "CP864", + "31": "Unknown", + "32": "CP1255", + "50": "CP437", + "52": "CP437", + "53": "CP858", + "54": "CP852", + "55": "CP860", + "56": "CP861", + "57": "CP863", + "58": "CP865", + "59": "CP866", + "60": "CP855", + "61": "CP857", + "62": "CP862", + "63": "CP864", + "64": "CP737", + "65": "CP851", + "66": "CP869", + "68": "CP772", + "69": "CP774", + "71": "CP1252", + "72": "CP1250", + "73": "CP1251", + "74": "CP3840", + "76": "CP3843", + "77": "CP3844", + "78": "CP3845", + "79": "CP3846", + "80": "CP3847", + "81": "CP3848", + "83": "CP2001", + "84": "CP3001", + "85": "CP3002", + "86": "CP3011", + "87": "CP3012", + "88": "CP3021", + "89": "CP3041", + "90": "CP1253", + "91": "CP1254", + "92": "CP1256", + "93": "CP720", + "94": "CP1258", + "95": "CP775", + "96": "Unknown", + "255": "Unknown" + }, + "colors": { + "0": "black" + }, + "features": { + "barcodeA": false, + "barcodeB": false, + "bitImageColumn": true, + "bitImageRaster": true, + "graphics": false, + "highDensity": true, + "paperFullCut": false, + "paperPartCut": false, + "pdf417Code": false, + "pulseBel": false, + "pulseStandard": true, + "qrCode": false, + "starCommands": false + }, + "fonts": { + "0": { + "columns": 32, + "name": "Font A" + }, + "1": { + "columns": 42, + "name": "Font B" + } + }, + "media": { + "width": { + "mm": 57.5, + "pixels": 384 + } + }, + "name": "NT-5890K", + "notes": "", + "vendor": "Netum" + }, "OCD-300": { "codePages": { "0": "CP437", @@ -314,11 +423,14 @@ "0": "black" }, "features": { + "barcodeA": false, "barcodeB": false, "bitImageColumn": false, "bitImageRaster": false, "graphics": false, "highDensity": true, + "paperFullCut": false, + "paperPartCut": false, "pdf417Code": false, "pulseBel": false, "pulseStandard": true, @@ -419,11 +531,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": false, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -525,11 +640,14 @@ "0": "black" }, "features": { + "barcodeA": false, "barcodeB": false, "bitImageColumn": false, "bitImageRaster": true, "graphics": false, "highDensity": true, + "paperFullCut": false, + "paperPartCut": false, "pdf417Code": false, "pulseBel": false, "pulseStandard": true, @@ -538,18 +656,18 @@ }, "fonts": { "0": { - "columns": 42, + "columns": 32, "name": "Font A" }, "1": { - "columns": 56, + "columns": 42, "name": "Font B" } }, "media": { "width": { - "mm": "Unknown", - "pixels": "Unknown" + "mm": 57.5, + "pixels": 384 } }, "name": "POS5890 Series", @@ -612,11 +730,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -712,11 +833,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -812,11 +936,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -916,11 +1043,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -966,11 +1096,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -1015,11 +1148,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -1055,11 +1191,14 @@ "1": "alternate" }, "features": { + "barcodeA": false, "barcodeB": false, "bitImageColumn": true, "bitImageRaster": false, "graphics": false, "highDensity": false, + "paperFullCut": false, + "paperPartCut": false, "pdf417Code": false, "pulseBel": false, "pulseStandard": true, @@ -1142,11 +1281,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -1229,11 +1371,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -1329,11 +1474,14 @@ "0": "black" }, "features": { + "barcodeA": true, "barcodeB": true, "bitImageColumn": true, "bitImageRaster": true, "graphics": true, "highDensity": true, + "paperFullCut": true, + "paperPartCut": true, "pdf417Code": true, "pulseBel": false, "pulseStandard": true, @@ -1368,11 +1516,14 @@ "0": "black" }, "features": { + "barcodeA": false, "barcodeB": false, "bitImageColumn": false, "bitImageRaster": true, "graphics": false, "highDensity": true, + "paperFullCut": false, + "paperPartCut": false, "pdf417Code": false, "pulseBel": false, "pulseStandard": true,