daryast

Untitled

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