1616use Http \Discovery \HttpClientDiscovery ;
1717use Http \Discovery \MessageFactoryDiscovery ;
1818use Http \Message \RequestFactory ;
19+ use GraphAware \Common \Connection \BaseConfiguration ;
1920
20- class Configuration implements ConfigInterface
21+ /**
22+ * @author Tobias Nyholm <[email protected] > 23+ */
24+ class Configuration extends BaseConfiguration implements ConfigInterface
2125{
2226 /**
2327 * @var int
@@ -31,34 +35,15 @@ class Configuration implements ConfigInterface
3135 */
3236 protected $ curlInterface ;
3337
34- /**
35- * @var HttpClient
36- */
37- private $ httpClient ;
38-
39- /**
40- * @var RequestFactory
41- */
42- private $ requestFactory ;
43-
4438 /**
4539 * @return Configuration
4640 */
4741 public static function create (HttpClient $ httpClient = null , RequestFactory $ requestFactory = null )
4842 {
49- $ config = new self ();
50- $ config ->httpClient = $ httpClient ?: HttpClientDiscovery::find ();
51- $ config ->requestFactory = $ requestFactory ?: MessageFactoryDiscovery::find ();
52-
53- return $ config ;
54- }
55-
56- /**
57- * @return HttpClient
58- */
59- public function getHttpClient ()
60- {
61- return $ this ->httpClient ;
43+ return new self ([
44+ 'http_client ' => $ httpClient ?: HttpClientDiscovery::find (),
45+ 'request_factory ' => $ requestFactory ?: MessageFactoryDiscovery::find (),
46+ ]);
6247 }
6348
6449 /**
@@ -68,18 +53,7 @@ public function getHttpClient()
6853 */
6954 public function setHttpClient (HttpClient $ httpClient )
7055 {
71- $ new = clone $ this ;
72- $ new ->httpClient = $ httpClient ;
73-
74- return $ new ;
75- }
76-
77- /**
78- * @return RequestFactory
79- */
80- public function getRequestFactory ()
81- {
82- return $ this ->requestFactory ;
56+ return $ this ->setValue ('http_client ' , $ httpClient );
8357 }
8458
8559 /**
@@ -89,36 +63,29 @@ public function getRequestFactory()
8963 */
9064 public function setRequestFactory (RequestFactory $ requestFactory )
9165 {
92- $ new = clone $ this ;
93- $ new ->requestFactory = $ requestFactory ;
94-
95- return $ new ;
66+ return $ this ->setValue ('request_factory ' , $ requestFactory );
9667 }
9768
9869 /**
9970 * @param int $timeout
10071 *
10172 * @return Configuration
102- * @deprecated Will be removed in 5.0
73+ * @deprecated Will be removed in 5.0. The Timeout option will disappear.
10374 */
10475 public function withTimeout ($ timeout )
10576 {
106- $ this ->timeout = $ timeout ;
107-
108- return $ this ;
77+ return $ this ->setValue ('timeout ' , $ timeout );
10978 }
11079
11180 /**
11281 * @param string $interface
11382 *
11483 * @return $this
115- * @deprecated Will be removed in 5.0
84+ * @deprecated Will be removed in 5.0. The CurlInterface option will disappear.
11685 */
11786 public function withCurlInterface ($ interface )
11887 {
119- $ this ->curlInterface = $ interface ;
120-
121- return $ this ;
88+ return $ this ->setValue ('curl_interface ' , $ interface );
12289 }
12390
12491 /**
@@ -127,15 +94,15 @@ public function withCurlInterface($interface)
12794 */
12895 public function getTimeout ()
12996 {
130- return $ this ->timeout ;
97+ return $ this ->getValue ( ' timeout ' ) ;
13198 }
13299
133100 /**
134101 * @return string
135- * @deprecated Will be removed in 5.0
102+ * @deprecated Will be removed in 5.0.
136103 */
137104 public function getCurlInterface ()
138105 {
139- return $ this ->curlInterface ;
106+ return $ this ->getValue ( ' curl_interface ' ) ;
140107 }
141108}
0 commit comments