123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace Predis\Protocol\Text;
- use Predis\CommunicationException;
- use Predis\Connection\ComposableConnectionInterface;
- use Predis\Protocol\ProtocolException;
- use Predis\Protocol\ResponseHandlerInterface;
- class ResponseMultiBulkHandler implements ResponseHandlerInterface
- {
-
- public function handle(ComposableConnectionInterface $connection, $lengthString)
- {
- $length = (int) $lengthString;
- if ("$length" !== $lengthString) {
- CommunicationException::handle(new ProtocolException(
- $connection, "Cannot parse '$lengthString' as multi-bulk 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;
- }
- }
|