daryast

Untitled

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