Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
namespace React\Socket;
4
 
5
/**
6
 * Decorates an existing Connector to always use a fixed, preconfigured URI
7
 *
8
 * This can be useful for consumers that do not support certain URIs, such as
9
 * when you want to explicitly connect to a Unix domain socket (UDS) path
10
 * instead of connecting to a default address assumed by an higher-level API:
11
 *
12
 * ```php
13
 * $connector = new React\Socket\FixedUriConnector(
14
 *     'unix:///var/run/docker.sock',
15
 *     new React\Socket\UnixConnector($loop)
16
 * );
17
 *
18
 * // destination will be ignored, actually connects to Unix domain socket
19
 * $promise = $connector->connect('localhost:80');
20
 * ```
21
 */
22
class FixedUriConnector implements ConnectorInterface
23
{
24
    private $uri;
25
    private $connector;
26
 
27
    /**
28
     * @param string $uri
29
     * @param ConnectorInterface $connector
30
     */
31
    public function __construct($uri, ConnectorInterface $connector)
32
    {
33
        $this->uri = $uri;
34
        $this->connector = $connector;
35
    }
36
 
37
    public function connect($_)
38
    {
39
        return $this->connector->connect($this->uri);
40
    }
41
}