Skip to content

Commit

Permalink
Merge pull request #79 from hgajjar/bugfix/una-add-new-line
Browse files Browse the repository at this point in the history
MISC: Add new line to UNA segment line
  • Loading branch information
sabas authored Mar 22, 2018
2 parents 765ffc1 + 1c6961e commit d241211
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/EDI/Encoder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* EDIFACT Messages Encoder
* (c)2016 Stefano Sabatini
* (c) 2018 Stefano Sabatini
*/

namespace EDI;
Expand All @@ -12,6 +12,7 @@ class Encoder
private $output = '';
private $UNAActive = false; // disable by default to preserve backward compatibility
private $originalArray = [];
private $wrap = true; //when false adds a newline after each segment

/**
* @var string : component separator character (default :)
Expand Down Expand Up @@ -55,6 +56,8 @@ public function __construct($array = null, $wrap = true)
public function encode($arr, $wrap = true, $filterKeys = false)
{
$this->originalArray = $arr;
$this->wrap = $wrap;

$edistring = '';
$count = count($arr);
$k = 0;
Expand Down Expand Up @@ -117,12 +120,16 @@ private function escapeValue($str)
public function get()
{
if ($this->UNAActive) {
return "UNA" . $this->sepComp .
$una = "UNA" . $this->sepComp .
$this->sepData .
$this->sepDec .
$this->symbRel .
$this->symbRep .
$this->symbEnd . $this->output;
$this->symbEnd ;
if ($this->wrap === false) {
$una .= "\n";
}
return $una . $this->output;
} else {
return $this->output;
}
Expand Down

0 comments on commit d241211

Please sign in to comment.