public function parse()
{
$fileLines = $this->getFileLines();
$data = [];
$currentSection = '';
$currentDivision = '';
for ($line = 0, $count = count($fileLines); $line < $count; ++$line) {
$currentLine = $fileLines[$line];
$currentLineLength = strlen($currentLine);
if ($currentLineLength === 0) {
continue;
}
if (substr($currentLine, 0, 40) === ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;') {
$currentDivision = trim(substr($currentLine, 41));
continue;
}
// We only skip comments that *start* with semicolon
if ($currentLine[0] === ';') {
continue;
}
if ($currentLine[0] === '[') {
$currentSection = substr($currentLine, 1, $currentLineLength - 2);
continue;
}
$bits = explode('=', $currentLine);
if (count($bits) > 2) {
throw new \RuntimeException("Too many equals in line: {$currentLine}, in Division: {$currentDivision}");
}
if (count($bits) < 2) {
$bits[1] = '';
}
$data[$currentSection][$bits[0]] = $bits[1];
$data[$currentSection]['Division'] = $currentDivision;
}
if ($this->shouldSort()) {
$data = $this->sortArrayAndChildArrays($data);
}
$this->data = $data;
return $data;
}