1212
1313namespace chillerlan \OAuthTest ;
1414
15- use chillerlan \HTTP \{Psr18 \CurlClient , Psr7 };
15+ use chillerlan \HTTP \{Psr18 \CurlClient , Psr18 \ LoggingClient };
1616use chillerlan \Settings \SettingsContainerInterface ;
1717use Psr \Http \Client \ClientInterface ;
1818use Psr \Http \Message \{RequestInterface , ResponseInterface };
19- use Psr \Log \{LoggerAwareInterface , LoggerAwareTrait , LoggerInterface , NullLogger };
19+ use Psr \Log \{LoggerAwareInterface , LoggerInterface , NullLogger };
20+
21+ use function usleep ;
2022
2123class OAuthTestHttpClient implements ClientInterface, LoggerAwareInterface{
22- use LoggerAwareTrait;
2324
2425 /**
2526 * @var \chillerlan\Settings\SettingsContainerInterface
@@ -40,9 +41,19 @@ class OAuthTestHttpClient implements ClientInterface, LoggerAwareInterface{
4041 */
4142 public function __construct (SettingsContainerInterface $ options , ClientInterface $ http = null , LoggerInterface $ logger = null ){
4243 $ this ->options = $ options ;
43- $ this ->client = $ http ?? new CurlClient ($ this ->options );
44+ $ this ->client = new LoggingClient (
45+ $ http ?? new CurlClient ($ this ->options ),
46+ $ logger ?? new NullLogger
47+ );
48+ }
4449
45- $ this ->setLogger ($ logger ?? new NullLogger );
50+ /**
51+ * @param \Psr\Log\LoggerInterface $logger
52+ *
53+ * @return void
54+ */
55+ public function setLogger (LoggerInterface $ logger ):void {
56+ $ this ->client ->setLogger ($ logger );
4657 }
4758
4859 /**
@@ -51,15 +62,9 @@ public function __construct(SettingsContainerInterface $options, ClientInterface
5162 * @return \Psr\Http\Message\ResponseInterface
5263 */
5364 public function sendRequest (RequestInterface $ request ):ResponseInterface {
54- \usleep ($ this ->options ->sleep * 1000000 );
55-
56- $ response = $ this ->client ->sendRequest ($ request );
57-
58- $ this ->logger ->debug ("\n-----REQUEST------ \n" .Psr7 \message_to_string ($ request ));
59- $ this ->logger ->debug ("\n-----RESPONSE----- \n" .Psr7 \message_to_string ($ response ));
65+ usleep ($ this ->options ->sleep * 1000000 );
6066
61- $ response ->getBody ()->rewind ();
62- return $ response ;
67+ return $ this ->client ->sendRequest ($ request );
6368 }
6469
6570}
0 commit comments