FixedUriConnector
in package
implements
ConnectorInterface
Decorates an existing Connector to always use a fixed, preconfigured URI
This can be useful for consumers that do not support certain URIs, such as when you want to explicitly connect to a Unix domain socket (UDS) path instead of connecting to a default address assumed by an higher-level API:
$connector = new React\Socket\FixedUriConnector(
'unix:///var/run/docker.sock',
new React\Socket\UnixConnector()
);
// destination will be ignored, actually connects to Unix domain socket
$promise = $connector->connect('localhost:80');
Table of Contents
Interfaces
- ConnectorInterface
- The `ConnectorInterface` is responsible for providing an interface for establishing streaming connections, such as a normal TCP/IP connection.
Properties
- $connector : mixed
- $uri : mixed
Methods
- __construct() : mixed
- connect() : PromiseInterface<string|int, ConnectionInterface>
- Creates a streaming connection to the given remote address
Properties
$connector
private
mixed
$connector
$uri
private
mixed
$uri
Methods
__construct()
public
__construct(string $uri, ConnectorInterface $connector) : mixed
Parameters
- $uri : string
- $connector : ConnectorInterface
connect()
Creates a streaming connection to the given remote address
public
connect(mixed $_) : PromiseInterface<string|int, ConnectionInterface>
If returns a Promise which either fulfills with a stream implementing
ConnectionInterface
on success or rejects with an Exception
if the
connection is not successful.
$connector->connect('google.com:443')->then(
function (React\Socket\ConnectionInterface $connection) {
// connection successfully established
},
function (Exception $error) {
// failed to connect due to $error
}
);
The returned Promise MUST be implemented in such a way that it can be cancelled when it is still pending. Cancelling a pending promise MUST reject its value with an Exception. It SHOULD clean up any underlying resources and references as applicable.
$promise = $connector->connect($uri);
$promise->cancel();
Parameters
- $_ : mixed