Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,19 @@ abstract class Command extends EventEmitter implements CommandInterface
*/
const INIT_AUTHENTICATE = 0xf1;

/**
* @var Connection
*/
protected $connection;

private $states = [];

private $error;

/**
* Construtor.
* Constructor.
*
* @param integer $cmd
* @param string $q
* @param Connection $connection
*/
public function __construct(Connection $connection)
{
Expand Down
23 changes: 14 additions & 9 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ class Connection extends EventEmitter implements ConnectionInterface
public function __construct(LoopInterface $loop, array $connectOptions = array(), ConnectorInterface $connector = null)
{
$this->loop = $loop;

if (!$connector) {
$connector = new Connector($loop);
}
$this->connector = $connector;

$this->executor = new Executor($this);
$this->options = $connectOptions + $this->options;

$this->options = array_replace($this->options, $connectOptions);
}

/**
Expand Down Expand Up @@ -262,7 +265,7 @@ public function getServerOptions()
}

/**
* @param Exception $err Error from socket.
* @param \Exception $err Error from socket.
*
* @return void
* @internal
Expand Down Expand Up @@ -293,12 +296,14 @@ public function handleConnectionClosed()
*/
protected function _doCommand(Command $command)
{
if ($command->equals(Command::INIT_AUTHENTICATE)) {
return $this->executor->undequeue($command);
} elseif ($this->state >= self::STATE_CONNECTING && $this->state <= self::STATE_AUTHENTICATED) {
return $this->executor->enqueue($command);
} else {
throw new Exception("Can't send command");
}
if ($command->equals(Command::INIT_AUTHENTICATE)) {
return $this->executor->undequeue($command);
}

if ($this->state >= self::STATE_CONNECTING && $this->state <= self::STATE_AUTHENTICATED) {
return $this->executor->enqueue($command);
}

throw new Exception("Can't send command");
}
}
Loading