-
Notifications
You must be signed in to change notification settings - Fork 6
Add getter/setter to the plugin client #43
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
Changes from all commits
ad39792
16c25b5
9558ed7
a70d550
5208c06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ final class PluginClient implements HttpClient, HttpAsyncClient | |
* | ||
* @var Plugin[] | ||
*/ | ||
private $plugins; | ||
private $plugins = []; | ||
|
||
/** | ||
* A list of options. | ||
|
@@ -57,10 +57,42 @@ public function __construct($client, array $plugins = [], array $options = []) | |
throw new \RuntimeException('Client must be an instance of Http\\Client\\HttpClient or Http\\Client\\HttpAsyncClient'); | ||
} | ||
|
||
$this->plugins = $plugins; | ||
$this->setPlugins($plugins); | ||
$this->options = $this->configure($options); | ||
} | ||
|
||
/** | ||
* Append a plugin to the end of the queue. | ||
* | ||
* @param Plugin $plugin | ||
*/ | ||
public function addPlugin(Plugin $plugin) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming to "appendPlugin"? Because you are appending items to the end of a queue. It would be more clear that the order of the plugins is important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I come from the symfony world and they use always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really think it matters, both sounds OK. The reason why I usually prefer add is that it fits into the three character long actions: add, get, set, has There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Agree, this behavior is crucial to be mentioned as the order of plugins matter. Probably this is a reason against allowing to add plugins runtime: it can cause confusions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we decide to want this functionality, i would call this appendPlugin, i find that more precise than add. we might also want prependPlugin at some point... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With prepend added it would indeed make sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be ok with addPlugin in normal. However, like described in our docs, order of plugins matters, so big 👍 for the appendPlugin / preprendPlugin method name. |
||
{ | ||
$this->plugins[] = $plugin; | ||
} | ||
|
||
/** | ||
* Get all active plugins. | ||
* | ||
* @return Plugin[] | ||
*/ | ||
public function getPlugins() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the use case of this? checking if a specific plugin is already in the chain? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep this was the idea behind it |
||
{ | ||
return $this->plugins; | ||
} | ||
|
||
/** | ||
* Assign plugins to the client. | ||
* | ||
* @param Plugin[] $plugins | ||
*/ | ||
public function setPlugins(array $plugins = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be appendPlugins, setPlugins makes me expect that this would replace the existing plugins (which would be a bad idea) |
||
{ | ||
foreach ($plugins as $plugin) { | ||
$this->addPlugin($plugin); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is the right way, i never worked with phpspec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine.