@@ -90,7 +90,7 @@ |
||
90 | 90 | * Sets the message based on the code |
91 | 91 | */ |
92 | 92 | protected function setMessageBasedOnCode() { |
93 | - if(empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
93 | + if (empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
94 | 94 | $this->message = self::$_code_to_messages[$this->code]; |
95 | 95 | } |
96 | 96 | } |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function setSupportedPackageTypes($supported_package_types) { |
74 | 74 | $this->_supported_package_types = null; |
75 | - if(is_array($supported_package_types)) { |
|
76 | - foreach($supported_package_types as $package_type) { |
|
77 | - if(in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
75 | + if (is_array($supported_package_types)) { |
|
76 | + foreach ($supported_package_types as $package_type) { |
|
77 | + if (in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
78 | 78 | $this->_supported_package_types[] = $package_type; |
79 | 79 | } |
80 | 80 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function setSupportedPackageFormats($supported_package_formats) { |
96 | 96 | $this->_supported_package_formats = null; |
97 | - if(is_array($supported_package_formats)) { |
|
98 | - foreach($supported_package_formats as $package_format) { |
|
99 | - if(in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
97 | + if (is_array($supported_package_formats)) { |
|
98 | + foreach ($supported_package_formats as $package_format) { |
|
99 | + if (in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
100 | 100 | $this->_supported_package_formats[] = $package_format; |
101 | 101 | } |
102 | 102 | } |
@@ -26,7 +26,7 @@ |
||
26 | 26 | * @licence http://www.gnu.org/licenses/gpl.txt |
27 | 27 | */ |
28 | 28 | |
29 | -require_once __DIR__ . '/pens_request.php'; |
|
29 | +require_once __DIR__.'/pens_request.php'; |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * PENSRequestReceipt |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | * @licence http://www.gnu.org/licenses/gpl.txt |
27 | 27 | */ |
28 | 28 | |
29 | -require_once __DIR__ . '/pens_controller.php'; |
|
30 | -require_once __DIR__ . '/pens_package_handler.php'; |
|
31 | -require_once __DIR__ . '/pens_exception.php'; |
|
32 | -require_once __DIR__ . '/pens_response.php'; |
|
29 | +require_once __DIR__.'/pens_controller.php'; |
|
30 | +require_once __DIR__.'/pens_package_handler.php'; |
|
31 | +require_once __DIR__.'/pens_exception.php'; |
|
32 | +require_once __DIR__.'/pens_response.php'; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * PENSServer |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * Singleton method |
65 | 65 | */ |
66 | 66 | public static function singleton() { |
67 | - if(!isset(self::$_instance)) { |
|
67 | + if (!isset(self::$_instance)) { |
|
68 | 68 | $c = __CLASS__; |
69 | 69 | self::$_instance = new $c; |
70 | 70 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param PENSPackageHandler Package handler |
89 | 89 | */ |
90 | 90 | public function setPackageHandler($package_handler) { |
91 | - if($package_handler instanceof PENSPackageHandler) { |
|
91 | + if ($package_handler instanceof PENSPackageHandler) { |
|
92 | 92 | $this->_package_handler = $package_handler; |
93 | 93 | } |
94 | 94 | } |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | try { |
102 | 102 | // First, try to parse the request |
103 | 103 | $request = $this->parseRequest(); |
104 | - if($request->getCommand() == "collect") { |
|
105 | - if(isset($_REQUEST['process'])) { |
|
104 | + if ($request->getCommand() == "collect") { |
|
105 | + if (isset($_REQUEST['process'])) { |
|
106 | 106 | // Collect the package and process it |
107 | 107 | $receipt = null; |
108 | 108 | $path_to_package = null; |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | // Collect the package |
111 | 111 | $path_to_package = $this->collectPackage($request); |
112 | 112 | $receipt = new PENSResponse(0, "package successfully collected"); |
113 | - } catch(PENSException $e) { |
|
113 | + } catch (PENSException $e) { |
|
114 | 114 | $receipt = new PENSResponse($e); |
115 | 115 | } |
116 | 116 | // Send receipt |
117 | 117 | $response = $this->sendReceipt($request, $receipt); |
118 | - if(!is_null($response) && !is_null($path_to_package)) { |
|
119 | - if($response->getError() === 0) { |
|
118 | + if (!is_null($response) && !is_null($path_to_package)) { |
|
119 | + if ($response->getError() === 0) { |
|
120 | 120 | // Process package |
121 | 121 | $this->processPackage($request, $path_to_package); |
122 | 122 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $params = $_REQUEST; |
130 | 130 | $params['process'] = 1; |
131 | 131 | $scheme = "http"; |
132 | - if(!empty($_SERVER['HTTPS'])) { |
|
132 | + if (!empty($_SERVER['HTTPS'])) { |
|
133 | 133 | $scheme = "https"; |
134 | 134 | } |
135 | 135 | $ch = curl_init(); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - } catch(PENSException $e) { |
|
144 | + } catch (PENSException $e) { |
|
145 | 145 | // If we could not parse the request, send the error back to the client |
146 | 146 | $this->sendResponse(new PENSResponse($e)); |
147 | 147 | } |
@@ -156,20 +156,20 @@ discard block |
||
156 | 156 | */ |
157 | 157 | protected function collectPackage($request) { |
158 | 158 | $supported_package_types = $this->_package_handler->getSupportedPackageTypes(); |
159 | - if(!in_array($request->getPackageType(), $supported_package_types)) { |
|
159 | + if (!in_array($request->getPackageType(), $supported_package_types)) { |
|
160 | 160 | throw new PENSException(1430); |
161 | 161 | } |
162 | 162 | $supported_package_formats = $this->_package_handler->getSupportedPackageFormats(); |
163 | - if(!in_array($request->getPackageFormat(), $supported_package_formats)) { |
|
163 | + if (!in_array($request->getPackageFormat(), $supported_package_formats)) { |
|
164 | 164 | throw new PENSException(1431); |
165 | 165 | } |
166 | - if(!$this->isExpiryDateValid($request->getPackageUrlExpiry())) { |
|
166 | + if (!$this->isExpiryDateValid($request->getPackageUrlExpiry())) { |
|
167 | 167 | throw new PENSException(1322); |
168 | 168 | } |
169 | 169 | |
170 | 170 | // Try to download the package in the temporary directory |
171 | 171 | $tmp = null; |
172 | - if(function_exists("sys_get_temp_dir")) { |
|
172 | + if (function_exists("sys_get_temp_dir")) { |
|
173 | 173 | $tmp = sys_get_temp_dir(); |
174 | 174 | } else { |
175 | 175 | $tmp = "/tmp"; |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | curl_setopt($ch, CURLOPT_URL, $request->getPackageUrl()); |
181 | 181 | curl_setopt($ch, CURLOPT_HEADER, false); |
182 | 182 | curl_setopt($ch, CURLOPT_FILE, $fp); |
183 | - if(!is_null($request->getPackageUrlUserId())) { |
|
183 | + if (!is_null($request->getPackageUrlUserId())) { |
|
184 | 184 | curl_setopt($ch, CURLOPT_USERPWD, $request->getPackageUrlUserId().":".$request->getPackageUrlPassword()); |
185 | 185 | } |
186 | - if(curl_exec($ch) === false) { |
|
186 | + if (curl_exec($ch) === false) { |
|
187 | 187 | $errno = curl_errno($ch); |
188 | 188 | curl_close($ch); |
189 | 189 | // Error occured. Throw an exception |
190 | - switch($errno) { |
|
190 | + switch ($errno) { |
|
191 | 191 | case CURLE_UNSUPPORTED_PROTOCOL: |
192 | 192 | throw new PENSException(1301); |
193 | 193 | break; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | date_default_timezone_set('UTC'); |
224 | 224 | $current_time = time(); |
225 | 225 | $expiry_time = strtotime($expiry->format(DateTime::ISO8601)); |
226 | - if($current_time > $expiry_time) { |
|
226 | + if ($current_time > $expiry_time) { |
|
227 | 227 | return false; |
228 | 228 | } else { |
229 | 229 | return true; |
@@ -239,17 +239,17 @@ discard block |
||
239 | 239 | * @return PENSResponse Response |
240 | 240 | */ |
241 | 241 | protected function sendAlertOrReceipt($request, $response, $mode) { |
242 | - if($mode == "alert") { |
|
242 | + if ($mode == "alert") { |
|
243 | 243 | $url = $request->getAlerts(); |
244 | 244 | } else { |
245 | 245 | $url = $request->getReceipt(); |
246 | 246 | } |
247 | - if(!empty($url)) { |
|
247 | + if (!empty($url)) { |
|
248 | 248 | $url_components = parse_url($url); |
249 | 249 | $scheme = $url_components["scheme"]; |
250 | - if($scheme == "mailto") { |
|
250 | + if ($scheme == "mailto") { |
|
251 | 251 | $to = $url_components["path"]; |
252 | - if($mode == "alert") { |
|
252 | + if ($mode == "alert") { |
|
253 | 253 | $subject = "PENS Alert for ".$request->getPackageId(); |
254 | 254 | } else { |
255 | 255 | $subject = "PENS Receipt for ".$request->getPackageId(); |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | $message = $response->__toString(); |
258 | 258 | mail($to, $subject, $message); |
259 | 259 | return new PENSResponse(0, ""); |
260 | - } else if($scheme == "http" || $scheme == "https") { |
|
261 | - if($mode == "alert") { |
|
260 | + } else if ($scheme == "http" || $scheme == "https") { |
|
261 | + if ($mode == "alert") { |
|
262 | 262 | $params = array_merge($request->getSendAlertArray(), $response->getArray()); |
263 | 263 | } else { |
264 | 264 | $params = array_merge($request->getSendReceiptArray(), $response->getArray()); |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
270 | 270 | $data = curl_exec($ch); |
271 | 271 | curl_close($ch); |
272 | - if($data === false) { |
|
272 | + if ($data === false) { |
|
273 | 273 | return null; |
274 | 274 | } else { |
275 | 275 | return new PENSResponse($data); |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | * @licence http://www.gnu.org/licenses/gpl.txt |
28 | 28 | */ |
29 | 29 | |
30 | -require_once __DIR__ . '/pens_exception.php'; |
|
31 | -require_once __DIR__ . '/pens_request_receipt.php'; |
|
32 | -require_once __DIR__ . '/pens_request_collect.php'; |
|
33 | -require_once __DIR__ . '/pens_request_alert.php'; |
|
30 | +require_once __DIR__.'/pens_exception.php'; |
|
31 | +require_once __DIR__.'/pens_request_receipt.php'; |
|
32 | +require_once __DIR__.'/pens_request_collect.php'; |
|
33 | +require_once __DIR__.'/pens_request_alert.php'; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * PENSRequestFactory |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public static function createPENSRequest($arguments) { |
57 | 57 | $command = $arguments["command"]; |
58 | - if($command == "alert") { |
|
58 | + if ($command == "alert") { |
|
59 | 59 | return new PENSRequestAlert($arguments); |
60 | - } else if($command == "collect") { |
|
60 | + } else if ($command == "collect") { |
|
61 | 61 | return new PENSRequestCollect($arguments); |
62 | - } else if($command == "receipt") { |
|
62 | + } else if ($command == "receipt") { |
|
63 | 63 | return new PENSRequestReceipt($arguments); |
64 | 64 | } else { |
65 | 65 | throw new PENSException(2002); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | * @throws PENSException with code 2001 if invalid |
187 | 187 | */ |
188 | 188 | public function setPensVersion($pens_version) { |
189 | - if($pens_version == PENSConfig::$version) { |
|
189 | + if ($pens_version == PENSConfig::$version) { |
|
190 | 190 | $this->_pens_version = $pens_version; |
191 | 191 | } else { |
192 | 192 | throw new PENSException(2001); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @throws PENSException with code 2002 if invalid |
206 | 206 | */ |
207 | 207 | protected function setCommand($command) { |
208 | - if(in_array($command, PENSConfig::$allowed_commands)) { |
|
208 | + if (in_array($command, PENSConfig::$allowed_commands)) { |
|
209 | 209 | $this->_command = $command; |
210 | 210 | } else { |
211 | 211 | throw new PENSException(2002); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @throws PENSException with code 2003 if invalid |
225 | 225 | */ |
226 | 226 | public function setPackageType($package_type) { |
227 | - if(in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
227 | + if (in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
228 | 228 | $this->_package_type = $package_type; |
229 | 229 | } else { |
230 | 230 | throw new PENSException(2003); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @throws PENSException with code 2004 if invalid |
244 | 244 | */ |
245 | 245 | public function setPackageTypeVersion($package_type_version) { |
246 | - if(empty($package_type_version)) { |
|
246 | + if (empty($package_type_version)) { |
|
247 | 247 | throw new PENSException(2004); |
248 | 248 | } else { |
249 | 249 | $this->_package_type_version = $package_type_version; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @throws PENSException with code 2005 if invalid |
263 | 263 | */ |
264 | 264 | public function setPackageFormat($package_format) { |
265 | - if(in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
265 | + if (in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
266 | 266 | $this->_package_format = $package_format; |
267 | 267 | } else { |
268 | 268 | throw new PENSException(2005); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | } |
317 | 317 | |
318 | 318 | public function setPackageUrlUserId($package_url_user_id) { |
319 | - if(!empty($package_url_user_id)) { |
|
319 | + if (!empty($package_url_user_id)) { |
|
320 | 320 | $this->_package_url_user_id = $package_url_user_id; |
321 | 321 | } |
322 | 322 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | } |
327 | 327 | |
328 | 328 | public function setPackageUrlAccount($package_url_account) { |
329 | - if(!empty($package_url_account)) { |
|
329 | + if (!empty($package_url_account)) { |
|
330 | 330 | $this->_package_url_account = $package_url_account; |
331 | 331 | } |
332 | 332 | } |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | public function setPackageUrlPassword($package_url_password) { |
339 | - if(!empty($package_url_password)) { |
|
339 | + if (!empty($package_url_password)) { |
|
340 | 340 | $this->_package_url_password = $package_url_password; |
341 | 341 | } |
342 | 342 | } |
@@ -354,13 +354,13 @@ discard block |
||
354 | 354 | * @todo Perform a better validation of the date |
355 | 355 | */ |
356 | 356 | public function setPackageUrlExpiry($package_url_expiry) { |
357 | - if(empty($package_url_expiry)) { |
|
357 | + if (empty($package_url_expiry)) { |
|
358 | 358 | throw new PENSException(2009); |
359 | 359 | } else { |
360 | 360 | try { |
361 | 361 | $expiry = new DateTime($package_url_expiry, new DateTimeZone('UTC')); |
362 | 362 | $this->_package_url_expiry = $expiry; |
363 | - } catch(Exception $e) { |
|
363 | + } catch (Exception $e) { |
|
364 | 364 | throw new PENSException(2009); |
365 | 365 | } |
366 | 366 | } |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @throws PENSException with code 2010 if invalid |
379 | 379 | */ |
380 | 380 | public function setClient($client) { |
381 | - if(!empty($client)) { |
|
381 | + if (!empty($client)) { |
|
382 | 382 | $this->_client = $client; |
383 | 383 | } else { |
384 | 384 | throw new PENSException(2010); |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | public function setSystemUserId($system_user_id) { |
393 | - if(!empty($system_user_id)) { |
|
393 | + if (!empty($system_user_id)) { |
|
394 | 394 | $this->_system_user_id = $system_user_id; |
395 | 395 | } |
396 | 396 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | } |
401 | 401 | |
402 | 402 | public function setSystemPassword($system_password) { |
403 | - if(!empty($system_password)) { |
|
403 | + if (!empty($system_password)) { |
|
404 | 404 | $this->_system_password = $system_password; |
405 | 405 | } |
406 | 406 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | * @throws PENSException with code 2011 if invalid |
418 | 418 | */ |
419 | 419 | public function setReceipt($receipt) { |
420 | - if($this instanceof PENSRequestCollect) { |
|
420 | + if ($this instanceof PENSRequestCollect) { |
|
421 | 421 | if (preg_match('/'.ABSOLUTEURI_2396.'/', $receipt)) { |
422 | 422 | $this->_receipt = $receipt; |
423 | 423 | } else { |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | } |
432 | 432 | |
433 | 433 | public function setAlerts($alerts) { |
434 | - if(!empty($alerts)) { |
|
435 | - if(preg_match('/'.ABSOLUTEURI_2396.'/', $alerts)) { |
|
434 | + if (!empty($alerts)) { |
|
435 | + if (preg_match('/'.ABSOLUTEURI_2396.'/', $alerts)) { |
|
436 | 436 | $this->_alerts = $alerts; |
437 | 437 | } else { |
438 | 438 | throw new PENSException(1201); |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | } |
446 | 446 | |
447 | 447 | public function setVendorData($vendor_data) { |
448 | - if(!empty($vendor_data)) { |
|
448 | + if (!empty($vendor_data)) { |
|
449 | 449 | $this->_vendor_data = $vendor_data; |
450 | 450 | } |
451 | 451 | } |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | * @licence http://www.gnu.org/licenses/gpl.txt |
27 | 27 | */ |
28 | 28 | |
29 | -require_once __DIR__ . '/pens_config.php'; |
|
30 | -require_once __DIR__ . '/pens_message.php'; |
|
31 | -require_once __DIR__ . '/pens_exception.php'; |
|
29 | +require_once __DIR__.'/pens_config.php'; |
|
30 | +require_once __DIR__.'/pens_message.php'; |
|
31 | +require_once __DIR__.'/pens_exception.php'; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * PENSResponse |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function __construct($error, $error_text = null, $pens_data = null) { |
75 | 75 | $this->_pens_version = PENSConfig::$version; |
76 | - if($error instanceof PENSException) { |
|
76 | + if ($error instanceof PENSException) { |
|
77 | 77 | $this->_error = $error->getCode(); |
78 | 78 | $this->_error_text = $error->getMessage(); |
79 | - } else if(is_string($error)){ |
|
79 | + } else if (is_string($error)) { |
|
80 | 80 | // Parse the string |
81 | 81 | $this->parseResponse($error); |
82 | - } else if(is_array($error)) { |
|
82 | + } else if (is_array($error)) { |
|
83 | 83 | // Try to build from array |
84 | 84 | $this->_error = $error["error"]; |
85 | 85 | $this->_error_text = $error["error-text"]; |
@@ -100,22 +100,22 @@ discard block |
||
100 | 100 | protected function parseResponse($response) { |
101 | 101 | $lines = explode(PENSConfig::$eol, $response); |
102 | 102 | $i = 1; |
103 | - foreach($lines as $line) { |
|
104 | - if($i < 5) { |
|
103 | + foreach ($lines as $line) { |
|
104 | + if ($i < 5) { |
|
105 | 105 | $pair = explode("=", $line); |
106 | - if($pair[0] == "error") { |
|
106 | + if ($pair[0] == "error") { |
|
107 | 107 | $this->_error = intval($pair[1]); |
108 | - } else if($pair[0] == "error-text") { |
|
108 | + } else if ($pair[0] == "error-text") { |
|
109 | 109 | $this->_error_text = $pair[1]; |
110 | - } else if($pair[0] == "version") { |
|
110 | + } else if ($pair[0] == "version") { |
|
111 | 111 | $this->_pens_version = $pair[1]; |
112 | - } else if($pair[0] == "pens-data") { |
|
113 | - if(!empty($pair[1])) { |
|
112 | + } else if ($pair[0] == "pens-data") { |
|
113 | + if (!empty($pair[1])) { |
|
114 | 114 | $this->_pens_data = $pair[1].PENSConfig::$eol; |
115 | 115 | } |
116 | 116 | } |
117 | 117 | } else { |
118 | - if(!empty($line)) { |
|
118 | + if (!empty($line)) { |
|
119 | 119 | $this->_pens_data .= $line.PENSConfig::$eol; |
120 | 120 | } |
121 | 121 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . '/pens/pens_request_factory.php'; |
|
4 | -require_once __DIR__ . '/pens/pens_response.php'; |
|
5 | -require_once __DIR__ . '/pens/pens_package_handler.php'; |
|
6 | -require_once __DIR__ . '/pens/pens_server.php'; |
|
7 | -require_once __DIR__ . '/pens/pens_client.php'; |
|
3 | +require_once __DIR__.'/pens/pens_request_factory.php'; |
|
4 | +require_once __DIR__.'/pens/pens_response.php'; |
|
5 | +require_once __DIR__.'/pens/pens_package_handler.php'; |
|
6 | +require_once __DIR__.'/pens/pens_server.php'; |
|
7 | +require_once __DIR__.'/pens/pens_client.php'; |
@@ -23,7 +23,7 @@ |
||
23 | 23 | * @licence http://www.gnu.org/licenses/gpl.txt |
24 | 24 | */ |
25 | 25 | |
26 | -require_once __DIR__ . '/pens.php'; |
|
26 | +require_once __DIR__.'/pens.php'; |
|
27 | 27 | |
28 | 28 | class MyPackageHandler extends PENSPackageHandler { |
29 | 29 | public function processPackage($request, $path_to_package) { |