-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from clue-labs/socket
Factory accepts Connector from Socket and deprecate legacy SocketClient
- Loading branch information
Showing
8 changed files
with
174 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Clue\React\Redis; | ||
|
||
use Evenement\EventEmitter; | ||
use React\Socket\ConnectionInterface; | ||
use React\Stream\DuplexStreamInterface; | ||
use React\Stream\WritableStreamInterface; | ||
use React\Stream\Util; | ||
|
||
/** | ||
* Adapter to upcast a legacy SocketClient-Connector result to a new Socket-ConnectionInterface | ||
* | ||
* @internal | ||
*/ | ||
class ConnectionUpcaster extends EventEmitter implements ConnectionInterface | ||
{ | ||
private $stream; | ||
|
||
public function __construct(DuplexStreamInterface $stream) | ||
{ | ||
$this->stream = $stream; | ||
|
||
Util::forwardEvents($stream, $this, array('data', 'end', 'close', 'error', 'drain')); | ||
$this->stream->on('close', array($this, 'close')); | ||
} | ||
|
||
public function isReadable() | ||
{ | ||
return $this->stream->isReadable(); | ||
} | ||
|
||
public function isWritable() | ||
{ | ||
return $this->isWritable(); | ||
} | ||
|
||
public function pause() | ||
{ | ||
$this->stream->pause(); | ||
} | ||
|
||
public function resume() | ||
{ | ||
$this->stream->resume(); | ||
} | ||
|
||
public function pipe(WritableStreamInterface $dest, array $options = array()) | ||
{ | ||
$this->stream->pipe($dest, $options); | ||
} | ||
|
||
public function write($data) | ||
{ | ||
return $this->stream->write($data); | ||
} | ||
|
||
public function end($data = null) | ||
{ | ||
return $this->stream->end($data); | ||
} | ||
|
||
public function close() | ||
{ | ||
$this->stream->close(); | ||
$this->removeAllListeners(); | ||
} | ||
|
||
public function getRemoteAddress() | ||
{ | ||
return null; | ||
} | ||
|
||
public function getLocalAddress() | ||
{ | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Clue\React\Redis; | ||
|
||
use React\Socket\ConnectorInterface; | ||
use React\SocketClient\ConnectorInterface as LegacyConnectorInterface; | ||
use React\Stream\DuplexStreamInterface; | ||
|
||
/** | ||
* Adapter to upcast a legacy SocketClient:v0.7/v0.6 Connector to a new Socket:v0.8 Connector | ||
* | ||
* @internal | ||
*/ | ||
class ConnectorUpcaster implements ConnectorInterface | ||
{ | ||
private $legacy; | ||
|
||
public function __construct(LegacyConnectorInterface $connector) | ||
{ | ||
$this->legacy = $connector; | ||
} | ||
|
||
public function connect($uri) | ||
{ | ||
return $this->legacy->connect($uri)->then(function (DuplexStreamInterface $stream) { | ||
return new ConnectionUpcaster($stream); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters