Browse Source

feat: withCertInfo

Hugh Harlequin 2 years ago
parent
commit
f9d6c8768d
1 changed files with 17 additions and 9 deletions
  1. 17 9
      src/Builder.php

+ 17 - 9
src/Builder.php

@@ -25,6 +25,7 @@ class Builder {
         'SSL_VERIFYPEER'        => false,
         'NOBODY'                => false,
         'HEADER'                => false,
+        'CERTINFO'              => false,
     );
 
     /** @var array $packageOptions      Array with options that are not specific to cURL but are used by the package */
@@ -65,6 +66,17 @@ class Builder {
         return $this->withCurlOption( 'URL', $url );
     }
 
+    /**
+     * Set the request with certinfo
+     *
+     * @param $certInfo boolean   Indicates whether or not the data should with certinfo. Default: true
+     * @return Builder
+     */
+    public function withCertInfo($certInfo = true) {
+        return $this->withOption( 'CERTINFO', $certInfo )
+            ->withOption( 'VERBOSE', $certInfo );
+    }
+
     /**
      * Set the request return content encoding by
      *
@@ -659,6 +671,10 @@ class Builder {
         $object->content = $content;
         $object->status = $responseData[ 'http_code' ];
         $object->contentType = $responseData[ 'content_type' ];
+        if ( $this->curlOptions[ 'CERTINFO' ] ) {
+            $object->certinfo = $responseData[ 'certinfo' ];
+        }
+
         if( array_key_exists('errorMessage', $responseData) ) {
             $object->error = $responseData[ 'errorMessage' ];
         }
@@ -667,15 +683,7 @@ class Builder {
             $object->headers = $this->parseHeaders( $header );
         }
 
-        if( $this->packageOptions[ 'responseObject' ] ) {
-            return $object;
-        }
-
-        if( $this->packageOptions[ 'responseArray' ] ) {
-            return (array) $object;
-        }
-
-        return $content;
+        return $this->packageOptions[ 'responseObject' ] ? $object : (array) $object;
     }
 
     /**