Skip to content

Commit d241211

Browse files
authored
Merge pull request #79 from hgajjar/bugfix/una-add-new-line
MISC: Add new line to UNA segment line
2 parents 765ffc1 + 1c6961e commit d241211

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/EDI/Encoder.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* EDIFACT Messages Encoder
4-
* (c)2016 Stefano Sabatini
4+
* (c) 2018 Stefano Sabatini
55
*/
66

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

1617
/**
1718
* @var string : component separator character (default :)
@@ -55,6 +56,8 @@ public function __construct($array = null, $wrap = true)
5556
public function encode($arr, $wrap = true, $filterKeys = false)
5657
{
5758
$this->originalArray = $arr;
59+
$this->wrap = $wrap;
60+
5861
$edistring = '';
5962
$count = count($arr);
6063
$k = 0;
@@ -117,12 +120,16 @@ private function escapeValue($str)
117120
public function get()
118121
{
119122
if ($this->UNAActive) {
120-
return "UNA" . $this->sepComp .
123+
$una = "UNA" . $this->sepComp .
121124
$this->sepData .
122125
$this->sepDec .
123126
$this->symbRel .
124127
$this->symbRep .
125-
$this->symbEnd . $this->output;
128+
$this->symbEnd ;
129+
if ($this->wrap === false) {
130+
$una .= "\n";
131+
}
132+
return $una . $this->output;
126133
} else {
127134
return $this->output;
128135
}

0 commit comments

Comments
 (0)