daryast

Untitled

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