@@ -12,10 +12,17 @@ class LDClient {
1212 protected $ _baseUri ;
1313 protected $ _client ;
1414
15- public function __construct ($ apiKey , $ baseUri = self :: DEFAULT_BASE_URI ) {
15+ public function __construct ($ apiKey , $ options = [] ) {
1616 $ this ->_apiKey = $ apiKey ;
17- $ this ->_baseUri = $ baseUri ;
18- $ this ->_client = $ this ->_make_client ();
17+ $ this ->_baseUri = $ options ['base_uri ' ] ? rtrim ($ options ['base_uri ' ], '/ ' ) : self ::DEFAULT_BASE_URI ;
18+ if (!isset ($ options ['timeout ' ])) {
19+ $ options ['timeout ' ] = 3 ;
20+ }
21+ if (!isset ($ options ['connect_timeout ' ])) {
22+ $ options ['connect_timeout ' ] = 3 ;
23+ }
24+
25+ $ this ->_client = $ this ->_make_client ($ options );
1926 }
2027
2128 public function getFlag ($ key , $ user , $ default = false ) {
@@ -47,11 +54,14 @@ protected function _make_client() {
4754 'Authorization ' => "api_key {$ this ->_apiKey }" ,
4855 'Content-Type ' => 'application/json ' ,
4956 'User-Agent ' => 'PHPClient/ ' . VERSION
50- ]
57+ ],
58+ 'timeout ' => $ options ['timeout ' ],
59+ 'connect_timeout ' => $ options ['connect_timeout ' ]
5160 ]
5261 ]);
5362
54- CacheSubscriber::attach ($ client );
63+ $ csOptions = $ options ['cache_storage ' ] ? ['storage ' => $ options ['cache_storage ' ]] : [];
64+ CacheSubscriber::attach ($ client , $ csOptions );
5565 return $ client ;
5666 }
5767
0 commit comments