Skip to content

Commit

Permalink
Reverting the leading comma prevent [7b544c9]
Browse files Browse the repository at this point in the history
- Fails on image ASCII
  • Loading branch information
stephandesouza committed Jan 6, 2021
1 parent 89b3914 commit ef545b6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
18 changes: 5 additions & 13 deletions src/Weez/Zpl/Utils/ZplUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,12 @@ public static function zplCommand($command, $variables = null)
return $zpl;
}

$cv = count($variables);
if ($cv > 1) {
$zpl .= self::variableObjectToZplCode($variables[0]);
for ($i = 1; $i < $cv; $i++) {
$zpl .= ",";
$zpl .= self::variableObjectToZplCode($variables[$i]);
}
$zplVariables = array_map(static function ($iValue) {
return self::variableObjectToZplCode($iValue);
}, $variables);

$zpl .= implode(',', $zplVariables);

//Prevents leading comma
$zpl = rtrim($zpl, ',');
} elseif ($cv == 1) {
//Only one element in variables
$zpl .= self::variableObjectToZplCode($variables[0]);
}
return $zpl;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Weez/Zpl/Tests/Model/Element/ZebraFieldBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class ZebraFieldBlockTest extends TestCase
public function testGetZplCode(): void
{
$barcode = new ZebraFieldBlock(500, 2, 10, new ZebraAlignment(ZebraAlignment::CENTER));
self::assertEquals("^FB500,2,10,C", $barcode->getZplCode());
self::assertEquals("^FB500,2,10,C,", $barcode->getZplCode());
}
}
2 changes: 1 addition & 1 deletion tests/Weez/Zpl/Tests/Model/Element/ZebraTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testGetZplCodeWithBlockTest(): void
{
$block = new ZebraFieldBlock(500, 2, 1, new ZebraAlignment(ZebraAlignment::RIGHT));
$text = new ZebraText(20, 20, "Text", null, null, null, $block);
self::assertEquals("^FT20,20^FB500,2,1,R^FH\^FDText^FS\n", $text->getZplCode());
self::assertEquals("^FT20,20^FB500,2,1,R,^FH\^FDText^FS\n", $text->getZplCode());
}

public function testGetZplCodeAllowDecimalTest(): void
Expand Down

0 comments on commit ef545b6

Please sign in to comment.