mirror of
https://github.com/predis/predis.git
synced 2026-10-15 16:26:48 +00:00
Reorganize the Predis\Protocols namespace.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Predis\Protocols\Text;
|
||||
|
||||
use Predis\Helpers;
|
||||
use Predis\Protocols\IResponseHandler;
|
||||
use Predis\Network\IConnectionComposable;
|
||||
|
||||
class ResponseMultiBulkHandler implements IResponseHandler {
|
||||
public function handle(IConnectionComposable $connection, $lengthString) {
|
||||
$length = (int) $lengthString;
|
||||
if ($length != $lengthString) {
|
||||
Helpers::onCommunicationException(new ProtocolException(
|
||||
$connection, "Cannot parse '$length' as data length"
|
||||
));
|
||||
}
|
||||
|
||||
if ($length === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$list = array();
|
||||
if ($length > 0) {
|
||||
$handlersCache = array();
|
||||
$reader = $connection->getProtocol()->getReader();
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$header = $connection->readLine();
|
||||
$prefix = $header[0];
|
||||
if (isset($handlersCache[$prefix])) {
|
||||
$handler = $handlersCache[$prefix];
|
||||
}
|
||||
else {
|
||||
$handler = $reader->getHandler($prefix);
|
||||
$handlersCache[$prefix] = $handler;
|
||||
}
|
||||
$list[$i] = $handler->handle($connection, substr($header, 1));
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user