Passed
Push — master ( 6f1b8a...49cefa )
by Dmitry
01:56
created
src/Provider31/Request/General.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -17,108 +17,108 @@  discard block
 block discarded – undo
17 17
 
18 18
 class General
19 19
 {
20
-    /**
21
-     *      @var string raw request
22
-     */
23
-    protected $raw_request;
24
-
25
-    /**
26
-     *      @var string 'DateTime' node
27
-     */
28
-    protected $DateTime;
29
-
30
-    /**
31
-     *      @var string 'Sign' node
32
-     */
33
-    protected $Sign;
34
-
35
-    /**
36
-     *      @var string 'Operation' type
37
-     */
38
-    protected $Operation;
39
-
40
-    /**
41
-     *      @var string 'ServiceId' node
42
-     */
43
-    protected $ServiceId;
44
-
45
-    /**
46
-     *      @var array list of possible operations
47
-     */
48
-    protected $operations = array('Check','Payment','Confirm','Cancel');
49
-
50
-    /**
51
-     *      General constructor
52
-     *
53
-     *      @param string $raw Raw request data
54
-     */
55
-    public function __construct($raw)
56
-    {
20
+        /**
21
+         *      @var string raw request
22
+         */
23
+        protected $raw_request;
24
+
25
+        /**
26
+         *      @var string 'DateTime' node
27
+         */
28
+        protected $DateTime;
29
+
30
+        /**
31
+         *      @var string 'Sign' node
32
+         */
33
+        protected $Sign;
34
+
35
+        /**
36
+         *      @var string 'Operation' type
37
+         */
38
+        protected $Operation;
39
+
40
+        /**
41
+         *      @var string 'ServiceId' node
42
+         */
43
+        protected $ServiceId;
44
+
45
+        /**
46
+         *      @var array list of possible operations
47
+         */
48
+        protected $operations = array('Check','Payment','Confirm','Cancel');
49
+
50
+        /**
51
+         *      General constructor
52
+         *
53
+         *      @param string $raw Raw request data
54
+         */
55
+        public function __construct($raw)
56
+        {
57 57
         $this->raw_request = strval($raw);
58 58
 
59 59
         $this->parse_request_data();
60
-    }
61
-
62
-    /**
63
-     *      Get DateTime
64
-     *
65
-     *      @return string
66
-     */
67
-    public function DateTime()
68
-    {
60
+        }
61
+
62
+        /**
63
+         *      Get DateTime
64
+         *
65
+         *      @return string
66
+         */
67
+        public function DateTime()
68
+        {
69 69
         return $this->DateTime;
70
-    }
71
-
72
-    /**
73
-     *      Get Sign
74
-     *
75
-     *      @return string
76
-     */
77
-    public function Sign()
78
-    {
70
+        }
71
+
72
+        /**
73
+         *      Get Sign
74
+         *
75
+         *      @return string
76
+         */
77
+        public function Sign()
78
+        {
79 79
         return $this->Sign;
80
-    }
81
-
82
-    /**
83
-     *      Get Operation type
84
-     *
85
-     *      @return string
86
-     */
87
-    public function Operation()
88
-    {
80
+        }
81
+
82
+        /**
83
+         *      Get Operation type
84
+         *
85
+         *      @return string
86
+         */
87
+        public function Operation()
88
+        {
89 89
         return $this->Operation;
90
-    }
91
-
92
-    /**
93
-     *      Get ServiceId
94
-     *
95
-     *      @return string
96
-     */
97
-    public function ServiceId()
98
-    {
90
+        }
91
+
92
+        /**
93
+         *      Get ServiceId
94
+         *
95
+         *      @return string
96
+         */
97
+        public function ServiceId()
98
+        {
99 99
         return $this->ServiceId;
100
-    }
101
-
102
-    /**
103
-     *      Parse xml-request, which was previously "extracted" from the body of the http request
104
-     *
105
-     *      @throws Exception\Structure
106
-     */
107
-    protected function parse_request_data()
108
-    {
100
+        }
101
+
102
+        /**
103
+         *      Parse xml-request, which was previously "extracted" from the body of the http request
104
+         *
105
+         *      @throws Exception\Structure
106
+         */
107
+        protected function parse_request_data()
108
+        {
109 109
         if (empty($this->raw_request))
110 110
         {
111
-            throw new Exception\Structure('An empty xml request', -50);
111
+                throw new Exception\Structure('An empty xml request', -50);
112 112
         }
113 113
 
114 114
         libxml_use_internal_errors(true);
115 115
         $doc = new \DOMDocument();
116 116
         if ( ! $doc->loadXML($this->raw_request))
117 117
         {
118
-            foreach(libxml_get_errors() as $e){
118
+                foreach(libxml_get_errors() as $e){
119 119
                 Log::instance()->error($e->message);
120
-            }
121
-            throw new Exception\Structure('The wrong XML is received', -51);
120
+                }
121
+                throw new Exception\Structure('The wrong XML is received', -51);
122 122
         }
123 123
 
124 124
         // process <Request> group
@@ -126,35 +126,35 @@  discard block
 block discarded – undo
126 126
 
127 127
         if (count($r) < 1)
128 128
         {
129
-            throw new Exception\Structure('The xml-query does not contain any element Request!', -52);
129
+                throw new Exception\Structure('The xml-query does not contain any element Request!', -52);
130 130
         }
131 131
 
132 132
         foreach ($r[0]->childNodes as $child)
133 133
         {
134
-            if ($child->nodeName == 'DateTime')
135
-            {
134
+                if ($child->nodeName == 'DateTime')
135
+                {
136 136
                 $this->parse_request_node($child, 'DateTime');
137
-            }
138
-            elseif ($child->nodeName == 'Sign')
139
-            {
137
+                }
138
+                elseif ($child->nodeName == 'Sign')
139
+                {
140 140
                 $this->parse_request_node($child, 'Sign');
141
-            }
142
-            elseif (in_array($child->nodeName, $this->operations))
143
-            {
141
+                }
142
+                elseif (in_array($child->nodeName, $this->operations))
143
+                {
144 144
                 if ( ! isset($this->Operation))
145 145
                 {
146
-                    $this->Operation = $child->nodeName;
146
+                        $this->Operation = $child->nodeName;
147 147
                 }
148 148
                 else
149 149
                 {
150
-                    throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53);
150
+                        throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53);
151
+                }
151 152
                 }
152
-            }
153 153
         }
154 154
 
155 155
         if ( ! isset($this->Operation))
156 156
         {
157
-            throw new Exception\Structure('There is no Operation type element in the xml request!', -55);
157
+                throw new Exception\Structure('There is no Operation type element in the xml request!', -55);
158 158
         }
159 159
 
160 160
         // process <Operation> group
@@ -162,42 +162,42 @@  discard block
 block discarded – undo
162 162
 
163 163
         foreach ($r[0]->childNodes as $child)
164 164
         {
165
-            if ($child->nodeName == 'ServiceId')
166
-            {
165
+                if ($child->nodeName == 'ServiceId')
166
+                {
167 167
                 $this->parse_request_node($child, 'ServiceId');
168
-            }
168
+                }
169
+        }
169 170
         }
170
-    }
171
-
172
-    /**
173
-     *      Parse node of request
174
-     *
175
-     *      @param \DOMNode $n
176
-     *      @param string $name
177
-     *
178
-     *      @throws Exception\Structure
179
-     */
180
-    protected function parse_request_node($n, $name)
181
-    {
171
+
172
+        /**
173
+         *      Parse node of request
174
+         *
175
+         *      @param \DOMNode $n
176
+         *      @param string $name
177
+         *
178
+         *      @throws Exception\Structure
179
+         */
180
+        protected function parse_request_node($n, $name)
181
+        {
182 182
         if ( ! isset($this->$name))
183 183
         {
184
-            $this->$name = $n->nodeValue;
184
+                $this->$name = $n->nodeValue;
185 185
         }
186 186
         else
187 187
         {
188
-            throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56);
188
+                throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56);
189
+        }
189 190
         }
190
-    }
191
-
192
-    /**
193
-     *      "Rough" validation of the received xml request
194
-     *
195
-     *      @param array $options
196
-     *      @throws Exception\Data
197
-     *      @throws Exception\Structure
198
-     */
199
-    public function validate_request($options)
200
-    {
191
+
192
+        /**
193
+         *      "Rough" validation of the received xml request
194
+         *
195
+         *      @param array $options
196
+         *      @throws Exception\Data
197
+         *      @throws Exception\Structure
198
+         */
199
+        public function validate_request($options)
200
+        {
201 201
         $this->validate_element('DateTime');
202 202
         $this->validate_element('Sign');
203 203
         $this->validate_element('ServiceId');
@@ -205,87 +205,87 @@  discard block
 block discarded – undo
205 205
         // compare received value ServiceId with option ServiceId
206 206
         if (intval($options['ServiceId']) != intval($this->ServiceId))
207 207
         {
208
-            throw new Exception\Data('This request is not for our ServiceId!', -58);
208
+                throw new Exception\Data('This request is not for our ServiceId!', -58);
209
+        }
209 210
         }
210
-    }
211
-
212
-    /**
213
-     *      Validation of xml-element
214
-     *
215
-     *      @param string $name
216
-     */
217
-    public function validate_element($name)
218
-    {
211
+
212
+        /**
213
+         *      Validation of xml-element
214
+         *
215
+         *      @param string $name
216
+         */
217
+        public function validate_element($name)
218
+        {
219 219
         if ( ! isset($this->$name))
220 220
         {
221
-            throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57);
221
+                throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57);
222
+        }
222 223
         }
223
-    }
224
-
225
-    /**
226
-     *      Verify signature of request
227
-     *
228
-     *      @param array $options
229
-     *      @throws Exception\Runtime
230
-     *      @throws Exception\Sign
231
-     */
232
-    public function verify_sign($options)
233
-    {
224
+
225
+        /**
226
+         *      Verify signature of request
227
+         *
228
+         *      @param array $options
229
+         *      @throws Exception\Runtime
230
+         *      @throws Exception\Sign
231
+         */
232
+        public function verify_sign($options)
233
+        {
234 234
         if (!isset($options['UseSign']) || ($options['UseSign'] === false))
235 235
         {
236
-            return null;
236
+                return null;
237 237
         }
238 238
         if ( ! isset($options['EasySoftPKey']))
239 239
         {
240
-            throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94);
240
+                throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94);
241 241
         }
242 242
         $pkeyid = (new Key())->get($options['EasySoftPKey'], 'public');
243 243
 
244 244
         $pub_key = openssl_pkey_get_public($pkeyid);
245 245
         if ($pub_key === FALSE)
246 246
         {
247
-            throw new Exception\Runtime('Can not extract the public key from certificate!', -97);
247
+                throw new Exception\Runtime('Can not extract the public key from certificate!', -97);
248 248
         }
249 249
         $bin_sign = pack("H*", $this->Sign);
250 250
         $xml = str_replace($this->Sign, '', $this->raw_request);
251 251
         $check = openssl_verify($xml, $bin_sign, $pub_key);
252 252
         if ($check == -1)
253 253
         {
254
-            throw new Exception\Sign('Error verify signature of request!', -96);
254
+                throw new Exception\Sign('Error verify signature of request!', -96);
255 255
         }
256 256
         elseif ($check == 0)
257 257
         {
258
-            throw new Exception\Sign('Signature of request is incorrect!', -95);
258
+                throw new Exception\Sign('Signature of request is incorrect!', -95);
259
+        }
259 260
         }
260
-    }
261
-
262
-    /**
263
-     *      Selects nodes by name
264
-     *
265
-     *      @param \DOMDocument $dom
266
-     *      @param string $name
267
-     *      @param array $ret
268
-     *
269
-     *      @return array nodes with the name
270
-     */
271
-    protected function getNodes($dom, $name, $ret=array())
272
-    {
261
+
262
+        /**
263
+         *      Selects nodes by name
264
+         *
265
+         *      @param \DOMDocument $dom
266
+         *      @param string $name
267
+         *      @param array $ret
268
+         *
269
+         *      @return array nodes with the name
270
+         */
271
+        protected function getNodes($dom, $name, $ret=array())
272
+        {
273 273
         foreach($dom->childNodes as $child)
274 274
         {
275
-            if ($child->nodeName == $name)
276
-            {
275
+                if ($child->nodeName == $name)
276
+                {
277 277
                 array_push($ret, $child);
278
-            }
279
-            else
280
-            {
278
+                }
279
+                else
280
+                {
281 281
                 if (count($child->childNodes) > 0)
282 282
                 {
283
-                    $ret = $this->getNodes($child, $name, $ret);
283
+                        $ret = $this->getNodes($child, $name, $ret);
284
+                }
284 285
                 }
285
-            }
286 286
         }
287 287
 
288 288
         return $ret;
289
-    }
289
+        }
290 290
 
291 291
 }
Please login to merge, or discard this patch.