Skip to content

Use xml to configure discovered clients #183

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
Jul 10, 2017
Merged

Use xml to configure discovered clients #183

merged 1 commit into from
Jul 10, 2017

Conversation

fbourigault
Copy link
Contributor

@fbourigault fbourigault commented Jul 7, 2017

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets partially #109
Documentation n/a
License MIT

This move discovered clients configuration from HttplugExtension to services.xml and data-collector.xml.

To Do

  • Add tests when discovered client is set to a configured service.

$httpClient = new Reference($httpClient);
if (!empty($httpClient) && $httpClient !== 'auto') {
$container->setAlias('httplug.auto_discovery.auto_discovered_client', $httpClient);
} elseif (null === $httpClient) {
Copy link
Member

Choose a reason for hiding this comment

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

Why "elseif"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because possible values are null, auto or any configured client name. So the first case handle the "any configured client name" and the elseif the null case which means remove the definition from the container.

$asyncHttpClient = new Reference($asyncHttpClient);
if (!empty($asyncHttpClient) && $asyncHttpClient !== 'auto') {
$container->setAlias('httplug.auto_discovery.auto_discovered_async', $asyncHttpClient);
} elseif (null === $asyncHttpClient) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here..

$container->setAlias('httplug.auto_discovery.auto_discovered_async', $asyncHttpClient);
} elseif (null === $asyncHttpClient) {
$container->removeDefinition('httplug.auto_discovery.auto_discovered_async');
$container->removeDefinition('httplug.collector.auto_discovered_async');
}

if (null === $httpClient && null === $asyncHttpClient) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this check still valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, If we have no discovered client (sync and async), we remove the useless listener.

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 a lot more readable to me.

an alternative to removing the definitions from the container could be to use separate files that we only load when the respective client is active. given the size of the xml file, i think it could be a good idea to split those out. wdyt?

@fbourigault
Copy link
Contributor Author

@dbu I will make conditional loading of some xml files. Far better than loading services and to remove them in the extension.I still have to fix a broken test I added in #184 and then I will improve configuration loading.

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.

Will this make the code even easier to read?

}

$httpClient = new Reference($httpClient);
if (!empty($httpClient) && $httpClient !== 'auto') {
Copy link
Member

Choose a reason for hiding this comment

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

if ($httpClient !== 'auto') {
   //...
  if (!empty($httpClient) {
     //...
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't used to write nested conditions (object calisthenics ❤️) but I will make an exception.

@fbourigault
Copy link
Contributor Author

I've update the code to make #184 tests fine.

About conditional xml loading, I don't think it worth it. I would need to load 5 different files (sync, async, sync_with_profiling, async_with_profiling and httplug.discovery).

I think it would be easier later as the profiling stuff will be handled differently (in the PluginClientFactory injected factory callback).

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 think this is a good improvement. lets merge as is. we can look at maybe splitting config files in a separate pull request.

@fbourigault
Copy link
Contributor Author

Thank you for reviews!

@fbourigault fbourigault merged commit 1b00264 into php-http:master Jul 10, 2017
@fbourigault fbourigault deleted the discovered-clients-refactoring branch July 10, 2017 12:41
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.

3 participants