1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dataslang; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
|
7
|
|
|
class DataslangApi { |
8
|
|
|
|
9
|
|
|
const BASE_URI = 'http://api.dataslang'; |
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
|
|
|
] |
26
|
|
|
]); |
27
|
|
|
|
28
|
|
|
$result = $response->getBody(); |
29
|
|
|
|
30
|
|
|
} catch (\Exception $e) { |
|
|
|
|
31
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
return $result; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function transformToXml($xml){ |
|
|
|
|
38
|
|
|
$result = null; |
39
|
|
|
|
40
|
|
|
try { |
41
|
|
|
|
42
|
|
|
$client = $this->getClient(); |
43
|
|
|
$response = $client->request('POST', '/xml/transform/xml', [ |
44
|
|
|
'form_params' => [ |
45
|
|
|
'xml' => urlencode($xml) |
46
|
|
|
] |
47
|
|
|
]); |
48
|
|
|
|
49
|
|
|
$result = $response->getBody(); |
50
|
|
|
|
51
|
|
|
} catch (\Exception $e) { |
|
|
|
|
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $result; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function transformToHtml($xml, $xsl, $dest_path){ |
|
|
|
|
59
|
|
|
$result = null; |
60
|
|
|
|
61
|
|
|
try { |
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
|
|
|
]); |
71
|
|
|
|
72
|
|
|
$result = $response->getBody(); |
73
|
|
|
|
74
|
|
|
} catch (\Exception $e) { |
|
|
|
|
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $result; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function setTimeout($timeout){ |
82
|
|
|
$this->timeout = $timeout; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getTimeout(){ |
86
|
|
|
return $this->timeout; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function getBaseUri(){ |
90
|
|
|
return self::BASE_URI; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
private function getClient(){ |
94
|
|
|
$settings = array(); |
95
|
|
|
$settings['base_uri'] = $this->getBaseUri(); |
96
|
|
|
$settings['timeout'] = $this->getTimeout(); |
97
|
|
|
|
98
|
|
|
return new Client($settings); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.