Skip to content

Added possibility for debug plugins #22

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 7 commits into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
### Added

- Suggest separate plugins in composer.json
- Introduced `debug_plugins` option for `PluginClient`


## 1.1.0 - 2016-05-04
Expand Down
15 changes: 13 additions & 2 deletions src/PluginClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ final class PluginClient implements HttpClient, HttpAsyncClient
* @param Plugin[] $plugins
* @param array $options {
*
* @var int $max_restarts
* @var int $max_restarts
* @var Plugin[] $debug_plugins an array of plugins that are injected between all normal plugins
Copy link
Contributor

Choose a reason for hiding this comment

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

s/all normal plugins/each normal plugin/

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you.

* }
*
* @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient
Expand Down Expand Up @@ -110,6 +111,7 @@ private function configure(array $options = [])
$resolver = new OptionsResolver();
$resolver->setDefaults([
'max_restarts' => 10,
'debug_plugins' => [],
Copy link
Member

@sagikazarmark sagikazarmark Jul 4, 2016

Choose a reason for hiding this comment

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

Can we add a type check for plugins somewhere? Does the OptionsResolver support "an array of type" check?

Copy link
Contributor

@dbu dbu Jul 4, 2016 via email

Choose a reason for hiding this comment

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

]);

return $resolver->resolve($options);
Expand All @@ -127,7 +129,16 @@ private function createPluginChain($pluginList, callable $clientCallable)
{
$firstCallable = $lastCallable = $clientCallable;

while ($plugin = array_pop($pluginList)) {
/*
* Inject debug plugins between each plugin.
*/
$pluginListWithDebug = $this->options['debug_plugins'];
foreach ($pluginList as $plugin) {
$pluginListWithDebug[] = $plugin;
$pluginListWithDebug = array_merge($pluginListWithDebug, $this->options['debug_plugins']);
}

while ($plugin = array_pop($pluginListWithDebug)) {
$lastCallable = function (RequestInterface $request) use ($plugin, $lastCallable, &$firstCallable) {
return $plugin->handleRequest($request, $lastCallable, $firstCallable);
};
Expand Down