Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @namespace
- */
- namespace Application\Service\Api\Protocol;
- /**
- * Api Handler BasicProtocol
- *
- * @author miholeus
- */
- class Curl extends AbstractProtocol
- {
- protected $errors;
- public function execute($action, $params)
- {
- $config = array(
- 'adapter' => 'Zend_Http_Client_Adapter_Curl',
- 'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
- );
- $options = $this->getHandler()->getOptions();
- $client = new \Zend_Http_Client($options['uri'], $config);
- $client->setParameterGet(array_merge(array(
- 'request' => $action,
- 'format' => 'json'
- ), $params));
- $client->request();
- $response = $client->getLastResponse();
- $this->service = new Curl\Service($this);
- $body = \Zend_Json_Decoder::decode($response->getBody());
- if(is_array($body)) {
- if(isset($body['response']['error'])) {
- $this->service->addErrors($body['response']['error']);
- }
- if(isset($body['response']['data'])) {
- return $body['response']['data'];
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment