EDI\Reader::readGroups PHP Method

readGroups() public method

get groups from message
public readGroups ( char $before, type $start, type $end, type $after ) : boolean/array
$before char segment before groups
$start type first segment of group
$end type last segment of group
$after type segment after groups
return boolean/array
    public function readGroups($before, $start, $end, $after)
    {
        $groups = [];
        $group = [];
        $position = 'before_search';
        foreach ($this->parsedfile as $edi_row) {
            //echo $edi_row[0].' '.$position.PHP_EOL;
            //search before group segment
            if ($position == 'before_search' && $edi_row[0] == $before) {
                $position = 'before_is';
                continue;
            }
            if ($position == 'before_search') {
                continue;
            }
            if ($position == 'before_is' && $edi_row[0] == $before) {
                continue;
            }
            //after before search start
            if ($position == 'before_is' && $edi_row[0] == $start) {
                $position = 'group_is';
                $group[] = $edi_row;
                continue;
            }
            //if after before segment no start segment, search again before segment
            if ($position == 'before_is') {
                $position = 'before_search';
                continue;
            }
            //get group element
            if ($position == 'group_is' && $edi_row[0] != $end) {
                $group[] = $edi_row;
                continue;
            }
            //found end of group
            if ($position == 'group_is' && $edi_row[0] == $end) {
                $position = 'group_finish';
                $group[] = $edi_row;
                $groups[] = $group;
                $group = [];
                continue;
            }
            //next group start
            if ($position == 'group_finish' && $edi_row[0] == $start) {
                $group[] = $edi_row;
                $position = 'group_is';
                continue;
            }
            //finish
            if ($position == 'group_finish' && $edi_row[0] == $after) {
                break;
            }
            $this->errors[] = 'Reading group ' . $before . '/' . $start . '/' . $end . '/' . $after . '. Error on position: ' . $position;
            return false;
        }
        return $groups;
    }