Advertisement
daryast

Untitled

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