Skip to content

Commit e4903a8

Browse files
authored
Merge pull request #131 from dextra-solutions/master
Public getter for encoding + error message extensions
2 parents d4c8450 + 1f23048 commit e4903a8

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/EDI/Interpreter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ private function loopMessage(array &$message, \SimpleXMLElement $xml, array &$er
479479
if ($segmentIdx != \count($message)) {
480480
$errors[] = [
481481
'text' => $this->messageTextConf['NOTCONFORMANT'],
482+
'position' => $segmentIdx,
483+
'segmentId' => $message[$segmentIdx][0],
482484
];
483485
}
484486

src/EDI/Parser.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function checkEncoding(): bool
284284
}
285285

286286
if (! isset(self::$charsets[$this->syntaxID])) {
287-
throw new \RuntimeException('Unsupported syntax identifier');
287+
throw new \RuntimeException('Unsupported syntax identifier: ' . $this->syntaxID);
288288
}
289289

290290
return mb_check_encoding($this->parsedfile, self::$charsets[$this->syntaxID]);
@@ -328,6 +328,24 @@ public function getRawSegments(): array
328328
return $this->rawSegments;
329329
}
330330

331+
/**
332+
* Get character encoding extracted from UNB header
333+
*
334+
* @return string
335+
*/
336+
public function getCharset(): string
337+
{
338+
if (empty($this->parsedfile)) {
339+
throw new \RuntimeException('No text has been parsed yet');
340+
}
341+
342+
if (! isset(self::$charsets[$this->syntaxID])) {
343+
throw new \RuntimeException('Unsupported syntax identifier: ' . $this->syntaxID);
344+
}
345+
346+
return self::$charsets[$this->syntaxID];
347+
}
348+
331349
/**
332350
* Load the message from file.
333351
*

0 commit comments

Comments
 (0)