11<?php
22namespace net \authorize \util ;
33
4+ use net \authorize \util \LogFactory ;
5+ use net \authorize \util \Log ;
6+
47/**
58 * A class to send a request to the XML API.
69 *
@@ -13,14 +16,15 @@ class HttpClient
1316
1417 public $ VERIFY_PEER = true ; // attempt trust validation of SSL certificates when establishing secure connections.
1518 private $ _log_file = false ;
16-
19+ private $ logger = NULL ;
1720 /**
1821 * Constructor.
1922 *
2023 */
2124 public function __construct ()
2225 {
2326 $ this ->_log_file = (defined ('AUTHORIZENET_LOG_FILE ' ) ? AUTHORIZENET_LOG_FILE : false );
27+ $ this ->logger = LogFactory::getLog (get_class ($ this ));
2428 date_default_timezone_set ('UTC ' );
2529 }
2630
@@ -71,38 +75,38 @@ public function _sendRequest($xmlRequest)
7175 curl_setopt ($ curl_request , CURLOPT_RETURNTRANSFER , 1 );
7276 curl_setopt ($ curl_request , CURLOPT_SSL_VERIFYHOST , 2 );
7377
74- file_put_contents ( $ this ->_log_file , sprintf ("\n %s: Url: %s " , $ this -> now (), $ post_url ), FILE_APPEND );
78+ $ this ->logger -> info ( sprintf (" Url: %s " , $ post_url ));
7579 // Do not log requests that could contain CC info.
76- file_put_contents ( $ this ->_log_file , sprintf ("\n %s: Request to AnetApi: \n%s " , $ this -> now (), $ xmlRequest ), FILE_APPEND );
80+ $ this ->logger -> info ( sprintf ("Request to AnetApi: \n%s " , $ xmlRequest ));
7781
7882 if ($ this ->VERIFY_PEER ) {
7983 curl_setopt ($ curl_request , CURLOPT_CAINFO , dirname (dirname (__FILE__ )) . '/../../ssl/cert.pem ' );
8084 } else {
81- if ($ this ->_log_file ) {
82- file_put_contents ($ this ->_log_file , "\nInvalid SSL option for the request " , FILE_APPEND );
83- }
85+ $ this ->logger ("Invalid SSL option for the request " );
8486 return false ;
8587 }
8688
8789 if (preg_match ('/xml/ ' ,$ post_url )) {
8890 curl_setopt ($ curl_request , CURLOPT_HTTPHEADER , Array ("Content-Type: text/xml " ));
89- file_put_contents ($ this ->_log_file , "\nSending 'XML' Request type " , FILE_APPEND );
91+ // file_put_contents($this->_log_file, "\nSending 'XML' Request type", FILE_APPEND);
92+ $ this ->logger ->info ("Sending 'XML' Request type " );
9093 }
9194
9295 try
9396 {
94- file_put_contents ( $ this ->_log_file , sprintf ( "\n %s: Sending http request via Curl ", $ this -> now ()), FILE_APPEND );
97+ $ this ->logger -> info ( " Sending http request via Curl " );
9598 $ xmlResponse = curl_exec ($ curl_request );
96- file_put_contents ($ this ->_log_file , sprintf ("\n%s:Response from AnetApi: \n%s \n" , $ this ->now (), $ xmlResponse ), FILE_APPEND );
99+ $ this ->logger ->info ("Response from AnetApi: $ xmlResponse " );
100+
97101 } catch (\Exception $ ex )
98102 {
99103 $ errorMessage = sprintf ("\n%s:Error making http request via curl: Code:'%s', Message:'%s', Trace:'%s', File:'%s':'%s' " ,
100104 $ this ->now (), $ ex ->getCode (), $ ex ->getMessage (), $ ex ->getTraceAsString (), $ ex ->getFile (), $ ex ->getLine () );
101- file_put_contents ( $ this ->_log_file , $ errorMessage, FILE_APPEND );
105+ $ this ->logger -> error ( $ errorMessage );
102106 }
103107 if ($ this ->_log_file ) {
104108 if ($ curl_error = curl_error ($ curl_request )) {
105- file_put_contents ( $ this ->_log_file , sprintf ( "\n %s: CURL ERROR: %s " , $ this -> now (), $ curl_error), FILE_APPEND );
109+ $ this ->logger -> error ( " CURL ERROR: $ curl_error" );
106110 }
107111
108112 }
@@ -115,4 +119,4 @@ private function now()
115119 {
116120 return date ( DATE_RFC2822 );
117121 }
118- }
122+ }
0 commit comments