Skip to content

Commit

Permalink
Merge pull request #600 from mike42/development
Browse files Browse the repository at this point in the history
Changes for release 2.0.2
  • Loading branch information
mike42 committed Jun 30, 2018
2 parents 71e9910 + ed626c2 commit 416e340
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -71,12 +71,14 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- AURES ODP-333
- AURES ODP-500
- Bematech-4200-TH
- Bematech LR2000E
- Bixolon SRP-350III
- Black Copper BC-85AC
- Citizen CBM1000-II
- Citizen CT-S310II
- Dapper-Geyi Q583P
- Daruma DR800
- DR-MP200 (manufacturer unknown)
- EPOS TEP 220M
- Epson EU-T332C
- Epson FX-890 (requires `feedForm()` to release paper).
Expand Down Expand Up @@ -108,6 +110,7 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Nyear NP100
- Okipos 80 Plus III
- Orient BTP-R580
- Partner Tech RP320
- P-822D
- P85A-401 (make unknown)
- Rongta RP326US
Expand All @@ -124,6 +127,7 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Star TUP-592
- Venus V248T
- Xprinter F-900
- Xprinter XP-365B
- Xprinter XP-58 Series
- Xprinter XP-80C
- Xprinter XP-90
Expand All @@ -133,6 +137,7 @@ Many thermal receipt printers support ESC/POS to some degree. This driver has be
- Zjiang ZJ-5870
- Zjiang ZJ-5890K
- Zjiang ZJ-5890T (Marketed as POS 5890T)
- Zjiang ZJ-8220

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.

Expand Down
12 changes: 10 additions & 2 deletions src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php
Expand Up @@ -50,15 +50,20 @@ public function __destruct()
*/
public function finalize()
{
fclose($this -> fp);
$this -> fp = false;
if ($this -> fp !== false) {
fclose($this -> fp);
$this -> fp = false;
}
}

/* (non-PHPdoc)
* @see PrintConnector::read()
*/
public function read($len)
{
if ($this -> fp === false) {
throw new Exception("PrintConnector has been closed, cannot read input.");
}
return fread($this -> fp, $len);
}

Expand All @@ -69,6 +74,9 @@ public function read($len)
*/
public function write($data)
{
if ($this -> fp === false) {
throw new Exception("PrintConnector has been closed, cannot send output.");
}
fwrite($this -> fp, $data);
}
}
2 changes: 1 addition & 1 deletion src/Mike42/Escpos/Printer.php
Expand Up @@ -1142,7 +1142,7 @@ protected static function validateInteger($test, $min, $max, $source, $argument
* Throw an exception if the argument given is not an integer within one of the specified ranges
*
* @param int $test the input to test
* @param arrray $ranges array of two-item min/max ranges.
* @param array $ranges array of two-item min/max ranges.
* @param string $source the name of the function calling this
* @param string $source the name of the function calling this
* @param string $argument the name of the invalid parameter
Expand Down
26 changes: 26 additions & 0 deletions test/unit/FilePrintConnectorTest.php
@@ -0,0 +1,26 @@
<?php
use Mike42\Escpos\PrintConnectors\FilePrintConnector;

class FilePrintConnectorTest extends PHPUnit_Framework_TestCase
{
public function testTmpfile()
{
// Should attempt to send data to the local printer by writing to it
$tmpfname = tempnam("/tmp", "php");
$connector = new FilePrintConnector($tmpfname);
$connector -> finalize();
$connector -> finalize(); // Silently do nothing if printer already closed
unlink($tmpfname);
}

public function testReadAfterClose()
{
// Should attempt to send data to the local printer by writing to it
$this -> setExpectedException('Exception');
$tmpfname = tempnam("/tmp", "php");
$connector = new FilePrintConnector($tmpfname);
$connector -> finalize();
$connector -> write("Test");
unlink($tmpfname);
}
}

0 comments on commit 416e340

Please sign in to comment.