Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Class ExternalService
- */
- class ExternalService /*extends CActiveRecordextends CActiveRecord*/
- {
- public $request;
- public $method;
- public $url;
- public $response;
- /*
- * @param $url - url внешнего сервиса
- */
- public function __construct($url)
- {
- $this->url = $url;
- }
- /**
- * Получение ответа от внешнего сервиса
- * @param $method - тип запроса
- * @param null $request - тело запроса
- * Вернет тело ответа внешнего сервиса
- * @return mixed
- *
- */
- public function getResponse($method, $request = null)
- {
- switch ($method) {
- case 'GET':
- $response = Yii::app()->httpClient->get($this->url,
- array('content-type' => 'application/json'))->getBody();
- break;
- case 'POST':
- $response = Yii::app()->httpClient->post($this->url,
- array('content-type' => 'application/json'), $request)->getBody();
- break;
- }
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment