|
@@ -8,6 +8,9 @@ class Builder {
|
|
|
/** @var resource $curlObject cURL request */
|
|
|
protected $curlObject = null;
|
|
|
|
|
|
+ /** @var boolean $multiple set class is in multiple Default: false*/
|
|
|
+ protected $multiple = false;
|
|
|
+
|
|
|
/** @var array $curlOptions Array of cURL options */
|
|
|
protected $curlOptions = array(
|
|
|
'RETURNTRANSFER' => true,
|
|
@@ -40,6 +43,16 @@ class Builder {
|
|
|
'saveFile' => '',
|
|
|
);
|
|
|
|
|
|
+ /**
|
|
|
+ * Set the Builder is in multiple
|
|
|
+ *
|
|
|
+ * @param $multiple boolean Prevent Builder fetch when it is in multiple. Default: true
|
|
|
+ * @return Builder
|
|
|
+ */
|
|
|
+ public function multiple($multiple = true) {
|
|
|
+ $this->multiple = $multiple;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Set the URL to which the request is to be sent
|
|
@@ -551,45 +564,46 @@ class Builder {
|
|
|
$options = $this->forgeOptions();
|
|
|
|
|
|
curl_setopt_array( $this->curlObject, $options );
|
|
|
+ if (!$this->multiple) {
|
|
|
+ // Send the request
|
|
|
+ $response = curl_exec( $this->curlObject );
|
|
|
+
|
|
|
+ $responseHeader = null;
|
|
|
+ if( $this->curlOptions[ 'HEADER' ] ) {
|
|
|
+ $headerSize = curl_getinfo( $this->curlObject, CURLINFO_HEADER_SIZE );
|
|
|
+ $responseHeader = substr( $response, 0, $headerSize );
|
|
|
+ $response = substr( $response, $headerSize );
|
|
|
+ }
|
|
|
|
|
|
- // Send the request
|
|
|
- $response = curl_exec( $this->curlObject );
|
|
|
-
|
|
|
- $responseHeader = null;
|
|
|
- if( $this->curlOptions[ 'HEADER' ] ) {
|
|
|
- $headerSize = curl_getinfo( $this->curlObject, CURLINFO_HEADER_SIZE );
|
|
|
- $responseHeader = substr( $response, 0, $headerSize );
|
|
|
- $response = substr( $response, $headerSize );
|
|
|
- }
|
|
|
-
|
|
|
- // Capture additional request information if needed
|
|
|
- $responseData = array();
|
|
|
- if( $this->packageOptions[ 'responseObject' ] || $this->packageOptions[ 'responseArray' ] ) {
|
|
|
- $responseData = curl_getinfo( $this->curlObject );
|
|
|
+ // Capture additional request information if needed
|
|
|
+ $responseData = array();
|
|
|
+ if( $this->packageOptions[ 'responseObject' ] || $this->packageOptions[ 'responseArray' ] ) {
|
|
|
+ $responseData = curl_getinfo( $this->curlObject );
|
|
|
|
|
|
- if( curl_errno($this->curlObject) ) {
|
|
|
- $responseData[ 'errorMessage' ] = curl_error($this->curlObject);
|
|
|
+ if( curl_errno($this->curlObject) ) {
|
|
|
+ $responseData[ 'errorMessage' ] = curl_error($this->curlObject);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- curl_close( $this->curlObject );
|
|
|
+ curl_close( $this->curlObject );
|
|
|
|
|
|
- if( $this->packageOptions[ 'saveFile' ] ) {
|
|
|
- // Save to file if a filename was specified
|
|
|
- $file = fopen($this->packageOptions[ 'saveFile' ], 'w');
|
|
|
- fwrite($file, $response);
|
|
|
- fclose($file);
|
|
|
- } else if( $this->packageOptions[ 'asJsonResponse' ] ) {
|
|
|
- // Decode the request if necessary
|
|
|
- $response = json_decode($response, $this->packageOptions[ 'returnAsArray' ]);
|
|
|
- }
|
|
|
+ if( $this->packageOptions[ 'saveFile' ] ) {
|
|
|
+ // Save to file if a filename was specified
|
|
|
+ $file = fopen($this->packageOptions[ 'saveFile' ], 'w');
|
|
|
+ fwrite($file, $response);
|
|
|
+ fclose($file);
|
|
|
+ } else if( $this->packageOptions[ 'asJsonResponse' ] ) {
|
|
|
+ // Decode the request if necessary
|
|
|
+ $response = json_decode($response, $this->packageOptions[ 'returnAsArray' ]);
|
|
|
+ }
|
|
|
|
|
|
- if( $this->packageOptions[ 'enableDebug' ] ) {
|
|
|
- fclose( $debugFile );
|
|
|
+ if( $this->packageOptions[ 'enableDebug' ] ) {
|
|
|
+ fclose( $debugFile );
|
|
|
+ }
|
|
|
+ // Return the result
|
|
|
+ return $this->returnResponse( $response, $responseData, $responseHeader );
|
|
|
}
|
|
|
-
|
|
|
- // Return the result
|
|
|
- return $this->returnResponse( $response, $responseData, $responseHeader );
|
|
|
+ return [$this->curlObject, $this->curlOptions, $this->packageOptions];
|
|
|
}
|
|
|
|
|
|
/**
|