Skip to content

Make it possible to create public httplug clients #280

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 1 commit into from
Oct 25, 2018

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Oct 24, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Documentation php-http/documentation#241
License MIT

What's in this PR?

Added public: true/false to the Configuration. It is used to make the created HTTPlug client public or private.

Why?

All HTTPlug clients that are created are private by default, which is a good thing. But sometimes, you just need a public HTTPlug client.

Checklist

  • Updated CHANGELOG.md to describe new feature
  • Documentation pull request created

@Nyholm
Copy link
Member

Nyholm commented Oct 24, 2018

Hm. I agree to this PR. We discussed it before and we said that the user should always want a private service since that is the best practice.

However, I know people tried to access them as they were public.. I don’t know if we ever talked about making it configurable, but I believe that would be awesome for all users.

👍

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

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

i agree with this. i'll check the doc PR next to see if we properly say that you SHOULD use private services and DI, but if you have a case where you want to make it public, you can.

config tests fail because a new option is there so the default config needs to be adjusted.

it would be nice to also have a test making sure that normally the client service is private but if we set public: true it indeed is set to public. that one should go into the HttplugExtensionTest

@ruudk
Copy link
Contributor Author

ruudk commented Oct 25, 2018

I added the tests and updated the documentation PR.

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

The test failures seem to be related to these changes. Also I think inside configureClient() we need to update the decorations happening at the end too.

@ruudk ruudk force-pushed the config-public branch 2 times, most recently from 96c891a to 83ae982 Compare October 25, 2018 11:15
@ruudk
Copy link
Contributor Author

ruudk commented Oct 25, 2018

@xabbuh Good catch. It now also makes the decorated services public. Also added tests for this.

I think the tests are failing because Symfony changed from default public services to default private services. I do added the setPublic call:

$container
->register($serviceId, PluginClient::class)
->setPublic($arguments['public'])
->setFactory([new Reference(PluginClientFactory::class), 'createClient'])
->addArgument(new Reference($serviceId.'.client'))

That means that existing services will break that rely on the service to be public, on older Symfony installations.

What would be the best way to solve this?

Maybe we should make the default value of public dependent on the Symfony version?

@ruudk
Copy link
Contributor Author

ruudk commented Oct 25, 2018

I made some changes to the test to check the Symfony version. I made the public configuration option null by default. That way, we know if the user actually tried to make the service public or not. It's always used in the decorated services (since they are private by default) and only used when it's a bool for the client.

The default null can be fixed in a new major version.

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

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

good solution! agree with how you do this.

this (implicitly) allows to set visibility to false for symfony < 3.4 be setting public to false - but i think we don't even need to add a test for that, its just until we can drop support for legacy versions of symfony.

@ruudk ruudk force-pushed the config-public branch 2 times, most recently from 2fcedcc to 9377c0b Compare October 25, 2018 13:05
@ruudk
Copy link
Contributor Author

ruudk commented Oct 25, 2018

@xabbuh Tests are now fixed and green ✅ 🤗

@dbu dbu merged commit e198392 into php-http:master Oct 25, 2018
@dbu
Copy link
Collaborator

dbu commented Oct 25, 2018

thanks for this contribution @ruudk !

@ruudk ruudk deleted the config-public branch October 25, 2018 15:28
@ruudk
Copy link
Contributor Author

ruudk commented Oct 25, 2018

Thanks for merging @dbu. When will it get released?

@dbu
Copy link
Collaborator

dbu commented Oct 25, 2018

i am updating the changelog in #281, once that is good we can tag the release

@dbu
Copy link
Collaborator

dbu commented Oct 26, 2018

done: https://github.com/php-http/HttplugBundle/releases/tag/1.12.0

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.

4 participants