daryast

Untitled

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