@@ -6,66 +6,66 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Client extends ClientAbstract |
| 8 | 8 | { |
| 9 | - public $apiKey; |
|
| 10 | - public $url = 'www.turbotext.ru'; |
|
| 11 | - public $protocol = 'https'; |
|
| 12 | - public $method = 'POST'; |
|
| 13 | - public $type = self::TYPE_FORM; |
|
| 14 | - public $output_type = self::TYPE_JSON; |
|
| 9 | + public $apiKey; |
|
| 10 | + public $url = 'www.turbotext.ru'; |
|
| 11 | + public $protocol = 'https'; |
|
| 12 | + public $method = 'POST'; |
|
| 13 | + public $type = self::TYPE_FORM; |
|
| 14 | + public $output_type = self::TYPE_JSON; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param array $data |
|
| 18 | - * @return array|string |
|
| 19 | - */ |
|
| 20 | - public function prepareData(array $data) |
|
| 21 | - { |
|
| 22 | - $data = parent::prepareData($data); |
|
| 23 | - $data['api_key'] = $this->apiKey; |
|
| 24 | - return $data; |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * @param array $data |
|
| 18 | + * @return array|string |
|
| 19 | + */ |
|
| 20 | + public function prepareData(array $data) |
|
| 21 | + { |
|
| 22 | + $data = parent::prepareData($data); |
|
| 23 | + $data['api_key'] = $this->apiKey; |
|
| 24 | + return $data; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param $urlRequest |
|
| 29 | - * @param array $data |
|
| 30 | - * @param string $responseClass |
|
| 31 | - * @return mixed |
|
| 32 | - */ |
|
| 33 | - public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response') |
|
| 34 | - { |
|
| 35 | - try { |
|
| 36 | - $content = parent::getContent($urlRequest, $data); |
|
| 37 | - return self::stdClassToResponse($content, $responseClass); |
|
| 38 | - } catch (\Exception $e) { |
|
| 39 | - $response = new Response(); |
|
| 40 | - $response->success = false; |
|
| 41 | - $response->errors = $e->getMessage(); |
|
| 42 | - return $response; |
|
| 43 | - } |
|
| 44 | - } |
|
| 27 | + /** |
|
| 28 | + * @param $urlRequest |
|
| 29 | + * @param array $data |
|
| 30 | + * @param string $responseClass |
|
| 31 | + * @return mixed |
|
| 32 | + */ |
|
| 33 | + public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response') |
|
| 34 | + { |
|
| 35 | + try { |
|
| 36 | + $content = parent::getContent($urlRequest, $data); |
|
| 37 | + return self::stdClassToResponse($content, $responseClass); |
|
| 38 | + } catch (\Exception $e) { |
|
| 39 | + $response = new Response(); |
|
| 40 | + $response->success = false; |
|
| 41 | + $response->errors = $e->getMessage(); |
|
| 42 | + return $response; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param $stdClass |
|
| 48 | - * @param $responseClass |
|
| 49 | - * @return ResponseAbstract |
|
| 50 | - */ |
|
| 51 | - protected static function stdClassToResponse($stdClass, $responseClass) |
|
| 52 | - { |
|
| 53 | - /** |
|
| 54 | - * @var ResponseAbstract $response |
|
| 55 | - */ |
|
| 56 | - $response = new $responseClass(); |
|
| 57 | - foreach ($stdClass as $key => $value) { |
|
| 58 | - if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) { |
|
| 59 | - foreach ($value as $item) { |
|
| 60 | - $response->{$key}[] = self::stdClassToResponse($item, $class); |
|
| 61 | - } |
|
| 62 | - } else { |
|
| 63 | - $response->$key = $value; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - if (isset($response->success)) { |
|
| 67 | - $response->success = filter_var($response->success, FILTER_VALIDATE_BOOLEAN); |
|
| 68 | - } |
|
| 69 | - return $response; |
|
| 70 | - } |
|
| 46 | + /** |
|
| 47 | + * @param $stdClass |
|
| 48 | + * @param $responseClass |
|
| 49 | + * @return ResponseAbstract |
|
| 50 | + */ |
|
| 51 | + protected static function stdClassToResponse($stdClass, $responseClass) |
|
| 52 | + { |
|
| 53 | + /** |
|
| 54 | + * @var ResponseAbstract $response |
|
| 55 | + */ |
|
| 56 | + $response = new $responseClass(); |
|
| 57 | + foreach ($stdClass as $key => $value) { |
|
| 58 | + if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) { |
|
| 59 | + foreach ($value as $item) { |
|
| 60 | + $response->{$key}[] = self::stdClassToResponse($item, $class); |
|
| 61 | + } |
|
| 62 | + } else { |
|
| 63 | + $response->$key = $value; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + if (isset($response->success)) { |
|
| 67 | + $response->success = filter_var($response->success, FILTER_VALIDATE_BOOLEAN); |
|
| 68 | + } |
|
| 69 | + return $response; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | \ No newline at end of file |