Skip to content

Commit 1c6961e

Browse files
authored
Refactor $wrap
1 parent 4cde8d9 commit 1c6961e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/EDI/Encoder.php

+11-9
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;
@@ -114,20 +117,19 @@ private function escapeValue($str)
114117
return str_replace($search, $replace, $str);
115118
}
116119

117-
public function get($wrap = true)
120+
public function get()
118121
{
119122
if ($this->UNAActive) {
120-
121-
if ($wrap === false) {
122-
$this->symbEnd .= "\n";
123-
}
124-
125-
return "UNA" . $this->sepComp .
123+
$una = "UNA" . $this->sepComp .
126124
$this->sepData .
127125
$this->sepDec .
128126
$this->symbRel .
129127
$this->symbRep .
130-
$this->symbEnd . $this->output;
128+
$this->symbEnd ;
129+
if ($this->wrap === false) {
130+
$una .= "\n";
131+
}
132+
return $una . $this->output;
131133
} else {
132134
return $this->output;
133135
}

0 commit comments

Comments
 (0)