Reuse code a bit.

This commit is contained in:
Daniele Alessandri
2011-01-04 10:55:39 +01:00
parent d94ad9942f
commit 306ed28c5d
+8 -3
View File
@@ -644,6 +644,7 @@ class ResponseReader {
public function read(IConnectionSingle $connection) {
$header = $connection->readLine();
if ($header === '') {
$this->throwMalformedResponse('Unexpected empty header');
Utils::onCommunicationException(new MalformedServerResponse(
$connection, 'Unexpected empty header'
));
@@ -651,13 +652,17 @@ class ResponseReader {
$prefix = $header[0];
if (!isset($this->_prefixHandlers[$prefix])) {
Utils::onCommunicationException(new MalformedServerResponse(
$connection, "Unknown prefix '$prefix'"
));
$this->throwMalformedResponse("Unknown prefix '$prefix'");
}
$handler = $this->_prefixHandlers[$prefix];
return $handler->handle($connection, substr($header, 1));
}
private function throwMalformedResponse($message) {
Utils::onCommunicationException(new MalformedServerResponse(
$connection, $message
));
}
}
class ResponseError {