File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,18 @@ class ClientFactory implements LoggerAwareInterface {
18
18
19
19
private $ client ;
20
20
private $ logger ;
21
+ private $ config ;
21
22
22
- public function __construct () {
23
+ /**
24
+ * @since 2.1.0
25
+ *
26
+ * @param array $config with possible keys:
27
+ * middleware => array of extra middleware to pass to guzzle
28
+ * user-agent => string default user agent to use for requests
29
+ */
30
+ public function __construct ( array $ config = array () ) {
23
31
$ this ->logger = new NullLogger ();
32
+ $ this ->config = $ config ;
24
33
}
25
34
26
35
/**
@@ -45,10 +54,22 @@ private function newClient() {
45
54
$ handlerStack = HandlerStack::create ( new CurlHandler () );
46
55
$ handlerStack ->push ( $ middlewareFactory ->retry () );
47
56
57
+ if ( array_key_exists ( 'user-agent ' , $ this ->config ) ) {
58
+ $ ua = $ this ->config ['user-agent ' ];
59
+ } else {
60
+ $ ua = 'Addwiki - mediawiki-api-base ' ;
61
+ }
62
+
63
+ if ( array_key_exists ( 'middleware ' , $ this ->config ) ) {
64
+ foreach ( $ this ->config ['middleware ' ] as $ middleware ) {
65
+ $ handlerStack ->push ( $ middleware );
66
+ }
67
+ }
68
+
48
69
return new Client ( array (
49
70
'cookies ' => true ,
50
71
'handler ' => $ handlerStack ,
51
- 'headers ' => array ( 'User-Agent ' => ' Addwiki - mediawiki-api-base ' ),
72
+ 'headers ' => array ( 'User-Agent ' => $ ua ),
52
73
) );
53
74
}
54
75
You can’t perform that action at this time.
0 commit comments