Livestatus\Connection: line splitting implementation

Will need some more work to get SplFixedArray handling safe
This commit is contained in:
Thomas Gelf 2014-11-16 16:02:50 +01:00
parent e1cdd30c93
commit 17c8453c1c
1 changed files with 23 additions and 0 deletions

View File

@ -257,6 +257,29 @@ class Connection
}
}
protected function splitLine(& $line)
{
if ($this->headers === null) {
$res = array();
} else {
$res = new SplFixedArray(count($this->headers));
$size = count($res);
}
$start = 0;
$col = 0;
while (false !== ($pos = strpos($line, self::FIELD_SEPARATOR, $start))) {
// TODO: safety measure for not killing the SPL. To be removed once code is clean
if ($col > $size -1 ) return $res; // ???
$res[$col] = substr($line, $start, $pos - $start);
$start = $pos + 1;
$col++;
}
// TODO: safety measure for not killing the SPL. To be removed once code is clean
if ($col > $size - 1) return $res;
$res[$col] = rtrim(substr($line, $start), "\r\n");
return $res;
}
public function fetchRowFromSocket()
{
$line = $this->readLineFromSocket();