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 simpler API (Facade pattern) #38

Closed
clue opened this issue Jun 7, 2015 · 2 comments · Fixed by #93
Closed

Add simpler API (Facade pattern) #38

clue opened this issue Jun 7, 2015 · 2 comments · Fixed by #93

Comments

@clue
Copy link
Contributor

clue commented Jun 7, 2015

Let's face it, our API might be clean (arguably), but it's cumbersome to work with.

IMO we should first figure out some use cases for our API to see how this is actually going to be used.

The socket-client component is quite lowlevel, so it's unlikely to be used by many users directly. It's probably more likely going to be used as part of some high level abstractions (say, a Redis or MySQL client implementation). See also https://libraries.io/packagist/react%2Fsocket-client/dependents

These high level components depend on a ConnectorInterface and will likely use DI to inject this. They probably care little about how the connector works. Neither should they care about any "additional" parameters. They do care about the target (hostname and port). Hence (IMHO) they should not have to take care of context options, connection timeouts or even selecting the "right" connector.

Afaict all they (essentially) need to do is to establish a connection to a given remote location. As such, I'm suggesting a simplified API similar to this:

// probably one of the most common use cases
$api->createConnection('tcp://www.google.com:80');

// automatically assumes TCP transport, as does fsockopen()
$api->createConnection('www.google.com:80');

// automatically picks use secure connector
$api->createConnection('tls://www.google.com:443');

Also, once we support Unix domain sockets (#37):

// create Unix domain socket, as does fsockopen()
$api->createConnection('unix:///var/tmp/demo.sock');

The implementation of such a facade would be pretty easy, it could accept a Connector and SecureConnector (or any other classes implementing the ConnectorInterface for that matter).

This facade would probably become the one class that every consumer of this component is going to use. The other classes should probably be left as-is and can still be used in advanced scenarios.

@clue
Copy link
Contributor Author

clue commented Apr 20, 2016

See also reactphp/reactphp#199

@clue
Copy link
Contributor Author

clue commented Feb 16, 2017

This will be deferred to one of the next releases

@clue clue added this to the v0.7.0 milestone Mar 10, 2017
@clue clue self-assigned this Mar 10, 2017
@clue clue closed this as completed in #93 Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant