@@ -40,9 +40,9 @@ |
||
40 | 40 | |
41 | 41 | class PENSRequestReceipt extends PENSRequest { |
42 | 42 | |
43 | - public function __construct($arguments) { |
|
44 | - parent::__construct($arguments); |
|
45 | - $this->setCommand("receipt"); |
|
46 | - } |
|
43 | + public function __construct($arguments) { |
|
44 | + parent::__construct($arguments); |
|
45 | + $this->setCommand("receipt"); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
@@ -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 |
@@ -43,26 +43,26 @@ |
||
43 | 43 | */ |
44 | 44 | class PENSRequestFactory { |
45 | 45 | |
46 | - /** |
|
47 | - * Factory method |
|
48 | - * |
|
49 | - * Creates the right PENSRequest object, based on the command inside the arguments |
|
50 | - * |
|
51 | - * @param array Associative array of arguments |
|
52 | - * @return mixed PENSRequestAlert or PENSRequestCollect or PENSRequestReceipt |
|
53 | - * |
|
54 | - * @throws PENSException with code 2002 if command is invalid |
|
55 | - */ |
|
56 | - public static function createPENSRequest($arguments) { |
|
57 | - $command = $arguments["command"]; |
|
58 | - if($command == "alert") { |
|
59 | - return new PENSRequestAlert($arguments); |
|
60 | - } else if($command == "collect") { |
|
61 | - return new PENSRequestCollect($arguments); |
|
62 | - } else if($command == "receipt") { |
|
63 | - return new PENSRequestReceipt($arguments); |
|
64 | - } else { |
|
65 | - throw new PENSException(2002); |
|
66 | - } |
|
67 | - } |
|
46 | + /** |
|
47 | + * Factory method |
|
48 | + * |
|
49 | + * Creates the right PENSRequest object, based on the command inside the arguments |
|
50 | + * |
|
51 | + * @param array Associative array of arguments |
|
52 | + * @return mixed PENSRequestAlert or PENSRequestCollect or PENSRequestReceipt |
|
53 | + * |
|
54 | + * @throws PENSException with code 2002 if command is invalid |
|
55 | + */ |
|
56 | + public static function createPENSRequest($arguments) { |
|
57 | + $command = $arguments["command"]; |
|
58 | + if($command == "alert") { |
|
59 | + return new PENSRequestAlert($arguments); |
|
60 | + } else if($command == "collect") { |
|
61 | + return new PENSRequestCollect($arguments); |
|
62 | + } else if($command == "receipt") { |
|
63 | + return new PENSRequestReceipt($arguments); |
|
64 | + } else { |
|
65 | + throw new PENSException(2002); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | } |
@@ -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 | } |
@@ -43,453 +43,453 @@ |
||
43 | 43 | |
44 | 44 | abstract class PENSRequest extends PENSMessage { |
45 | 45 | |
46 | - /** |
|
47 | - * PENS Version to be used. Currently, the only valid value is 1.0.0. Required. |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $_pens_version = null; |
|
51 | - |
|
52 | - /** |
|
53 | - * Command being used. The only valid values are collect, alert and receipt.Required |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_command = null; |
|
57 | - |
|
58 | - /** |
|
59 | - * Package type being used. The only valid values are aicc-pkg, scorm-pif, ims-qti. Required |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $_package_type = null; |
|
63 | - |
|
64 | - /** |
|
65 | - * Package type version. Required |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - protected $_package_type_version = null; |
|
69 | - |
|
70 | - /** |
|
71 | - * Package format. The only valid values are zip, url, jar, war and xml. Required |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - protected $_package_format = null; |
|
75 | - |
|
76 | - /** |
|
77 | - * Package id. Requires a valid URI according to RFC 2396. Required |
|
78 | - * @var string |
|
79 | - */ |
|
80 | - protected $_package_id = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * Package url. Requires a valid, fully qualified URL including transport protocol and filename extension. Required |
|
84 | - * @var string |
|
85 | - */ |
|
86 | - protected $_package_url = null; |
|
87 | - |
|
88 | - /** |
|
89 | - * User id required for system to retrieve package from URL. Optional. |
|
90 | - * @var string |
|
91 | - */ |
|
92 | - protected $_package_url_user_id = null; |
|
93 | - |
|
94 | - /** |
|
95 | - * Account required for system to retrieve package from URL. Optional. |
|
96 | - * @var string |
|
97 | - */ |
|
98 | - protected $_package_url_account = null; |
|
99 | - |
|
100 | - /** |
|
101 | - * Password required for system to retrieve package from URL. Optional. |
|
102 | - * @var string |
|
103 | - */ |
|
104 | - protected $_package_url_password = null; |
|
105 | - |
|
106 | - /** |
|
107 | - * Expiry date for package URL. ISO 8601 format expressed as UTC. Will be transformed into a PHP DateTime object during construction. Required |
|
108 | - * @var DateTime |
|
109 | - */ |
|
110 | - protected $_package_url_expiry = null; |
|
111 | - |
|
112 | - /** |
|
113 | - * Name or ID for client submitting the content package to the target system. Required. |
|
114 | - * @var string |
|
115 | - */ |
|
116 | - protected $_client = null; |
|
117 | - |
|
118 | - /** |
|
119 | - * User-id or sign-on for target system. Optional |
|
120 | - * @var string |
|
121 | - */ |
|
122 | - protected $_system_user_id = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * Either a URL-encoded password token or the null string. If the |
|
126 | - * target system requires a password and the null string value is |
|
127 | - * passed, then the target system is responsible for prompting for a |
|
128 | - * password for target system. Optional |
|
129 | - * @var string |
|
130 | - */ |
|
131 | - protected $_system_password = null; |
|
132 | - |
|
133 | - /** |
|
134 | - * URL to send acknowledgement receipt after collecting a package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Required. |
|
135 | - * @var string |
|
136 | - */ |
|
137 | - protected $_receipt = null; |
|
138 | - |
|
139 | - /** |
|
140 | - * URL to send alerts to while processing the package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Optional. |
|
141 | - * @var string |
|
142 | - */ |
|
143 | - protected $_alerts = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * Unstructured character string that may be used to transfer vendor-specific data such as processing hints or deployment information. Optional. |
|
147 | - * @var string |
|
148 | - */ |
|
149 | - protected $_vendor_data = null; |
|
150 | - |
|
151 | - /** |
|
152 | - * Constructor |
|
153 | - * |
|
154 | - * Constructs a PENSRequest based class using the arguments given |
|
155 | - * |
|
156 | - * @param array Arguments |
|
157 | - */ |
|
158 | - public function __construct($arguments) { |
|
159 | - $this->setPensVersion($arguments["pens-version"]); |
|
160 | - $this->setPackageType($arguments["package-type"]); |
|
161 | - $this->setPackageTypeVersion($arguments["package-type-version"]); |
|
162 | - $this->setPackageFormat($arguments["package-format"]); |
|
163 | - $this->setPackageId($arguments["package-id"]); |
|
164 | - $this->setPackageUrl($arguments["package-url"]); |
|
165 | - $this->setPackageUrlUserId($arguments["package-url-user-id"]); |
|
166 | - $this->setPackageUrlAccount($arguments["package-url-account"]); |
|
167 | - $this->setPackageUrlPassword($arguments["package-url-password"]); |
|
168 | - $this->setPackageUrlExpiry($arguments["package-url-expiry"]); |
|
169 | - $this->setClient($arguments["client"]); |
|
170 | - $this->setSystemUserId($arguments["system-user-id"]); |
|
171 | - $this->setSystemPassword($arguments["system-password"]); |
|
172 | - $this->setReceipt($arguments["receipt"]); |
|
173 | - $this->setAlerts($arguments["alerts"]); |
|
174 | - $this->setVendorData($arguments["vendor-data"]); |
|
175 | - } |
|
176 | - |
|
177 | - public function getPensVersion() { |
|
178 | - return $this->_pens_version; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Sets the PENS version |
|
183 | - * |
|
184 | - * @param string PENS version |
|
185 | - * |
|
186 | - * @throws PENSException with code 2001 if invalid |
|
187 | - */ |
|
188 | - public function setPensVersion($pens_version) { |
|
189 | - if($pens_version == PENSConfig::$version) { |
|
190 | - $this->_pens_version = $pens_version; |
|
191 | - } else { |
|
192 | - throw new PENSException(2001); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - public function getCommand() { |
|
197 | - return $this->_command; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Sets the command |
|
202 | - * |
|
203 | - * @param string command |
|
204 | - * |
|
205 | - * @throws PENSException with code 2002 if invalid |
|
206 | - */ |
|
207 | - protected function setCommand($command) { |
|
208 | - if(in_array($command, PENSConfig::$allowed_commands)) { |
|
209 | - $this->_command = $command; |
|
210 | - } else { |
|
211 | - throw new PENSException(2002); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - public function getPackageType() { |
|
216 | - return $this->_package_type; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Sets the package type |
|
221 | - * |
|
222 | - * @param string package type |
|
223 | - * |
|
224 | - * @throws PENSException with code 2003 if invalid |
|
225 | - */ |
|
226 | - public function setPackageType($package_type) { |
|
227 | - if(in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
228 | - $this->_package_type = $package_type; |
|
229 | - } else { |
|
230 | - throw new PENSException(2003); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - public function getPackageTypeVersion() { |
|
235 | - return $this->_package_type_version; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Sets the package type version |
|
240 | - * |
|
241 | - * @param string package type version |
|
242 | - * |
|
243 | - * @throws PENSException with code 2004 if invalid |
|
244 | - */ |
|
245 | - public function setPackageTypeVersion($package_type_version) { |
|
246 | - if(empty($package_type_version)) { |
|
247 | - throw new PENSException(2004); |
|
248 | - } else { |
|
249 | - $this->_package_type_version = $package_type_version; |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - public function getPackageFormat() { |
|
254 | - return $this->_package_format; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Sets the package format |
|
259 | - * |
|
260 | - * @param string package format |
|
261 | - * |
|
262 | - * @throws PENSException with code 2005 if invalid |
|
263 | - */ |
|
264 | - public function setPackageFormat($package_format) { |
|
265 | - if(in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
266 | - $this->_package_format = $package_format; |
|
267 | - } else { |
|
268 | - throw new PENSException(2005); |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - public function getPackageId() { |
|
273 | - return $this->_package_id; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Sets the package Id |
|
278 | - * |
|
279 | - * @param string package Id |
|
280 | - * |
|
281 | - * @throws PENSException with code 2007 if invalid |
|
282 | - */ |
|
283 | - public function setPackageId($package_id) { |
|
284 | - if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_id)) { |
|
285 | - $this->_package_id = $package_id; |
|
286 | - } else { |
|
287 | - throw new PENSException(2007); |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - public function getPackageUrl() { |
|
292 | - return $this->_package_url; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Sets the package url |
|
297 | - * |
|
298 | - * @param string package url |
|
299 | - * |
|
300 | - * @throws PENSException with code 2008 if invalid |
|
301 | - */ |
|
302 | - public function setPackageUrl($package_url) { |
|
303 | - if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_url) && substr($package_url, -4) == ".".$this->_package_format) { |
|
304 | - $this->_package_url = $package_url; |
|
305 | - } else { |
|
306 | - throw new PENSException(2008); |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - public function getFilename() { |
|
311 | - return substr(strrchr($this->_package_url, "/"), 1); |
|
312 | - } |
|
313 | - |
|
314 | - public function getPackageUrlUserId() { |
|
315 | - return $this->_package_url_user_id; |
|
316 | - } |
|
317 | - |
|
318 | - public function setPackageUrlUserId($package_url_user_id) { |
|
319 | - if(!empty($package_url_user_id)) { |
|
320 | - $this->_package_url_user_id = $package_url_user_id; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - public function getPackageUrlAccount() { |
|
325 | - return $this->_package_url_account; |
|
326 | - } |
|
327 | - |
|
328 | - public function setPackageUrlAccount($package_url_account) { |
|
329 | - if(!empty($package_url_account)) { |
|
330 | - $this->_package_url_account = $package_url_account; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - public function getPackageUrlPassword() { |
|
335 | - return $this->_package_url_password; |
|
336 | - } |
|
337 | - |
|
338 | - public function setPackageUrlPassword($package_url_password) { |
|
339 | - if(!empty($package_url_password)) { |
|
340 | - $this->_package_url_password = $package_url_password; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - public function getPackageUrlExpiry() { |
|
345 | - return $this->_package_url_expiry; |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Sets the package url expiry and transforms it into a php DateTime object |
|
350 | - * |
|
351 | - * @param string package url expiry |
|
352 | - * |
|
353 | - * @throws PENSException with code 2009 if invalid |
|
354 | - * @todo Perform a better validation of the date |
|
355 | - */ |
|
356 | - public function setPackageUrlExpiry($package_url_expiry) { |
|
357 | - if(empty($package_url_expiry)) { |
|
358 | - throw new PENSException(2009); |
|
359 | - } else { |
|
360 | - try { |
|
361 | - $expiry = new DateTime($package_url_expiry, new DateTimeZone('UTC')); |
|
362 | - $this->_package_url_expiry = $expiry; |
|
363 | - } catch(Exception $e) { |
|
364 | - throw new PENSException(2009); |
|
365 | - } |
|
366 | - } |
|
367 | - } |
|
368 | - |
|
369 | - public function getClient() { |
|
370 | - return $this->_client; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Sets the client |
|
375 | - * |
|
376 | - * @param string client |
|
377 | - * |
|
378 | - * @throws PENSException with code 2010 if invalid |
|
379 | - */ |
|
380 | - public function setClient($client) { |
|
381 | - if(!empty($client)) { |
|
382 | - $this->_client = $client; |
|
383 | - } else { |
|
384 | - throw new PENSException(2010); |
|
385 | - } |
|
386 | - } |
|
387 | - |
|
388 | - public function getSystemUserId() { |
|
389 | - return $this->_system_user_id; |
|
390 | - } |
|
391 | - |
|
392 | - public function setSystemUserId($system_user_id) { |
|
393 | - if(!empty($system_user_id)) { |
|
394 | - $this->_system_user_id = $system_user_id; |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - public function getSystemPassword() { |
|
399 | - return $this->_system_password; |
|
400 | - } |
|
401 | - |
|
402 | - public function setSystemPassword($system_password) { |
|
403 | - if(!empty($system_password)) { |
|
404 | - $this->_system_password = $system_password; |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - public function getReceipt() { |
|
409 | - return $this->_receipt; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Sets the receipt url |
|
414 | - * |
|
415 | - * @param string receipt url |
|
416 | - * |
|
417 | - * @throws PENSException with code 2011 if invalid |
|
418 | - */ |
|
419 | - public function setReceipt($receipt) { |
|
420 | - if($this instanceof PENSRequestCollect) { |
|
421 | - if (preg_match('/'.ABSOLUTEURI_2396.'/', $receipt)) { |
|
422 | - $this->_receipt = $receipt; |
|
423 | - } else { |
|
424 | - throw new PENSException(2011); |
|
425 | - } |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - public function getAlerts() { |
|
430 | - return $this->_alerts; |
|
431 | - } |
|
432 | - |
|
433 | - public function setAlerts($alerts) { |
|
434 | - if(!empty($alerts)) { |
|
435 | - if(preg_match('/'.ABSOLUTEURI_2396.'/', $alerts)) { |
|
436 | - $this->_alerts = $alerts; |
|
437 | - } else { |
|
438 | - throw new PENSException(1201); |
|
439 | - } |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - public function getVendorData() { |
|
444 | - return $this->_vendor_data; |
|
445 | - } |
|
446 | - |
|
447 | - public function setVendorData($vendor_data) { |
|
448 | - if(!empty($vendor_data)) { |
|
449 | - $this->_vendor_data = $vendor_data; |
|
450 | - } |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Returns an associative that contains all the fields needed to send a |
|
455 | - * receipt or an alert to the client |
|
456 | - * |
|
457 | - * @return array Associative array |
|
458 | - */ |
|
459 | - protected function getSendReceiptAlertArray() { |
|
460 | - return array("pens-version" => $this->getPensVersion(), |
|
461 | - "package-type" => $this->getPackageType(), |
|
462 | - "package-type-version" => $this->getPackageTypeVersion(), |
|
463 | - "package-format" => $this->getPackageFormat(), |
|
464 | - "package-id" => $this->getPackageId(), |
|
465 | - "package-url" => $this->getPackageUrl(), |
|
466 | - "package-url-expiry" => $this->getPackageUrlExpiry()->format(DateTime::ISO8601), |
|
467 | - "client" => $this->getClient()); |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Returns an associative that contains all the fields needed to send a |
|
472 | - * receipt to the client |
|
473 | - * |
|
474 | - * @return array Associative array |
|
475 | - */ |
|
476 | - public function getSendReceiptArray() { |
|
477 | - $receipt = $this->getSendReceiptAlertArray(); |
|
478 | - $receipt["command"] = "receipt"; |
|
479 | - return $receipt; |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Returns an associative that contains all the fields needed to send an |
|
484 | - * alert to the client |
|
485 | - * |
|
486 | - * @return array Associative array |
|
487 | - */ |
|
488 | - public function getSendAlertArray() { |
|
489 | - $alert = $this->getSendReceiptAlertArray(); |
|
490 | - $alert["command"] = "alert"; |
|
491 | - return $alert; |
|
492 | - } |
|
46 | + /** |
|
47 | + * PENS Version to be used. Currently, the only valid value is 1.0.0. Required. |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $_pens_version = null; |
|
51 | + |
|
52 | + /** |
|
53 | + * Command being used. The only valid values are collect, alert and receipt.Required |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_command = null; |
|
57 | + |
|
58 | + /** |
|
59 | + * Package type being used. The only valid values are aicc-pkg, scorm-pif, ims-qti. Required |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $_package_type = null; |
|
63 | + |
|
64 | + /** |
|
65 | + * Package type version. Required |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + protected $_package_type_version = null; |
|
69 | + |
|
70 | + /** |
|
71 | + * Package format. The only valid values are zip, url, jar, war and xml. Required |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + protected $_package_format = null; |
|
75 | + |
|
76 | + /** |
|
77 | + * Package id. Requires a valid URI according to RFC 2396. Required |
|
78 | + * @var string |
|
79 | + */ |
|
80 | + protected $_package_id = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * Package url. Requires a valid, fully qualified URL including transport protocol and filename extension. Required |
|
84 | + * @var string |
|
85 | + */ |
|
86 | + protected $_package_url = null; |
|
87 | + |
|
88 | + /** |
|
89 | + * User id required for system to retrieve package from URL. Optional. |
|
90 | + * @var string |
|
91 | + */ |
|
92 | + protected $_package_url_user_id = null; |
|
93 | + |
|
94 | + /** |
|
95 | + * Account required for system to retrieve package from URL. Optional. |
|
96 | + * @var string |
|
97 | + */ |
|
98 | + protected $_package_url_account = null; |
|
99 | + |
|
100 | + /** |
|
101 | + * Password required for system to retrieve package from URL. Optional. |
|
102 | + * @var string |
|
103 | + */ |
|
104 | + protected $_package_url_password = null; |
|
105 | + |
|
106 | + /** |
|
107 | + * Expiry date for package URL. ISO 8601 format expressed as UTC. Will be transformed into a PHP DateTime object during construction. Required |
|
108 | + * @var DateTime |
|
109 | + */ |
|
110 | + protected $_package_url_expiry = null; |
|
111 | + |
|
112 | + /** |
|
113 | + * Name or ID for client submitting the content package to the target system. Required. |
|
114 | + * @var string |
|
115 | + */ |
|
116 | + protected $_client = null; |
|
117 | + |
|
118 | + /** |
|
119 | + * User-id or sign-on for target system. Optional |
|
120 | + * @var string |
|
121 | + */ |
|
122 | + protected $_system_user_id = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * Either a URL-encoded password token or the null string. If the |
|
126 | + * target system requires a password and the null string value is |
|
127 | + * passed, then the target system is responsible for prompting for a |
|
128 | + * password for target system. Optional |
|
129 | + * @var string |
|
130 | + */ |
|
131 | + protected $_system_password = null; |
|
132 | + |
|
133 | + /** |
|
134 | + * URL to send acknowledgement receipt after collecting a package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Required. |
|
135 | + * @var string |
|
136 | + */ |
|
137 | + protected $_receipt = null; |
|
138 | + |
|
139 | + /** |
|
140 | + * URL to send alerts to while processing the package. Any URL, including mailto (as per RFC 2368 and RFC 2822). Optional. |
|
141 | + * @var string |
|
142 | + */ |
|
143 | + protected $_alerts = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * Unstructured character string that may be used to transfer vendor-specific data such as processing hints or deployment information. Optional. |
|
147 | + * @var string |
|
148 | + */ |
|
149 | + protected $_vendor_data = null; |
|
150 | + |
|
151 | + /** |
|
152 | + * Constructor |
|
153 | + * |
|
154 | + * Constructs a PENSRequest based class using the arguments given |
|
155 | + * |
|
156 | + * @param array Arguments |
|
157 | + */ |
|
158 | + public function __construct($arguments) { |
|
159 | + $this->setPensVersion($arguments["pens-version"]); |
|
160 | + $this->setPackageType($arguments["package-type"]); |
|
161 | + $this->setPackageTypeVersion($arguments["package-type-version"]); |
|
162 | + $this->setPackageFormat($arguments["package-format"]); |
|
163 | + $this->setPackageId($arguments["package-id"]); |
|
164 | + $this->setPackageUrl($arguments["package-url"]); |
|
165 | + $this->setPackageUrlUserId($arguments["package-url-user-id"]); |
|
166 | + $this->setPackageUrlAccount($arguments["package-url-account"]); |
|
167 | + $this->setPackageUrlPassword($arguments["package-url-password"]); |
|
168 | + $this->setPackageUrlExpiry($arguments["package-url-expiry"]); |
|
169 | + $this->setClient($arguments["client"]); |
|
170 | + $this->setSystemUserId($arguments["system-user-id"]); |
|
171 | + $this->setSystemPassword($arguments["system-password"]); |
|
172 | + $this->setReceipt($arguments["receipt"]); |
|
173 | + $this->setAlerts($arguments["alerts"]); |
|
174 | + $this->setVendorData($arguments["vendor-data"]); |
|
175 | + } |
|
176 | + |
|
177 | + public function getPensVersion() { |
|
178 | + return $this->_pens_version; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Sets the PENS version |
|
183 | + * |
|
184 | + * @param string PENS version |
|
185 | + * |
|
186 | + * @throws PENSException with code 2001 if invalid |
|
187 | + */ |
|
188 | + public function setPensVersion($pens_version) { |
|
189 | + if($pens_version == PENSConfig::$version) { |
|
190 | + $this->_pens_version = $pens_version; |
|
191 | + } else { |
|
192 | + throw new PENSException(2001); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + public function getCommand() { |
|
197 | + return $this->_command; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Sets the command |
|
202 | + * |
|
203 | + * @param string command |
|
204 | + * |
|
205 | + * @throws PENSException with code 2002 if invalid |
|
206 | + */ |
|
207 | + protected function setCommand($command) { |
|
208 | + if(in_array($command, PENSConfig::$allowed_commands)) { |
|
209 | + $this->_command = $command; |
|
210 | + } else { |
|
211 | + throw new PENSException(2002); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + public function getPackageType() { |
|
216 | + return $this->_package_type; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Sets the package type |
|
221 | + * |
|
222 | + * @param string package type |
|
223 | + * |
|
224 | + * @throws PENSException with code 2003 if invalid |
|
225 | + */ |
|
226 | + public function setPackageType($package_type) { |
|
227 | + if(in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
228 | + $this->_package_type = $package_type; |
|
229 | + } else { |
|
230 | + throw new PENSException(2003); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + public function getPackageTypeVersion() { |
|
235 | + return $this->_package_type_version; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Sets the package type version |
|
240 | + * |
|
241 | + * @param string package type version |
|
242 | + * |
|
243 | + * @throws PENSException with code 2004 if invalid |
|
244 | + */ |
|
245 | + public function setPackageTypeVersion($package_type_version) { |
|
246 | + if(empty($package_type_version)) { |
|
247 | + throw new PENSException(2004); |
|
248 | + } else { |
|
249 | + $this->_package_type_version = $package_type_version; |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + public function getPackageFormat() { |
|
254 | + return $this->_package_format; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Sets the package format |
|
259 | + * |
|
260 | + * @param string package format |
|
261 | + * |
|
262 | + * @throws PENSException with code 2005 if invalid |
|
263 | + */ |
|
264 | + public function setPackageFormat($package_format) { |
|
265 | + if(in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
266 | + $this->_package_format = $package_format; |
|
267 | + } else { |
|
268 | + throw new PENSException(2005); |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + public function getPackageId() { |
|
273 | + return $this->_package_id; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Sets the package Id |
|
278 | + * |
|
279 | + * @param string package Id |
|
280 | + * |
|
281 | + * @throws PENSException with code 2007 if invalid |
|
282 | + */ |
|
283 | + public function setPackageId($package_id) { |
|
284 | + if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_id)) { |
|
285 | + $this->_package_id = $package_id; |
|
286 | + } else { |
|
287 | + throw new PENSException(2007); |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + public function getPackageUrl() { |
|
292 | + return $this->_package_url; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Sets the package url |
|
297 | + * |
|
298 | + * @param string package url |
|
299 | + * |
|
300 | + * @throws PENSException with code 2008 if invalid |
|
301 | + */ |
|
302 | + public function setPackageUrl($package_url) { |
|
303 | + if (preg_match('/'.ABSOLUTEURI_2396.'/', $package_url) && substr($package_url, -4) == ".".$this->_package_format) { |
|
304 | + $this->_package_url = $package_url; |
|
305 | + } else { |
|
306 | + throw new PENSException(2008); |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + public function getFilename() { |
|
311 | + return substr(strrchr($this->_package_url, "/"), 1); |
|
312 | + } |
|
313 | + |
|
314 | + public function getPackageUrlUserId() { |
|
315 | + return $this->_package_url_user_id; |
|
316 | + } |
|
317 | + |
|
318 | + public function setPackageUrlUserId($package_url_user_id) { |
|
319 | + if(!empty($package_url_user_id)) { |
|
320 | + $this->_package_url_user_id = $package_url_user_id; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + public function getPackageUrlAccount() { |
|
325 | + return $this->_package_url_account; |
|
326 | + } |
|
327 | + |
|
328 | + public function setPackageUrlAccount($package_url_account) { |
|
329 | + if(!empty($package_url_account)) { |
|
330 | + $this->_package_url_account = $package_url_account; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + public function getPackageUrlPassword() { |
|
335 | + return $this->_package_url_password; |
|
336 | + } |
|
337 | + |
|
338 | + public function setPackageUrlPassword($package_url_password) { |
|
339 | + if(!empty($package_url_password)) { |
|
340 | + $this->_package_url_password = $package_url_password; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + public function getPackageUrlExpiry() { |
|
345 | + return $this->_package_url_expiry; |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Sets the package url expiry and transforms it into a php DateTime object |
|
350 | + * |
|
351 | + * @param string package url expiry |
|
352 | + * |
|
353 | + * @throws PENSException with code 2009 if invalid |
|
354 | + * @todo Perform a better validation of the date |
|
355 | + */ |
|
356 | + public function setPackageUrlExpiry($package_url_expiry) { |
|
357 | + if(empty($package_url_expiry)) { |
|
358 | + throw new PENSException(2009); |
|
359 | + } else { |
|
360 | + try { |
|
361 | + $expiry = new DateTime($package_url_expiry, new DateTimeZone('UTC')); |
|
362 | + $this->_package_url_expiry = $expiry; |
|
363 | + } catch(Exception $e) { |
|
364 | + throw new PENSException(2009); |
|
365 | + } |
|
366 | + } |
|
367 | + } |
|
368 | + |
|
369 | + public function getClient() { |
|
370 | + return $this->_client; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Sets the client |
|
375 | + * |
|
376 | + * @param string client |
|
377 | + * |
|
378 | + * @throws PENSException with code 2010 if invalid |
|
379 | + */ |
|
380 | + public function setClient($client) { |
|
381 | + if(!empty($client)) { |
|
382 | + $this->_client = $client; |
|
383 | + } else { |
|
384 | + throw new PENSException(2010); |
|
385 | + } |
|
386 | + } |
|
387 | + |
|
388 | + public function getSystemUserId() { |
|
389 | + return $this->_system_user_id; |
|
390 | + } |
|
391 | + |
|
392 | + public function setSystemUserId($system_user_id) { |
|
393 | + if(!empty($system_user_id)) { |
|
394 | + $this->_system_user_id = $system_user_id; |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + public function getSystemPassword() { |
|
399 | + return $this->_system_password; |
|
400 | + } |
|
401 | + |
|
402 | + public function setSystemPassword($system_password) { |
|
403 | + if(!empty($system_password)) { |
|
404 | + $this->_system_password = $system_password; |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + public function getReceipt() { |
|
409 | + return $this->_receipt; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Sets the receipt url |
|
414 | + * |
|
415 | + * @param string receipt url |
|
416 | + * |
|
417 | + * @throws PENSException with code 2011 if invalid |
|
418 | + */ |
|
419 | + public function setReceipt($receipt) { |
|
420 | + if($this instanceof PENSRequestCollect) { |
|
421 | + if (preg_match('/'.ABSOLUTEURI_2396.'/', $receipt)) { |
|
422 | + $this->_receipt = $receipt; |
|
423 | + } else { |
|
424 | + throw new PENSException(2011); |
|
425 | + } |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + public function getAlerts() { |
|
430 | + return $this->_alerts; |
|
431 | + } |
|
432 | + |
|
433 | + public function setAlerts($alerts) { |
|
434 | + if(!empty($alerts)) { |
|
435 | + if(preg_match('/'.ABSOLUTEURI_2396.'/', $alerts)) { |
|
436 | + $this->_alerts = $alerts; |
|
437 | + } else { |
|
438 | + throw new PENSException(1201); |
|
439 | + } |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + public function getVendorData() { |
|
444 | + return $this->_vendor_data; |
|
445 | + } |
|
446 | + |
|
447 | + public function setVendorData($vendor_data) { |
|
448 | + if(!empty($vendor_data)) { |
|
449 | + $this->_vendor_data = $vendor_data; |
|
450 | + } |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Returns an associative that contains all the fields needed to send a |
|
455 | + * receipt or an alert to the client |
|
456 | + * |
|
457 | + * @return array Associative array |
|
458 | + */ |
|
459 | + protected function getSendReceiptAlertArray() { |
|
460 | + return array("pens-version" => $this->getPensVersion(), |
|
461 | + "package-type" => $this->getPackageType(), |
|
462 | + "package-type-version" => $this->getPackageTypeVersion(), |
|
463 | + "package-format" => $this->getPackageFormat(), |
|
464 | + "package-id" => $this->getPackageId(), |
|
465 | + "package-url" => $this->getPackageUrl(), |
|
466 | + "package-url-expiry" => $this->getPackageUrlExpiry()->format(DateTime::ISO8601), |
|
467 | + "client" => $this->getClient()); |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Returns an associative that contains all the fields needed to send a |
|
472 | + * receipt to the client |
|
473 | + * |
|
474 | + * @return array Associative array |
|
475 | + */ |
|
476 | + public function getSendReceiptArray() { |
|
477 | + $receipt = $this->getSendReceiptAlertArray(); |
|
478 | + $receipt["command"] = "receipt"; |
|
479 | + return $receipt; |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Returns an associative that contains all the fields needed to send an |
|
484 | + * alert to the client |
|
485 | + * |
|
486 | + * @return array Associative array |
|
487 | + */ |
|
488 | + public function getSendAlertArray() { |
|
489 | + $alert = $this->getSendReceiptAlertArray(); |
|
490 | + $alert["command"] = "alert"; |
|
491 | + return $alert; |
|
492 | + } |
|
493 | 493 | |
494 | 494 | |
495 | 495 | } |
@@ -39,137 +39,137 @@ |
||
39 | 39 | * @author Guillaume Viguier-Just <[email protected]> |
40 | 40 | * @licence http://www.gnu.org/licenses/gpl.txt |
41 | 41 | */ |
42 | - class PENSResponse extends PENSMessage { |
|
43 | - /** |
|
44 | - * Error code |
|
45 | - * @var int |
|
46 | - */ |
|
47 | - protected $_error = null; |
|
42 | + class PENSResponse extends PENSMessage { |
|
43 | + /** |
|
44 | + * Error code |
|
45 | + * @var int |
|
46 | + */ |
|
47 | + protected $_error = null; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Descriptive text of the error |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - protected $_error_text = null; |
|
49 | + /** |
|
50 | + * Descriptive text of the error |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + protected $_error_text = null; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Data linked to the error |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $_pens_data = null; |
|
55 | + /** |
|
56 | + * Data linked to the error |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $_pens_data = null; |
|
60 | 60 | |
61 | - /** |
|
62 | - * Version |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - protected $_pens_version = null; |
|
61 | + /** |
|
62 | + * Version |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + protected $_pens_version = null; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Constructor |
|
69 | - * |
|
70 | - * @param mixed Can be a PENSException or an error code or a string representing an HTTP response |
|
71 | - * @param string error text |
|
72 | - * @param string PENS data |
|
73 | - */ |
|
74 | - public function __construct($error, $error_text = null, $pens_data = null) { |
|
75 | - $this->_pens_version = PENSConfig::$version; |
|
76 | - if($error instanceof PENSException) { |
|
77 | - $this->_error = $error->getCode(); |
|
78 | - $this->_error_text = $error->getMessage(); |
|
79 | - } else if(is_string($error)){ |
|
80 | - // Parse the string |
|
81 | - $this->parseResponse($error); |
|
82 | - } else if(is_array($error)) { |
|
83 | - // Try to build from array |
|
84 | - $this->_error = $error["error"]; |
|
85 | - $this->_error_text = $error["error-text"]; |
|
86 | - $this->_pens_data = $error["pens-data"]; |
|
87 | - } else { |
|
88 | - $this->_error = $error; |
|
89 | - $this->_error_text = $error_text; |
|
90 | - $this->_pens_data = $pens_data; |
|
91 | - } |
|
67 | + /** |
|
68 | + * Constructor |
|
69 | + * |
|
70 | + * @param mixed Can be a PENSException or an error code or a string representing an HTTP response |
|
71 | + * @param string error text |
|
72 | + * @param string PENS data |
|
73 | + */ |
|
74 | + public function __construct($error, $error_text = null, $pens_data = null) { |
|
75 | + $this->_pens_version = PENSConfig::$version; |
|
76 | + if($error instanceof PENSException) { |
|
77 | + $this->_error = $error->getCode(); |
|
78 | + $this->_error_text = $error->getMessage(); |
|
79 | + } else if(is_string($error)){ |
|
80 | + // Parse the string |
|
81 | + $this->parseResponse($error); |
|
82 | + } else if(is_array($error)) { |
|
83 | + // Try to build from array |
|
84 | + $this->_error = $error["error"]; |
|
85 | + $this->_error_text = $error["error-text"]; |
|
86 | + $this->_pens_data = $error["pens-data"]; |
|
87 | + } else { |
|
88 | + $this->_error = $error; |
|
89 | + $this->_error_text = $error_text; |
|
90 | + $this->_pens_data = $pens_data; |
|
91 | + } |
|
92 | 92 | |
93 | - } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Parses an HTTP response and assigns the attributes of the object |
|
97 | - * |
|
98 | - * @param string HTTP response |
|
99 | - */ |
|
100 | - protected function parseResponse($response) { |
|
101 | - $lines = explode(PENSConfig::$eol, $response); |
|
102 | - $i = 1; |
|
103 | - foreach($lines as $line) { |
|
104 | - if($i < 5) { |
|
105 | - $pair = explode("=", $line); |
|
106 | - if($pair[0] == "error") { |
|
107 | - $this->_error = intval($pair[1]); |
|
108 | - } else if($pair[0] == "error-text") { |
|
109 | - $this->_error_text = $pair[1]; |
|
110 | - } else if($pair[0] == "version") { |
|
111 | - $this->_pens_version = $pair[1]; |
|
112 | - } else if($pair[0] == "pens-data") { |
|
113 | - if(!empty($pair[1])) { |
|
114 | - $this->_pens_data = $pair[1].PENSConfig::$eol; |
|
115 | - } |
|
116 | - } |
|
117 | - } else { |
|
118 | - if(!empty($line)) { |
|
119 | - $this->_pens_data .= $line.PENSConfig::$eol; |
|
120 | - } |
|
121 | - } |
|
122 | - $i++; |
|
123 | - } |
|
124 | - } |
|
95 | + /** |
|
96 | + * Parses an HTTP response and assigns the attributes of the object |
|
97 | + * |
|
98 | + * @param string HTTP response |
|
99 | + */ |
|
100 | + protected function parseResponse($response) { |
|
101 | + $lines = explode(PENSConfig::$eol, $response); |
|
102 | + $i = 1; |
|
103 | + foreach($lines as $line) { |
|
104 | + if($i < 5) { |
|
105 | + $pair = explode("=", $line); |
|
106 | + if($pair[0] == "error") { |
|
107 | + $this->_error = intval($pair[1]); |
|
108 | + } else if($pair[0] == "error-text") { |
|
109 | + $this->_error_text = $pair[1]; |
|
110 | + } else if($pair[0] == "version") { |
|
111 | + $this->_pens_version = $pair[1]; |
|
112 | + } else if($pair[0] == "pens-data") { |
|
113 | + if(!empty($pair[1])) { |
|
114 | + $this->_pens_data = $pair[1].PENSConfig::$eol; |
|
115 | + } |
|
116 | + } |
|
117 | + } else { |
|
118 | + if(!empty($line)) { |
|
119 | + $this->_pens_data .= $line.PENSConfig::$eol; |
|
120 | + } |
|
121 | + } |
|
122 | + $i++; |
|
123 | + } |
|
124 | + } |
|
125 | 125 | |
126 | - public function getError() { |
|
127 | - return $this->_error; |
|
128 | - } |
|
126 | + public function getError() { |
|
127 | + return $this->_error; |
|
128 | + } |
|
129 | 129 | |
130 | - public function getErrorText() { |
|
131 | - return $this->_error_text; |
|
132 | - } |
|
130 | + public function getErrorText() { |
|
131 | + return $this->_error_text; |
|
132 | + } |
|
133 | 133 | |
134 | - public function getPensData() { |
|
135 | - return $this->_pens_data; |
|
136 | - } |
|
134 | + public function getPensData() { |
|
135 | + return $this->_pens_data; |
|
136 | + } |
|
137 | 137 | |
138 | - public function getVersion() { |
|
139 | - return $this->_pens_version; |
|
140 | - } |
|
138 | + public function getVersion() { |
|
139 | + return $this->_pens_version; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Sends the response content through HTTP headers |
|
144 | - */ |
|
145 | - public function send() { |
|
146 | - header("Content-Type: text/plain"); |
|
147 | - print $this; |
|
148 | - } |
|
142 | + /** |
|
143 | + * Sends the response content through HTTP headers |
|
144 | + */ |
|
145 | + public function send() { |
|
146 | + header("Content-Type: text/plain"); |
|
147 | + print $this; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Returns an associative array of the response |
|
152 | - * |
|
153 | - * @return array Associative array |
|
154 | - */ |
|
155 | - public function getArray() { |
|
156 | - return array("error" => $this->_error, |
|
157 | - "error-text" => $this->_error_text, |
|
158 | - "version" => PENSConfig::$version, |
|
159 | - "pens-data" => $this->_pens_data); |
|
160 | - } |
|
150 | + /** |
|
151 | + * Returns an associative array of the response |
|
152 | + * |
|
153 | + * @return array Associative array |
|
154 | + */ |
|
155 | + public function getArray() { |
|
156 | + return array("error" => $this->_error, |
|
157 | + "error-text" => $this->_error_text, |
|
158 | + "version" => PENSConfig::$version, |
|
159 | + "pens-data" => $this->_pens_data); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Transforms the object into a string |
|
164 | - */ |
|
165 | - public function __toString() { |
|
166 | - $eol = PENSConfig::$eol; |
|
167 | - $return = "error=".$this->_error.$eol; |
|
168 | - $return .= "error-text=".$this->_error_text.$eol; |
|
169 | - $return .= "version=".PENSConfig::$version.$eol; |
|
170 | - $return .= "pens-data=".$this->_pens_data.$eol; |
|
171 | - return $return; |
|
172 | - } |
|
162 | + /** |
|
163 | + * Transforms the object into a string |
|
164 | + */ |
|
165 | + public function __toString() { |
|
166 | + $eol = PENSConfig::$eol; |
|
167 | + $return = "error=".$this->_error.$eol; |
|
168 | + $return .= "error-text=".$this->_error_text.$eol; |
|
169 | + $return .= "version=".PENSConfig::$version.$eol; |
|
170 | + $return .= "pens-data=".$this->_pens_data.$eol; |
|
171 | + return $return; |
|
172 | + } |
|
173 | 173 | |
174 | - } |
|
174 | + } |
|
175 | 175 |
@@ -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 | } |
@@ -26,9 +26,9 @@ |
||
26 | 26 | require_once __DIR__ . '/pens.php'; |
27 | 27 | |
28 | 28 | class MyRequestHandler extends PENSRequestHandler { |
29 | - public function processRequest($request, $response) { |
|
30 | - // Do the processing of the alert or the receipt here |
|
31 | - } |
|
29 | + public function processRequest($request, $response) { |
|
30 | + // Do the processing of the alert or the receipt here |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $handler = new MyRequestHandler(); |
@@ -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 MyRequestHandler extends PENSRequestHandler { |
29 | 29 | public function processRequest($request, $response) { |
@@ -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'; |
@@ -26,9 +26,9 @@ |
||
26 | 26 | require_once __DIR__ . '/pens.php'; |
27 | 27 | |
28 | 28 | class MyPackageHandler extends PENSPackageHandler { |
29 | - public function processPackage($request, $path_to_package) { |
|
30 | - // Do the package processing here |
|
31 | - } |
|
29 | + public function processPackage($request, $path_to_package) { |
|
30 | + // Do the package processing here |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $handler = new MyPackageHandler(); |
@@ -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) { |
@@ -44,25 +44,25 @@ |
||
44 | 44 | */ |
45 | 45 | class TestPENSResponse extends UnitTestCase { |
46 | 46 | |
47 | - public function testCreationFromPENSException() { |
|
48 | - $object = new PENSResponse(new PENSException(1101)); |
|
49 | - $this->assertEqual($object->getError(), 1101); |
|
50 | - $this->assertNotNull($object->getErrorText()); |
|
51 | - } |
|
47 | + public function testCreationFromPENSException() { |
|
48 | + $object = new PENSResponse(new PENSException(1101)); |
|
49 | + $this->assertEqual($object->getError(), 1101); |
|
50 | + $this->assertNotNull($object->getErrorText()); |
|
51 | + } |
|
52 | 52 | |
53 | - public function testCreationFromArguments() { |
|
54 | - $object = new PENSResponse(0, "collect command received and understood"); |
|
55 | - $this->assertIdentical($object->getError(), 0); |
|
56 | - $this->assertEqual($object->getErrorText(), "collect command received and understood"); |
|
57 | - } |
|
53 | + public function testCreationFromArguments() { |
|
54 | + $object = new PENSResponse(0, "collect command received and understood"); |
|
55 | + $this->assertIdentical($object->getError(), 0); |
|
56 | + $this->assertEqual($object->getErrorText(), "collect command received and understood"); |
|
57 | + } |
|
58 | 58 | |
59 | - public function testCreationFromHTTPResponse() { |
|
60 | - $eol = PENSConfig::$eol; |
|
61 | - $response = "error=1101".$eol."error-text=unable to parse PENS command".$eol."version=1.0.0".$eol."pens-data=".$eol; |
|
62 | - $object = new PENSResponse($response); |
|
63 | - $this->assertIdentical($object->getError(), 1101); |
|
64 | - $this->assertIdentical($object->getErrorText(), "unable to parse PENS command"); |
|
65 | - $this->assertIdentical($object->getVersion(), "1.0.0"); |
|
66 | - $this->assertNull($object->getPensData()); |
|
67 | - } |
|
59 | + public function testCreationFromHTTPResponse() { |
|
60 | + $eol = PENSConfig::$eol; |
|
61 | + $response = "error=1101".$eol."error-text=unable to parse PENS command".$eol."version=1.0.0".$eol."pens-data=".$eol; |
|
62 | + $object = new PENSResponse($response); |
|
63 | + $this->assertIdentical($object->getError(), 1101); |
|
64 | + $this->assertIdentical($object->getErrorText(), "unable to parse PENS command"); |
|
65 | + $this->assertIdentical($object->getVersion(), "1.0.0"); |
|
66 | + $this->assertNull($object->getPensData()); |
|
67 | + } |
|
68 | 68 | } |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | require_once(dirname(__FILE__)."/../pens.php"); |
34 | 34 | |
35 | 35 | class MyPackageHandler extends PENSPackageHandler { |
36 | - public function processPackage($request, $path_to_package) { |
|
37 | - } |
|
36 | + public function processPackage($request, $path_to_package) { |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -49,39 +49,39 @@ discard block |
||
49 | 49 | */ |
50 | 50 | class TestPENSPackageHandler extends UnitTestCase { |
51 | 51 | |
52 | - public function testSupportedPackageTypesInvalid() { |
|
53 | - $object = new MyPackageHandler(); |
|
54 | - $object->setSupportedPackageTypes("testing"); |
|
55 | - $this->assertEqual($object->getSupportedPackageTypes(), null); |
|
56 | - } |
|
52 | + public function testSupportedPackageTypesInvalid() { |
|
53 | + $object = new MyPackageHandler(); |
|
54 | + $object->setSupportedPackageTypes("testing"); |
|
55 | + $this->assertEqual($object->getSupportedPackageTypes(), null); |
|
56 | + } |
|
57 | 57 | |
58 | - public function testSupportedPackageTypesInvalid2() { |
|
59 | - $object = new MyPackageHandler(); |
|
60 | - $object->setSupportedPackageTypes(array("aicc-pkg", "testing")); |
|
61 | - $this->assertEqual($object->getSupportedPackageTypes(), array("aicc-pkg")); |
|
62 | - } |
|
58 | + public function testSupportedPackageTypesInvalid2() { |
|
59 | + $object = new MyPackageHandler(); |
|
60 | + $object->setSupportedPackageTypes(array("aicc-pkg", "testing")); |
|
61 | + $this->assertEqual($object->getSupportedPackageTypes(), array("aicc-pkg")); |
|
62 | + } |
|
63 | 63 | |
64 | - public function testSupportedPackageTypesValid() { |
|
65 | - $object = new MyPackageHandler(); |
|
66 | - $object->setSupportedPackageTypes(array("aicc-pkg", "lms-qti")); |
|
67 | - $this->assertEqual($object->getSupportedPackageTypes(), array("aicc-pkg", "lms-qti")); |
|
68 | - } |
|
64 | + public function testSupportedPackageTypesValid() { |
|
65 | + $object = new MyPackageHandler(); |
|
66 | + $object->setSupportedPackageTypes(array("aicc-pkg", "lms-qti")); |
|
67 | + $this->assertEqual($object->getSupportedPackageTypes(), array("aicc-pkg", "lms-qti")); |
|
68 | + } |
|
69 | 69 | |
70 | - public function testSupportedPackageFormatsInvalid() { |
|
71 | - $object = new MyPackageHandler(); |
|
72 | - $object->setSupportedPackageFormats("testing"); |
|
73 | - $this->assertEqual($object->getSupportedPackageFormats(), null); |
|
74 | - } |
|
70 | + public function testSupportedPackageFormatsInvalid() { |
|
71 | + $object = new MyPackageHandler(); |
|
72 | + $object->setSupportedPackageFormats("testing"); |
|
73 | + $this->assertEqual($object->getSupportedPackageFormats(), null); |
|
74 | + } |
|
75 | 75 | |
76 | - public function testSupportedPackageFormatsInvalid2() { |
|
77 | - $object = new MyPackageHandler(); |
|
78 | - $object->setSupportedPackageFormats(array("zip", "testing")); |
|
79 | - $this->assertEqual($object->getSupportedPackageFormats(), array("zip")); |
|
80 | - } |
|
76 | + public function testSupportedPackageFormatsInvalid2() { |
|
77 | + $object = new MyPackageHandler(); |
|
78 | + $object->setSupportedPackageFormats(array("zip", "testing")); |
|
79 | + $this->assertEqual($object->getSupportedPackageFormats(), array("zip")); |
|
80 | + } |
|
81 | 81 | |
82 | - public function testSupportedPackageFormatsValid() { |
|
83 | - $object = new MyPackageHandler(); |
|
84 | - $object->setSupportedPackageFormats(array("zip", "jar")); |
|
85 | - $this->assertEqual($object->getSupportedPackageFormats(), array("zip", "jar")); |
|
86 | - } |
|
82 | + public function testSupportedPackageFormatsValid() { |
|
83 | + $object = new MyPackageHandler(); |
|
84 | + $object->setSupportedPackageFormats(array("zip", "jar")); |
|
85 | + $this->assertEqual($object->getSupportedPackageFormats(), array("zip", "jar")); |
|
86 | + } |
|
87 | 87 | } |