Reuse code a bit.

This commit is contained in:
Daniele Alessandri
2011-01-04 10:55:39 +01:00
parent cf522ff2b4
commit d46b0e0785
+8 -6
View File
@@ -686,20 +686,22 @@ class ResponseReader {
public function read(Connection $connection) {
$header = $connection->readLine();
if ($header === '') {
Shared\Utils::onCommunicationException(new MalformedServerResponse(
$connection, 'Unexpected empty header'
));
$this->throwMalformedResponse($connection, 'Unexpected empty header');
}
$prefix = $header[0];
if (!isset($this->_prefixHandlers[$prefix])) {
Shared\Utils::onCommunicationException(new MalformedServerResponse(
$connection, "Unknown prefix '$prefix'"
));
$this->throwMalformedResponse($connection, "Unknown prefix '$prefix'");
}
$handler = $this->_prefixHandlers[$prefix];
return $handler->handle($connection, substr($header, 1));
}
private function throwMalformedResponse(Connection $connection, $message) {
Shared\Utils::onCommunicationException(new MalformedServerResponse(
$connection, $message
));
}
}
class ResponseError {