Skip to content

Add client builder #480

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

Merged
merged 16 commits into from
Dec 9, 2016
Merged

Add client builder #480

merged 16 commits into from
Dec 9, 2016

Conversation

Nyholm
Copy link
Collaborator

@Nyholm Nyholm commented Dec 4, 2016

This will fix #461

The client builder makes sure that all logic related to creating the client is in a separate class.
This is a first draft and feedback is welcome.

TODO

  • Fix the tests
  • Update docs

@acrobat
Copy link
Collaborator

acrobat commented Dec 4, 2016

I like the idea! 👍

@acrobat
Copy link
Collaborator

acrobat commented Dec 5, 2016

@Nyholm you should also update the docs for customizing the api-client as setHttpClient is now removed

@Nyholm
Copy link
Collaborator Author

Nyholm commented Dec 5, 2016

Thank you. I've updated the PR

@acrobat
Copy link
Collaborator

acrobat commented Dec 5, 2016

}



Copy link
Contributor

Choose a reason for hiding this comment

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

too many empty lines?


/**
* A builder that builds the API client. This will allow you to fluently add and remove
* plugins.
Copy link
Contributor

Choose a reason for hiding this comment

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

you can place each sentence on new line, right now it feels a bit strange :D

*/
public function __construct(HttpClient $httpClient = null, $apiVersion = null, $enterpriseUrl = null)
public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it's better to leave old constructor and create new builder inline or support both.

Copy link
Collaborator

@acrobat acrobat Dec 6, 2016

Choose a reason for hiding this comment

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

Maybe keep the old constructor indeed but deprecated it (throw deprecation warning) and use the new constructor in 3.0. Or you could say use the new constructor from now on as 2.0 stable is not yet released

Copy link
Contributor

@cursedcoder cursedcoder Dec 6, 2016

Choose a reason for hiding this comment

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

My idea is that client should always be constructed without extra manipulations, i.e.

$github = new Client();
$github->doAnything();

// or
$github = new Client($guzzle);

maybe static factory can be a possible solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right about that, it should be a simple as possible to instantiate and use the client

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not like the new constructor myself to be honest. Should I add another constructor argument with the builder?

@Nyholm
Copy link
Collaborator Author

Nyholm commented Dec 6, 2016

I made an update. Are we happy with this constructor?

$httpBuilder = new Github\HttpClient\Builder(new Http\Adapter\Guzzle6\Client());
$httpBuilder->addPlugin(new CustomUserAgentPlugin());

$client = new Github\Client(null, $httpBuilder);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Check out this example.

Are we happy with the constructor like this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I don't know. It looks a bit weird to me that you must start with null. I will think about a different approach

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could keep Github\Client($httpBuilder, $version, $enterprice);
and then have a factory like:

Github\Client::create($guzzle);

Copy link
Collaborator

Choose a reason for hiding this comment

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

That would maybe be a good solution. What do you think @cursedcoder?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems nice.
Just Client::fromAdapter() or fromClient, put some more sense in your method name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great! I'll update the PR after lunch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Client::withHttpClient($guzzle)?
Client::usingHttpClient($guzzle)?
Client::createWithHttpClient($guzzle)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Client::createFromHttpClient($guzzle)? Otherwise I would go for createWith..

@Nyholm Nyholm mentioned this pull request Dec 6, 2016
@Nyholm
Copy link
Collaborator Author

Nyholm commented Dec 6, 2016

There, this PR is updated. I'm happy to change the name of createFromHttpClient to whatever.

My opinion is that you would not create a Github client from a http client. The Github client is using the http client somehow.

@acrobat
Copy link
Collaborator

acrobat commented Dec 6, 2016

YEs maybe you are right about the name of the method!

@Nyholm
Copy link
Collaborator Author

Nyholm commented Dec 6, 2016

YEs maybe you are right about the name of the method!

I have no strong opinions at all. =) @cursedcoder can you make a decision and I can consider this PR ready for final review.

@cursedcoder
Copy link
Contributor

My opinion is that you would not create a Github client from a http client. The Github client is using the http client somehow.

Got you. So it makes sense to rename createWithHttpClient?

@Nyholm
Copy link
Collaborator Author

Nyholm commented Dec 7, 2016

Thank you. I've updated the PR

@@ -5,6 +5,20 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee

## 2.0.0-rc5 (UNRELEASED)

### Changed
Copy link
Collaborator

@acrobat acrobat Dec 7, 2016

Choose a reason for hiding this comment

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

The changed part is already added for RC5 right under added (line 32 in your changed file)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's correct. Thank you.

@cursedcoder cursedcoder merged commit 4839bd9 into KnpLabs:master Dec 9, 2016
@Nyholm
Copy link
Collaborator Author

Nyholm commented Dec 9, 2016

Thank you for merging

@Nyholm Nyholm deleted the client-builder branch December 9, 2016 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use a factory or a configurator for the HTTP client
3 participants