Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add main Connector facade #93

Merged
merged 7 commits into from
Mar 29, 2017
Merged

Conversation

clue
Copy link
Contributor

@clue clue commented Mar 27, 2017

This PR adds a new Connector class that acts as a facade for all underlying connectors, which are now marked as "advanced usage", but continue to work unchanged.

The Connector class now makes it trivially easy to create plaintext TCP/IP, secure TLS and Unix domain socket connection streams like this:

$connector = new Connector($loop);

$connector->connect('tls://google.com:443')->then(function (ConnectionInterface $conn) {
    $conn->write('');
});

Resolves / closes #38

@clue clue added this to the v0.7.0 milestone Mar 27, 2017
}

if (!isset($this->connectors[$scheme])) {
return Promise\reject(new RuntimeException('No connector registered for unknown URI scheme'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest the following exception message:

return Promise\reject(new RuntimeException(
    sprintf(
        'No connector registered for URI scheme %s',
        $scheme
    )
));

$scheme = 'tcp';
if (strpos($uri, '://') !== false) {
$scheme = (string)substr($uri, 0, strpos($uri, '://'));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: if no scheme is explicitely given and port is 443, use tls connector.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More magic:

  • google.com with 'tcp' => false -> Use tls
  • google.com:443 with 'tls' => false -> Use tcp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both suggestions make sense in higher-level protocols (e.g. HTTP/HTTPS), but I'm hesitant to add them in the low-level network protocols (TCP/IP etc.) here.

I believe this is best left up to consumers of this package (such as react/http-client), but I guess it makes sense to add some kind of support for these kind of things in future versions 👍

@clue
Copy link
Contributor Author

clue commented Mar 28, 2017

Thanks for the suggestion, updated and squashed to use improved error message :shipit:

@WyriHaximus WyriHaximus self-requested a review March 28, 2017 11:03
@clue clue merged commit 1a0b360 into reactphp-legacy:master Mar 29, 2017
@clue clue deleted the connector branch March 29, 2017 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add simpler API (Facade pattern)
3 participants