| 1 |
<?php |
| 2 |
|
| 3 |
namespace Clue\Redis\Protocol\Model; |
| 4 |
|
| 5 |
use Clue\Redis\Protocol\Serializer\SerializerInterface; |
| 6 |
|
| 7 |
class Request implements ModelInterface |
| 8 |
{ |
| 9 |
private $command; |
| 10 |
private $args; |
| 11 |
|
| 12 |
public function __construct($command, array $args = array()) |
| 13 |
{ |
| 14 |
$this->command = $command; |
| 15 |
$this->args = $args; |
| 16 |
} |
| 17 |
|
| 18 |
public function getCommand() |
| 19 |
{ |
| 20 |
return $this->command; |
| 21 |
} |
| 22 |
|
| 23 |
public function getArgs() |
| 24 |
{ |
| 25 |
return $this->args; |
| 26 |
} |
| 27 |
|
| 28 |
public function getReplyModel() |
| 29 |
{ |
| 30 |
$models = array(new BulkReply($this->command)); |
| 31 |
foreach ($this->args as $arg) { |
| 32 |
$models []= new BulkReply($arg); |
| 33 |
} |
| 34 |
|
| 35 |
return new MultiBulkReply($models); |
| 36 |
} |
| 37 |
|
| 38 |
public function getValueNative() |
| 39 |
{ |
| 40 |
$ret = $this->args; |
| 41 |
array_unshift($ret, $this->command); |
| 42 |
|
| 43 |
return $ret; |
| 44 |
} |
| 45 |
|
| 46 |
public function getMessageSerialized(SerializerInterface $serializer) |
| 47 |
{ |
| 48 |
return $serializer->getRequestMessage($this->command, $this->args); |
| 49 |
} |
| 50 |
} |