Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add PluginClientFactory support #202

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 13 commits into from
Sep 5, 2017
Merged

Add PluginClientFactory support #202

merged 13 commits into from
Sep 5, 2017

Conversation

fbourigault
Copy link
Contributor

@fbourigault fbourigault commented Aug 22, 2017

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets fixes #109
Documentation TODO
License MIT

Here we are! This PR is the journey achievement for 0 config profiling of 3rd party libraries.

It relies on php-http/client-common#83 which will be released with 1.6.0.

In a few words, it uses the Http\Client\Common\PluginClientFactory::setFactory internal method to replace the PluginClientFactory internals. By doing so, every 3rd party library which use the Http\Client\Common\PluginClientFactory to create it's client will automatically get profiling when used within a Symfony application.

To be more precise, clients created using the bundle configuration uses the Http\Client\Common\PluginClientFactory service as a DI factory which is replaced by an instance of Http\HttplugBundle\Collector\PluginClientFactory when profiling is enabled. Using the collector version of the PluginClientFactory make all clients and plugins decorated with appropriate decorators.

The Http\HttplugBundle\Collector\PluginClientFactorySubscriber inject the factory callback into `` at early Symfony events like Http\HttplugBundle\Discovery\ConfiguredClientsStrategy.

I still have to work on code comments and documentation, I open this pull request to get your feedback.

To Do

@fbourigault fbourigault requested review from Nyholm and dbu August 22, 2017 21:13
@fbourigault fbourigault added this to the 1.8.0 milestone Aug 22, 2017
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.

looks great! i added some nitpicks but things seem fine to me.

@@ -2,6 +2,8 @@

namespace Http\HttplugBundle\ClientFactory;

@trigger_error('The '.__NAMESPACE__.'\PluginClientFactory class is deprecated since version 1.8 and will be removed in 2.0.', E_USER_DEPRECATED);
Copy link
Collaborator

Choose a reason for hiding this comment

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

i am a big fan of telling people what to use instead. can we do that here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we could also add a @deprecated annotation in the class docblock to make IDEs show that there is a problem when using this class.

use Symfony\Component\Stopwatch\Stopwatch;

/**
* This factory is used as a replacement for Http\Client\Common\PluginClientFactory when profiling is enabled. It create
Copy link
Collaborator

Choose a reason for hiding this comment

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

It creates (with an s at the end)


/**
* This subscriber ensure that every PluginClient created when using Http\Client\Common\PluginClientFactory without
* using the Symfony dependency injection container use the Http\HttplugBundle\Collector\PluginClientFactory factory
Copy link
Collaborator

Choose a reason for hiding this comment

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

this subscriber ensures that ... injection container uses the ...

@fbourigault
Copy link
Contributor Author

David, I addressed all your comments. Thanks for the proofreading!

@Nyholm
Copy link
Member

Nyholm commented Aug 26, 2017

I think this looks good. All my clients are called "Default" now. But I guess that will be fixed when this PR is rebased.

@fbourigault
Copy link
Contributor Author

I just rebased the PR to include #200 and #201 changes.

@Nyholm clients names is now fixed. See latest commit.

@Nyholm
Copy link
Member

Nyholm commented Aug 28, 2017

Could you add the following to composer.json so the build has a change to be green:

    "minimum-stability": "dev",
    "prefer-dist": true,

@fbourigault
Copy link
Contributor Author

Do we all agree on how the PluginClientFactory stuff works? If so, we could release client-common 1.6 to make tests green.

@fbourigault
Copy link
Contributor Author

Do you plan to release client-common 1.6 before merging this PR?

@Nyholm
Copy link
Member

Nyholm commented Aug 28, 2017

I think we should postpone that until this PR is merged and we know (for sure) that the bundle and client-common works great together

@Nyholm
Copy link
Member

Nyholm commented Aug 30, 2017

Do you know why deps low test fails?

@fbourigault
Copy link
Contributor Author

Not yet, wanna give it a look today.


$dispatcher->dispatch(KernelEvents::REQUEST, $event);

return static::$kernel;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this might be confusing because the base test cases don't do it in older symfony versions. but i think its still a good idea. assigning the bootKernel return value, then accessing static::$kernel and in the end return the variable would be weird.

@Nyholm
Copy link
Member

Nyholm commented Sep 3, 2017

You can fix the broken tests by require "symfony/dependency-injection": "^2.8.3 || ^3.0"

@fbourigault
Copy link
Contributor Author

Thank you @Nyholm. Tests are now green. I used ^3.0.3 instead of ^3.0 because 2.8 and 3.0 contains the same bug fixes (I think the fix is symfony/symfony#17866).

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Okey, great. Im happy to merge this.

@dbu?

@fbourigault
Copy link
Contributor Author

I added a few changelog entries.

@fbourigault fbourigault changed the title [WIP] Add PluginClientFactory support Add PluginClientFactory support Sep 4, 2017
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.

another naming nitpick, apart from that i am happy with this PR. very cool!

*
* @internal
*/
final class PluginClientFactorySubscriber implements EventSubscriberInterface
Copy link
Collaborator

Choose a reason for hiding this comment

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

i heard such a class should still be called ...Listener. it semantically is an event listener. the subscriber interface is about how to wire up the listener and less central.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I updated the name.

@Nyholm
Copy link
Member

Nyholm commented Sep 4, 2017

Can you resolve the conflicts?

@fbourigault
Copy link
Contributor Author

Of course, I just created those when #203 gets merged!

@Nyholm
Copy link
Member

Nyholm commented Sep 5, 2017

One the merge conflicts is resolved, I'll be happy to merge

@Nyholm Nyholm merged commit f710b9f into php-http:master Sep 5, 2017
@Nyholm
Copy link
Member

Nyholm commented Sep 5, 2017

Thank you

@fbourigault fbourigault deleted the plugin-client-factory branch September 5, 2017 08:07
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.

Show plugins created without the Symfony config
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.