/** * Class constructor * * @param mixed $url URL (string), stream (resource) or Q\Stream * @param array $options Additional options. Properties of this class, methods/callbacks of ssh2_connect() and auth ('none', 'password', 'publickey' or 'hostbased') + props for auth. */ public function __construct($url, $options = array()) { if (is_array($url)) { $options = $url + $options; $url = isset($options['url']) ? $options['url'] : null; } if (is_object($url) || isset($options['use'])) { $this->connection = is_object($url) ? $url : (is_object($options['use']) ? $options['use'] : Stream::create($options['use'], $options)); if (!interface_exists(__NAMESPACE__ . '::StreamingConnection', false) || !$this->connection instanceof StreamingConnection) { throw new Exception("You can't use an " . (is_object($this->connection) ? get_class($this->connection) : $this->connection) . " as a stream."); } } else { $this->connection = Connection::create($url, $options); } $this->copyfiles = !empty($options['copyfiles']); $this->keepalive = isset($this->stream) || !empty($options['keepalive']); }
/** * Create new Stream monad. * * @param mixed $value a value * @return Stream a Stream monad */ function stream($traversable) : Stream { return Stream::create($traversable); }