123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace Predis\Protocol\Text;
- use Predis\Command\CommandInterface;
- use Predis\Connection\ComposableConnectionInterface;
- use Predis\Protocol\ProtocolProcessorInterface;
- use Predis\Protocol\RequestSerializerInterface;
- use Predis\Protocol\ResponseReaderInterface;
- class ComposableProtocolProcessor implements ProtocolProcessorInterface
- {
- protected $serializer;
- protected $reader;
-
- public function __construct(
- RequestSerializerInterface $serializer = null,
- ResponseReaderInterface $reader = null
- ) {
- $this->setRequestSerializer($serializer ?: new RequestSerializer());
- $this->setResponseReader($reader ?: new ResponseReader());
- }
-
- public function serialize(CommandInterface $command)
- {
- return $this->serializer->serialize($command);
- }
-
- public function write(ComposableConnectionInterface $connection, CommandInterface $command)
- {
- $connection->writeBytes($this->serializer->serialize($command));
- }
-
- public function read(ComposableConnectionInterface $connection)
- {
- return $this->reader->read($connection);
- }
-
- public function setRequestSerializer(RequestSerializerInterface $serializer)
- {
- $this->serializer = $serializer;
- }
-
- public function getRequestSerializer()
- {
- return $this->serializer;
- }
-
- public function setResponseReader(ResponseReaderInterface $reader)
- {
- $this->reader = $reader;
- }
-
- public function getResponseReader()
- {
- return $this->reader;
- }
- }
|