EDI\Interpreter::prepare PHP Method

prepare() public method

Split multiple messages and process
public prepare ( $parsed ) : array
$parsed An array coming from EDI\Parser
return array
    public function prepare($parsed)
    {
        $this->msgs = self::splitMessages($parsed);
        $groups = [];
        $errors = [];
        $service = $this->msgs['service'];
        $this->serviceSeg = $this->processService($service);
        foreach ($this->msgs as $k => $msg) {
            if ($k === 'service') {
                continue;
            }
            $grouped = $this->loopMessage($msg, $this->xmlMsg);
            $groups[] = $grouped['message'];
            $errors[] = $grouped['errors'];
        }
        $this->ediGroups = $groups;
        $this->errors = $errors;
        return $groups;
    }

Usage Example

Example #1
0
 public function testDESADV()
 {
     $parser = new Parser(__DIR__ . "/../files/D96ADESADV.edi");
     $mapping = new \EDI\Mapping\MappingProvider('D96A');
     $analyser = new Analyser();
     $segs = $analyser->loadSegmentsXml($mapping->getSegments());
     $svc = $analyser->loadSegmentsXml($mapping->getServiceSegments(3));
     $interpreter = new Interpreter($mapping->getMessage('desadv'), $segs, $svc);
     $interpreter->prepare($parser->get());
     $this->assertJsonStringEqualsJsonFile(__DIR__ . "/../files/D96ADESADV.json", $interpreter->getJson(true), "JSON does not match expected output");
     $this->assertCount(2, $interpreter->getMessages());
     $this->assertCount(1, $interpreter->getErrors());
     $this->assertCount(2, $interpreter->getServiceSegments());
     $this->assertEquals([[]], $interpreter->getErrors());
 }