Skip to content

Commit 68f0648

Browse files
committed
Retrieve message format from UNH segment
1 parent 874841a commit 68f0648

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/EDI/Parser.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class Parser
4343
* @var string : encoding (default UNOB)
4444
*/
4545
private $encoding;
46+
/**
47+
* @var string : message format from UNH
48+
*/
49+
private $messageFormat;
50+
/**
51+
* @var string : message directory
52+
*/
53+
private $messageDirectory;
4654

4755
private $encodingToStripChars = [
4856
"UNOA" => "/[\x01-\x1F\x80-\xFF]/", // not as restrictive as it should be
@@ -203,7 +211,16 @@ public function analyseUNB($encoding)
203211
*/
204212
public function analyseUNH($line)
205213
{
206-
214+
if (count($line)<3) {
215+
return;
216+
}
217+
$lineElement = $line[2];
218+
if (!is_array($lineElement)) {
219+
$this->messageFormat = $lineElement;
220+
return;
221+
}
222+
$this->messageFormat = $lineElement[0];
223+
$this->messageDirectory = $lineElement[2];
207224
}
208225

209226
//unwrap string splitting rows on terminator (if not escaped)
@@ -296,4 +313,14 @@ public function setStripRegex($regex)
296313
{
297314
$this->stripChars=$regex;
298315
}
316+
317+
public function getMessageFormat()
318+
{
319+
return $this->messageFormat;
320+
}
321+
322+
public function getMessageDirectory()
323+
{
324+
return $this->messageDirectory;
325+
}
299326
}

0 commit comments

Comments
 (0)