1: <?php
2:
3: namespace React\Socket;
4:
5: use React\Socket\ConnectorInterface;
6: use React\EventLoop\LoopInterface;
7: use React\Promise;
8: use RuntimeException;
9:
10: 11: 12: 13: 14: 15:
16: final class UnixConnector implements ConnectorInterface
17: {
18: private $loop;
19:
20: public function __construct(LoopInterface $loop)
21: {
22: $this->loop = $loop;
23: }
24:
25: public function connect($path)
26: {
27: if (strpos($path, '://') === false) {
28: $path = 'unix://' . $path;
29: } elseif (substr($path, 0, 7) !== 'unix://') {
30: return Promise\reject(new \InvalidArgumentException('Given URI "' . $path . '" is invalid'));
31: }
32:
33: $resource = @stream_socket_client($path, $errno, $errstr, 1.0);
34:
35: if (!$resource) {
36: return Promise\reject(new RuntimeException('Unable to connect to unix domain socket "' . $path . '": ' . $errstr, $errno));
37: }
38:
39: return Promise\resolve(new Connection($resource, $this->loop));
40: }
41: }
42: