daryast

Untitled

Apr 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Class ExternalService
  5. */
  6. class ExternalService /*extends CActiveRecordextends CActiveRecord*/
  7. {
  8. public $request;
  9. public $method;
  10. public $url;
  11. public $response;
  12.  
  13.  
  14. /*
  15. * @param $url - url внешнего сервиса
  16. */
  17. public function __construct($url)
  18. {
  19. $this->url = $url;
  20. }
  21.  
  22.  
  23. /**
  24. * Получение ответа от внешнего сервиса
  25. * @param $method - тип запроса
  26. * @param null $request - тело запроса
  27. * Вернет тело ответа внешнего сервиса
  28. * @return mixed
  29. *
  30. */
  31.  
  32. public function getResponse($method, $request = null)
  33. {
  34. switch ($method) {
  35. case 'GET':
  36. $response = Yii::app()->httpClient->get($this->url,
  37. array('content-type' => 'application/json'))->getBody();
  38. break;
  39. case 'POST':
  40. $response = Yii::app()->httpClient->post($this->url,
  41. array('content-type' => 'application/json'), $request)->getBody();
  42. break;
  43. }
  44. return $response;
  45. }
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment