@@ -109,12 +109,13 @@ Libraries that Require Plugins
109
109
110
110
When :doc: `writing a library based on HTTPlug <../httplug/library-developers >`, you might require
111
111
specific plugins to be active. The recommended way for doing this is to provide a factory method
112
- for the ``PluginClient `` that your library users should use. This allows them to inject their own
112
+ for the ``PluginClient `` that library users should use. This allows them to inject their own
113
113
plugins or configure a different client. For example::
114
114
115
115
$myApiClient = new My\Api\Client('https://api.example.org', My\Api\HttpClientFactory::create('john', 's3cr3t'));
116
116
117
117
use Http\Client\HttpClient;
118
+ use Http\Client\Common\Plugin;
118
119
use Http\Client\Common\Plugin\AuthenticationPlugin;
119
120
use Http\Client\Common\Plugin\ErrorPlugin;
120
121
use Http\Discovery\HttpClientDiscovery;
@@ -124,22 +125,22 @@ plugins or configure a different client. For example::
124
125
/**
125
126
* Build the HTTP client to talk with the API.
126
127
*
127
- * @param string $user Username
128
- * @param string $pass Password
129
- * @param HttpClient $client Base HTTP client
128
+ * @param string $user Username for the application on the API
129
+ * @param string $pass Password for the application on the API
130
+ * @param Plugin[] $plugins List of additional plugins to use
131
+ * @param HttpClient $client Base HTTP client
130
132
*
131
133
* @return HttpClient
132
134
*/
133
- public static function create($user, $pass, HttpClient $client = null)
135
+ public static function create($user, $pass, array $plugins = [], HttpClient $client = null)
134
136
{
135
137
if (!$client) {
136
138
$client = HttpClientDiscovery::find();
137
139
}
138
- return new PluginClient($client, [
139
- new ErrorPlugin(),
140
- new AuthenticationPlugin(
141
- // This API has it own authentication algorithm
142
- new ApiAuthentication(Client::AUTH_OAUTH_TOKEN, $user, $pass)
143
- ),
144
- ]);
140
+ $plugins[] = new ErrorPlugin();
141
+ $plugins[] = new AuthenticationPlugin(
142
+ // This API has it own authentication algorithm
143
+ new ApiAuthentication(Client::AUTH_OAUTH_TOKEN, $user, $pass)
144
+ );
145
+ return new PluginClient($client, $plugins);
145
146
}
0 commit comments