1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dataslang; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
|
7
|
|
|
class DataslangApi { |
8
|
|
|
|
9
|
|
|
const BASE_URI = 'http://api.dataslang.com'; |
10
|
|
|
|
11
|
|
|
private $client = null; |
12
|
|
|
private $settings = array(); |
|
|
|
|
13
|
|
|
private $timeout = 7; |
14
|
|
|
|
15
|
|
View Code Duplication |
public function validate($xml, $xsd){ |
|
|
|
|
16
|
|
|
$result = null; |
17
|
|
|
|
18
|
|
|
try { |
19
|
|
|
|
20
|
|
|
$client = $this->getClient(); |
21
|
|
|
$response = $client->request('POST', '/xml/validate', [ |
22
|
|
|
'form_params' => [ |
23
|
|
|
'xml' => urlencode($xml), |
24
|
|
|
'xsd' => urlencode($xsd), |
25
|
|
|
'response-type' => urlencode('txt') |
26
|
|
|
] |
27
|
|
|
]); |
28
|
|
|
|
29
|
|
|
$result = $response->getBody(); |
30
|
|
|
|
31
|
|
|
} catch (\Exception $e) { |
32
|
|
|
$result = $e->getMessage(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $result; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function transformToXml($xml, $xsl, $dest_path){ |
|
|
|
|
39
|
|
|
$result = null; |
40
|
|
|
|
41
|
|
|
try { |
42
|
|
|
|
43
|
|
|
$client = $this->getClient(); |
44
|
|
|
$response = $client->request('POST', '/xml/transform/xml', [ |
45
|
|
|
'form_params' => [ |
46
|
|
|
'xml' => urlencode($xml), |
47
|
|
|
'xsl' => urlencode($xsl), |
48
|
|
|
'dest_path' => urlencode($dest_path), |
49
|
|
|
'response-type' => urlencode('txt') |
50
|
|
|
] |
51
|
|
|
]); |
52
|
|
|
|
53
|
|
|
$result = $response->getBody(); |
54
|
|
|
|
55
|
|
|
} catch (\Exception $e) { |
56
|
|
|
$result = $e->getMessage(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $result; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
public function transformToHtml($xml, $xsl, $dest_path){ |
|
|
|
|
63
|
|
|
$result = null; |
64
|
|
|
|
65
|
|
|
try { |
66
|
|
|
|
67
|
|
|
$client = $this->getClient(); |
68
|
|
|
$response = $client->request('POST', '/xml/transform/html', [ |
69
|
|
|
'form_params' => [ |
70
|
|
|
'xml' => urlencode($xml), |
71
|
|
|
'xsl' => urlencode($xsl), |
72
|
|
|
'dest_path' => urlencode($dest_path), |
73
|
|
|
'response-type' => urlencode('txt') |
74
|
|
|
] |
75
|
|
|
]); |
76
|
|
|
|
77
|
|
|
$result = $response->getBody(); |
78
|
|
|
|
79
|
|
|
} catch (\Exception $e) { |
80
|
|
|
$result = $e->getMessage(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $result; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function setTimeout($timeout){ |
87
|
|
|
$this->timeout = $timeout; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getTimeout(){ |
91
|
|
|
return $this->timeout; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getBaseUri(){ |
95
|
|
|
return self::BASE_URI; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
private function getClient(){ |
99
|
|
|
if ($this->client === null){ |
100
|
|
|
$settings = array(); |
101
|
|
|
$settings['base_uri'] = $this->getBaseUri(); |
102
|
|
|
$settings['timeout'] = $this->getTimeout(); |
103
|
|
|
|
104
|
|
|
$this->client = new Client($settings); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $this->client; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.