File tree 1 file changed +11
-9
lines changed
1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
/**
3
3
* EDIFACT Messages Encoder
4
- * (c)2016 Stefano Sabatini
4
+ * (c) 2018 Stefano Sabatini
5
5
*/
6
6
7
7
namespace EDI ;
@@ -12,6 +12,7 @@ class Encoder
12
12
private $ output = '' ;
13
13
private $ UNAActive = false ; // disable by default to preserve backward compatibility
14
14
private $ originalArray = [];
15
+ private $ wrap = true ; //when false adds a newline after each segment
15
16
16
17
/**
17
18
* @var string : component separator character (default :)
@@ -55,6 +56,8 @@ public function __construct($array = null, $wrap = true)
55
56
public function encode ($ arr , $ wrap = true , $ filterKeys = false )
56
57
{
57
58
$ this ->originalArray = $ arr ;
59
+ $ this ->wrap = $ wrap ;
60
+
58
61
$ edistring = '' ;
59
62
$ count = count ($ arr );
60
63
$ k = 0 ;
@@ -114,20 +117,19 @@ private function escapeValue($str)
114
117
return str_replace ($ search , $ replace , $ str );
115
118
}
116
119
117
- public function get ($ wrap = true )
120
+ public function get ()
118
121
{
119
122
if ($ this ->UNAActive ) {
120
-
121
- if ($ wrap === false ) {
122
- $ this ->symbEnd .= "\n" ;
123
- }
124
-
125
- return "UNA " . $ this ->sepComp .
123
+ $ una = "UNA " . $ this ->sepComp .
126
124
$ this ->sepData .
127
125
$ this ->sepDec .
128
126
$ this ->symbRel .
129
127
$ this ->symbRep .
130
- $ this ->symbEnd . $ this ->output ;
128
+ $ this ->symbEnd ;
129
+ if ($ this ->wrap === false ) {
130
+ $ una .= "\n" ;
131
+ }
132
+ return $ una . $ this ->output ;
131
133
} else {
132
134
return $ this ->output ;
133
135
}
You can’t perform that action at this time.
0 commit comments