-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New HttpGetXML handles XML requests.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
namespace Lsw\ApiCallerBundle\Call; | ||
|
||
use Lsw\ApiCallerBundle\Helper\Curl; | ||
|
||
/** | ||
* cURL based API call with request data send as GET parameters | ||
* | ||
* @author J. Cary Howell <[email protected]> | ||
*/ | ||
class HttpGetXML extends CurlCall implements ApiCallInterface | ||
{ | ||
/** | ||
* ApiCall class constructor | ||
* | ||
* @param string $url API url | ||
* @param object $cookie Cookie | ||
* @param object $requestObject Request | ||
* @param boolean $asAssociativeArray | ||
*/ | ||
public function __construct($url,$cookie,$asAssociativeArray=false,$requestObject=null) | ||
{ | ||
$this->url = $url; | ||
$this->cookie = $cookie; | ||
$this->requestObject = $requestObject; | ||
$this->asAssociativeArray = $asAssociativeArray; | ||
$this->generateRequestData(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function generateRequestData() | ||
{ | ||
if ($this->requestObject) { | ||
$this->requestData = '?'.http_build_query($this->requestObject); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function parseResponseData() | ||
{ | ||
if($this->asAssociativeArray) { | ||
$xml = simplexml_load_string($this->responseData); | ||
$json = json_encode($xml); | ||
$this->responseObject = json_decode( $json, TRUE ); | ||
} else { | ||
$this->responseObject = $this->responseData; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function makeRequest($curl, $options) | ||
{ | ||
$url = $this->url; | ||
if ($this->requestData) { | ||
$url.= $this->requestData; | ||
} | ||
$curl->setopt(CURLOPT_URL, $url); | ||
$curl->setopt(CURLOPT_COOKIE, $this->cookie); | ||
$curl->setopt(CURLOPT_HTTPGET, TRUE); | ||
$curl->setoptArray($options); | ||
$this->curlExec($curl); | ||
} | ||
|
||
} |