@@ -6,112 +6,112 @@ |
||
6 | 6 | |
7 | 7 | class DataslangApi { |
8 | 8 | |
9 | - const BASE_URI = 'http://api.dataslang'; |
|
9 | + const BASE_URI = 'http://api.dataslang'; |
|
10 | 10 | |
11 | - private $client = null; |
|
12 | - private $settings = array(); |
|
13 | - private $timeout = 7; |
|
11 | + private $client = null; |
|
12 | + private $settings = array(); |
|
13 | + private $timeout = 7; |
|
14 | 14 | |
15 | - public function validate($xml, $xsd){ |
|
16 | - $result = null; |
|
15 | + public function validate($xml, $xsd){ |
|
16 | + $result = null; |
|
17 | 17 | |
18 | - try { |
|
18 | + try { |
|
19 | 19 | |
20 | - $client = $this->getClient(); |
|
21 | - $response = $client->request('POST', '/xml/validate', [ |
|
22 | - 'form_params' => [ |
|
23 | - 'xml' => urlencode($xml), |
|
24 | - 'xsd' => urlencode($xsd) |
|
25 | - ] |
|
26 | - ]); |
|
20 | + $client = $this->getClient(); |
|
21 | + $response = $client->request('POST', '/xml/validate', [ |
|
22 | + 'form_params' => [ |
|
23 | + 'xml' => urlencode($xml), |
|
24 | + 'xsd' => urlencode($xsd) |
|
25 | + ] |
|
26 | + ]); |
|
27 | 27 | |
28 | - $result = $response->getBody(); |
|
28 | + $result = $response->getBody(); |
|
29 | 29 | |
30 | - } catch (\Exception $e) { |
|
30 | + } catch (\Exception $e) { |
|
31 | 31 | |
32 | - } |
|
32 | + } |
|
33 | 33 | |
34 | - return $result; |
|
35 | - } |
|
34 | + return $result; |
|
35 | + } |
|
36 | 36 | |
37 | - public function transformToXml($xml){ |
|
38 | - $result = null; |
|
37 | + public function transformToXml($xml){ |
|
38 | + $result = null; |
|
39 | 39 | |
40 | - try { |
|
40 | + try { |
|
41 | 41 | |
42 | - $client = $this->getClient(); |
|
43 | - $response = $client->request('POST', '/xml/transform/xml', [ |
|
44 | - 'form_params' => [ |
|
45 | - 'xml' => urlencode($xml) |
|
46 | - ] |
|
47 | - ]); |
|
42 | + $client = $this->getClient(); |
|
43 | + $response = $client->request('POST', '/xml/transform/xml', [ |
|
44 | + 'form_params' => [ |
|
45 | + 'xml' => urlencode($xml) |
|
46 | + ] |
|
47 | + ]); |
|
48 | 48 | |
49 | - $result = $response->getBody(); |
|
49 | + $result = $response->getBody(); |
|
50 | 50 | |
51 | - } catch (\Exception $e) { |
|
51 | + } catch (\Exception $e) { |
|
52 | 52 | |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - return $result; |
|
56 | - } |
|
55 | + return $result; |
|
56 | + } |
|
57 | 57 | |
58 | - public function transformToHtml($xml, $xsl, $dest_path){ |
|
59 | - $result = null; |
|
58 | + public function transformToHtml($xml, $xsl, $dest_path){ |
|
59 | + $result = null; |
|
60 | 60 | |
61 | - try { |
|
61 | + try { |
|
62 | 62 | |
63 | - $client = $this->getClient(); |
|
64 | - $response = $client->request('POST', '/xml/transform/html', [ |
|
65 | - 'form_params' => [ |
|
66 | - 'xml' => urlencode($xml), |
|
67 | - 'xsl' => urlencode($xsl), |
|
68 | - 'dest_path' => urlencode($dest_path) |
|
69 | - ] |
|
70 | - ]); |
|
63 | + $client = $this->getClient(); |
|
64 | + $response = $client->request('POST', '/xml/transform/html', [ |
|
65 | + 'form_params' => [ |
|
66 | + 'xml' => urlencode($xml), |
|
67 | + 'xsl' => urlencode($xsl), |
|
68 | + 'dest_path' => urlencode($dest_path) |
|
69 | + ] |
|
70 | + ]); |
|
71 | 71 | |
72 | - $result = $response->getBody(); |
|
72 | + $result = $response->getBody(); |
|
73 | 73 | |
74 | - } catch (\Exception $e) { |
|
74 | + } catch (\Exception $e) { |
|
75 | 75 | |
76 | - } |
|
76 | + } |
|
77 | 77 | |
78 | - return $result; |
|
79 | - } |
|
78 | + return $result; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * |
|
83 | - * @param int $timeout |
|
84 | - */ |
|
85 | - public function setTimeout($timeout){ |
|
86 | - $this->timeout = $timeout; |
|
87 | - } |
|
81 | + /** |
|
82 | + * |
|
83 | + * @param int $timeout |
|
84 | + */ |
|
85 | + public function setTimeout($timeout){ |
|
86 | + $this->timeout = $timeout; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * |
|
91 | - * @return int $timeout |
|
92 | - */ |
|
93 | - public function getTimeout(){ |
|
94 | - return $this->timeout; |
|
95 | - } |
|
89 | + /** |
|
90 | + * |
|
91 | + * @return int $timeout |
|
92 | + */ |
|
93 | + public function getTimeout(){ |
|
94 | + return $this->timeout; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * |
|
99 | - * @return string BASE_URI |
|
100 | - */ |
|
101 | - public function getBaseUri(){ |
|
102 | - return self::BASE_URI; |
|
103 | - } |
|
97 | + /** |
|
98 | + * |
|
99 | + * @return string BASE_URI |
|
100 | + */ |
|
101 | + public function getBaseUri(){ |
|
102 | + return self::BASE_URI; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * |
|
107 | - * @return \GuzzleHttp\Client |
|
108 | - */ |
|
109 | - private function getClient(){ |
|
110 | - $settings = array(); |
|
111 | - $settings['base_uri'] = $this->getBaseUri(); |
|
112 | - $settings['timeout'] = $this->getTimeout(); |
|
105 | + /** |
|
106 | + * |
|
107 | + * @return \GuzzleHttp\Client |
|
108 | + */ |
|
109 | + private function getClient(){ |
|
110 | + $settings = array(); |
|
111 | + $settings['base_uri'] = $this->getBaseUri(); |
|
112 | + $settings['timeout'] = $this->getTimeout(); |
|
113 | 113 | |
114 | - return new Client($settings); |
|
115 | - } |
|
114 | + return new Client($settings); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } |