1 | <?php |
||
14 | class XmlHandler implements Handler, Collection |
||
15 | { |
||
16 | use XmlConverter; |
||
17 | |||
18 | private $response; |
||
19 | |||
20 | private $validText = []; |
||
21 | |||
22 | private $buildXml; |
||
23 | |||
24 | /* |
||
25 | |-------------------------------------------------------------------------- |
||
26 | | Namespaces XML API BPM |
||
27 | |-------------------------------------------------------------------------- |
||
28 | | Namespaces in BPM API to parse the XML response |
||
29 | | |
||
30 | */ |
||
31 | private $namespaces = [ |
||
32 | 'NamespaceAtom' => 'http://www.w3.org/2005/Atom', |
||
33 | 'NamespaceMetadata' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata', |
||
34 | 'NamespaceDataServices' => 'http://schemas.microsoft.com/ado/2007/08/dataservices', |
||
35 | ]; |
||
36 | |||
37 | /* |
||
38 | |-------------------------------------------------------------------------- |
||
39 | | List Namespaces for post request in BPM |
||
40 | |-------------------------------------------------------------------------- |
||
41 | | Namespaces To specify a file in XML |
||
42 | | |
||
43 | */ |
||
44 | private $listNamespaces = [ |
||
45 | ['xml:base' => 'http://softex-iis:7503/0/ServiceModel/EntityDataService.svc/'], |
||
46 | ['xmlns' => 'http://www.w3.org/2005/Atom'], |
||
47 | ['xmlns:d' => 'http://schemas.microsoft.com/ado/2007/08/dataservices'], |
||
48 | ['xmlns:m' => 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'], |
||
49 | ['xmlns:georss' => 'http://www.georss.org/georss'], |
||
50 | ['xmlns:gml' => 'http://www.opengis.net/gml'], |
||
51 | ]; |
||
52 | |||
53 | /* |
||
54 | |-------------------------------------------------------------------------- |
||
55 | | Prefix XML document |
||
56 | |-------------------------------------------------------------------------- |
||
57 | | The prefix for insertion into Namespace XML document to be sent to API BPM |
||
58 | | |
||
59 | */ |
||
60 | private $prefixNamespace = 'd'; |
||
61 | |||
62 | /** |
||
63 | * @return string |
||
64 | */ |
||
65 | 2 | public function getAccept() |
|
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 2 | public function getContentType() |
|
77 | |||
78 | /** |
||
79 | * @param $response |
||
80 | * @return XmlHandler|array|mixed |
||
81 | */ |
||
82 | 6 | public function parse($response) |
|
83 | { |
||
84 | 6 | $this->response = simplexml_load_string($response); |
|
85 | 6 | $copyXml = $this->response; |
|
86 | |||
87 | 6 | if ( $this->response === false || $this->checkIntegrity($this->response) === false ) |
|
88 | 6 | { |
|
89 | 1 | return []; |
|
90 | } |
||
91 | |||
92 | 5 | $array_vars_list = get_object_vars($copyXml); |
|
93 | |||
94 | 5 | if (key_exists('content', $array_vars_list)) { |
|
95 | 1 | return $this->arrayOne(); |
|
96 | } |
||
97 | 4 | if (key_exists('workspace', $array_vars_list)) { |
|
98 | 1 | return $this->workspace(); |
|
99 | } else { |
||
100 | 3 | return $this->arrayMany(); |
|
101 | } |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @param $response |
||
106 | * @return bool |
||
107 | */ |
||
108 | 8 | public function checkIntegrity($response) |
|
116 | |||
117 | /** |
||
118 | * @return array |
||
119 | */ |
||
120 | 1 | public function getData() |
|
124 | |||
125 | /** |
||
126 | * @return array|null |
||
127 | */ |
||
128 | 2 | public function toArray() |
|
132 | |||
133 | /** |
||
134 | * @return \Illuminate\Support\Collection |
||
135 | */ |
||
136 | 1 | public function toArrayCollect() |
|
137 | { |
||
138 | 1 | return collect($this->xmlToArrayRecursive($this->validText)); |
|
139 | } |
||
140 | |||
141 | /** |
||
142 | * @return string |
||
143 | */ |
||
144 | 1 | public function toJson() |
|
148 | |||
149 | /** |
||
150 | * Return All Collection Bpm |
||
151 | * if not specified all parameters in url |
||
152 | * return list all collection from bpm |
||
153 | * @throws \Exception |
||
154 | */ |
||
155 | 1 | private function workspace() |
|
162 | |||
163 | /** |
||
164 | * Extraction array in response XML , more element one |
||
165 | * @return XmlHandler |
||
166 | * @throws \Exception |
||
167 | */ |
||
168 | 3 | private function arrayMany() |
|
180 | /** |
||
181 | * Get one Element |
||
182 | * @return mixed |
||
183 | */ |
||
184 | 1 | private function arrayOne() |
|
191 | |||
192 | |||
193 | /** |
||
194 | * Xml text for request in Bpm Online |
||
195 | * @param $data array |
||
196 | * @return string |
||
197 | */ |
||
198 | 1 | public function create(array $data) |
|
236 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: