@@ -16,15 +16,15 @@ discard block |
||
| 16 | 16 | * along with php-pens. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * PENSClient |
|
| 21 | - * |
|
| 22 | - * Provides the PENSClient class |
|
| 23 | - * |
|
| 24 | - * @package PENS |
|
| 25 | - * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | - * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | - */ |
|
| 19 | + /** |
|
| 20 | + * PENSClient |
|
| 21 | + * |
|
| 22 | + * Provides the PENSClient class |
|
| 23 | + * |
|
| 24 | + * @package PENS |
|
| 25 | + * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | + * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | + */ |
|
| 28 | 28 | |
| 29 | 29 | require_once(dirname(__FILE__)."/pens_controller.php"); |
| 30 | 30 | require_once(dirname(__FILE__)."/pens_request_handler.php"); |
@@ -39,75 +39,75 @@ discard block |
||
| 39 | 39 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 40 | 40 | */ |
| 41 | 41 | class PENSClient extends PENSController { |
| 42 | - /** |
|
| 43 | - * Instance of the PENSClient |
|
| 44 | - * @var PENSServer |
|
| 45 | - */ |
|
| 46 | - private static $_instance; |
|
| 42 | + /** |
|
| 43 | + * Instance of the PENSClient |
|
| 44 | + * @var PENSServer |
|
| 45 | + */ |
|
| 46 | + private static $_instance; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Request handler |
|
| 50 | - * @var PENSRequestHandler |
|
| 51 | - */ |
|
| 52 | - protected $_request_handler = null; |
|
| 48 | + /** |
|
| 49 | + * Request handler |
|
| 50 | + * @var PENSRequestHandler |
|
| 51 | + */ |
|
| 52 | + protected $_request_handler = null; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Private constructor |
|
| 56 | - */ |
|
| 57 | - private function __construct() { |
|
| 58 | - } |
|
| 54 | + /** |
|
| 55 | + * Private constructor |
|
| 56 | + */ |
|
| 57 | + private function __construct() { |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Singleton method |
|
| 62 | - */ |
|
| 63 | - public static function singleton() { |
|
| 64 | - if(!isset(self::$_instance)) { |
|
| 65 | - $c = __CLASS__; |
|
| 66 | - self::$_instance = new $c; |
|
| 67 | - } |
|
| 68 | - return self::$_instance; |
|
| 69 | - } |
|
| 60 | + /** |
|
| 61 | + * Singleton method |
|
| 62 | + */ |
|
| 63 | + public static function singleton() { |
|
| 64 | + if(!isset(self::$_instance)) { |
|
| 65 | + $c = __CLASS__; |
|
| 66 | + self::$_instance = new $c; |
|
| 67 | + } |
|
| 68 | + return self::$_instance; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Prevent users to clone the instance |
|
| 73 | - */ |
|
| 74 | - public function __clone() { |
|
| 75 | - trigger_error('Clone is not allowed', E_USER_ERROR); |
|
| 76 | - } |
|
| 71 | + /** |
|
| 72 | + * Prevent users to clone the instance |
|
| 73 | + */ |
|
| 74 | + public function __clone() { |
|
| 75 | + trigger_error('Clone is not allowed', E_USER_ERROR); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function getRequestHandler() { |
|
| 79 | - return $this->_request_handler; |
|
| 80 | - } |
|
| 78 | + public function getRequestHandler() { |
|
| 79 | + return $this->_request_handler; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Sets the request handler. Does nothing if the argument is not an instance of PENSRequestHandler |
|
| 84 | - * |
|
| 85 | - * @param PENSRequestHandler Request handler |
|
| 86 | - */ |
|
| 87 | - public function setRequestHandler($request_handler) { |
|
| 88 | - if($request_handler instanceof PENSRequestHandler) { |
|
| 89 | - $this->_request_handler = $request_handler; |
|
| 90 | - } |
|
| 91 | - } |
|
| 82 | + /** |
|
| 83 | + * Sets the request handler. Does nothing if the argument is not an instance of PENSRequestHandler |
|
| 84 | + * |
|
| 85 | + * @param PENSRequestHandler Request handler |
|
| 86 | + */ |
|
| 87 | + public function setRequestHandler($request_handler) { |
|
| 88 | + if($request_handler instanceof PENSRequestHandler) { |
|
| 89 | + $this->_request_handler = $request_handler; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Receives a request, calls the handler and displays the response |
|
| 95 | - */ |
|
| 96 | - public function receiveRequest() { |
|
| 97 | - $request = null; |
|
| 98 | - try { |
|
| 99 | - $request = $this->parseRequest(); |
|
| 100 | - $command = $request->getCommand(); |
|
| 101 | - if($command == "alert" || $command == "receipt") { |
|
| 102 | - if(!is_null($this->_request_handler)) { |
|
| 103 | - // Call the handler |
|
| 104 | - $this->_request_handler->processRequest($request, new PENSResponse($_REQUEST)); |
|
| 105 | - } |
|
| 106 | - $this->sendResponse(new PENSResponse(0, $command." received and understood")); |
|
| 107 | - } |
|
| 108 | - } catch(PENSException $e) { |
|
| 109 | - // If we could not parse the request, send the error |
|
| 110 | - $this->sendResponse(new PENSResponse($e)); |
|
| 111 | - } |
|
| 112 | - } |
|
| 93 | + /** |
|
| 94 | + * Receives a request, calls the handler and displays the response |
|
| 95 | + */ |
|
| 96 | + public function receiveRequest() { |
|
| 97 | + $request = null; |
|
| 98 | + try { |
|
| 99 | + $request = $this->parseRequest(); |
|
| 100 | + $command = $request->getCommand(); |
|
| 101 | + if($command == "alert" || $command == "receipt") { |
|
| 102 | + if(!is_null($this->_request_handler)) { |
|
| 103 | + // Call the handler |
|
| 104 | + $this->_request_handler->processRequest($request, new PENSResponse($_REQUEST)); |
|
| 105 | + } |
|
| 106 | + $this->sendResponse(new PENSResponse(0, $command." received and understood")); |
|
| 107 | + } |
|
| 108 | + } catch(PENSException $e) { |
|
| 109 | + // If we could not parse the request, send the error |
|
| 110 | + $this->sendResponse(new PENSResponse($e)); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | 113 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * Singleton method |
| 62 | 62 | */ |
| 63 | 63 | public static function singleton() { |
| 64 | - if(!isset(self::$_instance)) { |
|
| 64 | + if (!isset(self::$_instance)) { |
|
| 65 | 65 | $c = __CLASS__; |
| 66 | 66 | self::$_instance = new $c; |
| 67 | 67 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param PENSRequestHandler Request handler |
| 86 | 86 | */ |
| 87 | 87 | public function setRequestHandler($request_handler) { |
| 88 | - if($request_handler instanceof PENSRequestHandler) { |
|
| 88 | + if ($request_handler instanceof PENSRequestHandler) { |
|
| 89 | 89 | $this->_request_handler = $request_handler; |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | try { |
| 99 | 99 | $request = $this->parseRequest(); |
| 100 | 100 | $command = $request->getCommand(); |
| 101 | - if($command == "alert" || $command == "receipt") { |
|
| 102 | - if(!is_null($this->_request_handler)) { |
|
| 101 | + if ($command == "alert" || $command == "receipt") { |
|
| 102 | + if (!is_null($this->_request_handler)) { |
|
| 103 | 103 | // Call the handler |
| 104 | 104 | $this->_request_handler->processRequest($request, new PENSResponse($_REQUEST)); |
| 105 | 105 | } |
| 106 | 106 | $this->sendResponse(new PENSResponse(0, $command." received and understood")); |
| 107 | 107 | } |
| 108 | - } catch(PENSException $e) { |
|
| 108 | + } catch (PENSException $e) { |
|
| 109 | 109 | // If we could not parse the request, send the error |
| 110 | 110 | $this->sendResponse(new PENSResponse($e)); |
| 111 | 111 | } |
@@ -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 | } |
@@ -37,62 +37,62 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class PENSException extends Exception { |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Array that provides an association between exception codes and messages |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - protected static $_code_to_messages = array( |
|
| 45 | - 1101 => "Unable to parse PENS command", |
|
| 46 | - 1201 => "Attempt to pass an invalid argument", |
|
| 47 | - 1301 => "Unable to retrieve package", |
|
| 48 | - 1302 => "Unable to retrieve package via HTTPS", |
|
| 49 | - 1304 => "Unable to retrieve package via FTP", |
|
| 50 | - 1306 => "Unable to retrieve package via FTPS", |
|
| 51 | - 1310 => "Unable to retrieve package at specified URL due to error in URL or lack of response from URL", |
|
| 52 | - 1312 => "Unable to retrieve package at specified URL due to error with access credential for package URL", |
|
| 53 | - 1320 => "Expiration date is non-null and in an improper format", |
|
| 54 | - 1322 => "Current time indicates expiry date has passed", |
|
| 55 | - 1420 => "PENS version not supported", |
|
| 56 | - 1421 => "Command not supported", |
|
| 57 | - 1430 => "Package type not supported", |
|
| 58 | - // The following error code is not specified in the PENS specification and was added in this implementation |
|
| 59 | - 1431 => "Package format not supported", |
|
| 60 | - 1432 => "Internal package error", |
|
| 61 | - 1440 => "Insufficient host space/storage available", |
|
| 62 | - 1500 => "Unable to communicate with provided acknowledgement URL", |
|
| 63 | - 1510 => "Unsupported acknowledgement protocol", |
|
| 64 | - 1520 => "Unsupported alert protocol", |
|
| 65 | - 2001 => "PENS version invalid or not specified", |
|
| 66 | - 2002 => "PENS command invalid or not specified", |
|
| 67 | - 2003 => "package-type invalid or not specified", |
|
| 68 | - 2004 => "package-type-version invalid or not specified", |
|
| 69 | - 2005 => "package-format invalid or not specified", |
|
| 70 | - 2007 => "package-id invalid or not specified", |
|
| 71 | - 2008 => "package-url invalid or not specified", |
|
| 72 | - 2009 => "package-url-expiry date invalid or not specified", |
|
| 73 | - 2010 => "client submitting package invalid or not specified", |
|
| 74 | - 2011 => "receipt url invalid or not specified" |
|
| 75 | - ); |
|
| 40 | + /** |
|
| 41 | + * Array that provides an association between exception codes and messages |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + protected static $_code_to_messages = array( |
|
| 45 | + 1101 => "Unable to parse PENS command", |
|
| 46 | + 1201 => "Attempt to pass an invalid argument", |
|
| 47 | + 1301 => "Unable to retrieve package", |
|
| 48 | + 1302 => "Unable to retrieve package via HTTPS", |
|
| 49 | + 1304 => "Unable to retrieve package via FTP", |
|
| 50 | + 1306 => "Unable to retrieve package via FTPS", |
|
| 51 | + 1310 => "Unable to retrieve package at specified URL due to error in URL or lack of response from URL", |
|
| 52 | + 1312 => "Unable to retrieve package at specified URL due to error with access credential for package URL", |
|
| 53 | + 1320 => "Expiration date is non-null and in an improper format", |
|
| 54 | + 1322 => "Current time indicates expiry date has passed", |
|
| 55 | + 1420 => "PENS version not supported", |
|
| 56 | + 1421 => "Command not supported", |
|
| 57 | + 1430 => "Package type not supported", |
|
| 58 | + // The following error code is not specified in the PENS specification and was added in this implementation |
|
| 59 | + 1431 => "Package format not supported", |
|
| 60 | + 1432 => "Internal package error", |
|
| 61 | + 1440 => "Insufficient host space/storage available", |
|
| 62 | + 1500 => "Unable to communicate with provided acknowledgement URL", |
|
| 63 | + 1510 => "Unsupported acknowledgement protocol", |
|
| 64 | + 1520 => "Unsupported alert protocol", |
|
| 65 | + 2001 => "PENS version invalid or not specified", |
|
| 66 | + 2002 => "PENS command invalid or not specified", |
|
| 67 | + 2003 => "package-type invalid or not specified", |
|
| 68 | + 2004 => "package-type-version invalid or not specified", |
|
| 69 | + 2005 => "package-format invalid or not specified", |
|
| 70 | + 2007 => "package-id invalid or not specified", |
|
| 71 | + 2008 => "package-url invalid or not specified", |
|
| 72 | + 2009 => "package-url-expiry date invalid or not specified", |
|
| 73 | + 2010 => "client submitting package invalid or not specified", |
|
| 74 | + 2011 => "receipt url invalid or not specified" |
|
| 75 | + ); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Redefines the constructor so that code is the first argument |
|
| 79 | - * |
|
| 80 | - * @param int Exception code |
|
| 81 | - * @param string Message to display |
|
| 82 | - * @return PENSException Exception created |
|
| 83 | - */ |
|
| 84 | - public function __construct($code, $message = null) { |
|
| 85 | - parent::__construct($message, $code); |
|
| 86 | - $this->setMessageBasedOnCode(); |
|
| 87 | - } |
|
| 77 | + /** |
|
| 78 | + * Redefines the constructor so that code is the first argument |
|
| 79 | + * |
|
| 80 | + * @param int Exception code |
|
| 81 | + * @param string Message to display |
|
| 82 | + * @return PENSException Exception created |
|
| 83 | + */ |
|
| 84 | + public function __construct($code, $message = null) { |
|
| 85 | + parent::__construct($message, $code); |
|
| 86 | + $this->setMessageBasedOnCode(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Sets the message based on the code |
|
| 91 | - */ |
|
| 92 | - protected function setMessageBasedOnCode() { |
|
| 93 | - if(empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
| 94 | - $this->message = self::$_code_to_messages[$this->code]; |
|
| 95 | - } |
|
| 96 | - } |
|
| 89 | + /** |
|
| 90 | + * Sets the message based on the code |
|
| 91 | + */ |
|
| 92 | + protected function setMessageBasedOnCode() { |
|
| 93 | + if(empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
| 94 | + $this->message = self::$_code_to_messages[$this->code]; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | } |
@@ -40,9 +40,9 @@ |
||
| 40 | 40 | |
| 41 | 41 | class PENSRequestCollect extends PENSRequest { |
| 42 | 42 | |
| 43 | - public function __construct($arguments) { |
|
| 44 | - parent::__construct($arguments); |
|
| 45 | - $this->setCommand("collect"); |
|
| 46 | - } |
|
| 43 | + public function __construct($arguments) { |
|
| 44 | + parent::__construct($arguments); |
|
| 45 | + $this->setCommand("collect"); |
|
| 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 |
@@ -16,15 +16,15 @@ discard block |
||
| 16 | 16 | * along with php-pens. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * PENSPackageHandler |
|
| 21 | - * |
|
| 22 | - * Provides the PENSPackageHandler abstract class |
|
| 23 | - * |
|
| 24 | - * @package PENS |
|
| 25 | - * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | - * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | - */ |
|
| 19 | + /** |
|
| 20 | + * PENSPackageHandler |
|
| 21 | + * |
|
| 22 | + * Provides the PENSPackageHandler abstract class |
|
| 23 | + * |
|
| 24 | + * @package PENS |
|
| 25 | + * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | + * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | + */ |
|
| 28 | 28 | |
| 29 | 29 | require_once(dirname(__FILE__)."/pens_config.php"); |
| 30 | 30 | |
@@ -39,76 +39,76 @@ discard block |
||
| 39 | 39 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 40 | 40 | */ |
| 41 | 41 | abstract class PENSPackageHandler { |
| 42 | - /** |
|
| 43 | - * Array of supported package types for this handler. Set by default to PENSConfig::$allowed_package_types |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $_supported_package_types = null; |
|
| 42 | + /** |
|
| 43 | + * Array of supported package types for this handler. Set by default to PENSConfig::$allowed_package_types |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $_supported_package_types = null; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Array of supported package formats for this handler. Set by default to PENSConfig::$allowed_package_formats |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - protected $_supported_package_formats = null; |
|
| 48 | + /** |
|
| 49 | + * Array of supported package formats for this handler. Set by default to PENSConfig::$allowed_package_formats |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + protected $_supported_package_formats = null; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Constructor. Sets the default values of supported_package_types and supported_package_formats |
|
| 56 | - */ |
|
| 57 | - public function __construct() { |
|
| 58 | - $this->_supported_package_types = PENSConfig::$allowed_package_types; |
|
| 59 | - $this->_supported_package_formats = PENSConfig::$allowed_package_formats; |
|
| 60 | - } |
|
| 54 | + /** |
|
| 55 | + * Constructor. Sets the default values of supported_package_types and supported_package_formats |
|
| 56 | + */ |
|
| 57 | + public function __construct() { |
|
| 58 | + $this->_supported_package_types = PENSConfig::$allowed_package_types; |
|
| 59 | + $this->_supported_package_formats = PENSConfig::$allowed_package_formats; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function getSupportedPackageTypes() { |
|
| 63 | - return $this->_supported_package_types; |
|
| 64 | - } |
|
| 62 | + public function getSupportedPackageTypes() { |
|
| 63 | + return $this->_supported_package_types; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Sets the supported package types. All package types in the array provided as an argument |
|
| 68 | - * not present in PENSConfig::$allowed_package_types will be ignored. The supported_package_types |
|
| 69 | - * will be set to null if the argument given is not an array |
|
| 70 | - * |
|
| 71 | - * @param array Supported package types |
|
| 72 | - */ |
|
| 73 | - public function setSupportedPackageTypes($supported_package_types) { |
|
| 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)) { |
|
| 78 | - $this->_supported_package_types[] = $package_type; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 66 | + /** |
|
| 67 | + * Sets the supported package types. All package types in the array provided as an argument |
|
| 68 | + * not present in PENSConfig::$allowed_package_types will be ignored. The supported_package_types |
|
| 69 | + * will be set to null if the argument given is not an array |
|
| 70 | + * |
|
| 71 | + * @param array Supported package types |
|
| 72 | + */ |
|
| 73 | + public function setSupportedPackageTypes($supported_package_types) { |
|
| 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)) { |
|
| 78 | + $this->_supported_package_types[] = $package_type; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function getSupportedPackageFormats() { |
|
| 85 | - return $this->_supported_package_formats; |
|
| 86 | - } |
|
| 84 | + public function getSupportedPackageFormats() { |
|
| 85 | + return $this->_supported_package_formats; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Sets the supported package formats. All package types in the array provided as an argument |
|
| 90 | - * not present in PENSConfig::$allowed_package_formats will be ignored. The supported_package_formats |
|
| 91 | - * will be set to null if the argument given is not an array. |
|
| 92 | - * |
|
| 93 | - * @param array Supported package formats |
|
| 94 | - */ |
|
| 95 | - public function setSupportedPackageFormats($supported_package_formats) { |
|
| 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)) { |
|
| 100 | - $this->_supported_package_formats[] = $package_format; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 88 | + /** |
|
| 89 | + * Sets the supported package formats. All package types in the array provided as an argument |
|
| 90 | + * not present in PENSConfig::$allowed_package_formats will be ignored. The supported_package_formats |
|
| 91 | + * will be set to null if the argument given is not an array. |
|
| 92 | + * |
|
| 93 | + * @param array Supported package formats |
|
| 94 | + */ |
|
| 95 | + public function setSupportedPackageFormats($supported_package_formats) { |
|
| 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)) { |
|
| 100 | + $this->_supported_package_formats[] = $package_format; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Processes the package. Must be implemented by subclasses |
|
| 108 | - * |
|
| 109 | - * @param PENSRequestCollect Collect request sent by the client |
|
| 110 | - * @param string Path to the collected package on the hard drive |
|
| 111 | - */ |
|
| 112 | - abstract public function processPackage($request, $path_to_package); |
|
| 106 | + /** |
|
| 107 | + * Processes the package. Must be implemented by subclasses |
|
| 108 | + * |
|
| 109 | + * @param PENSRequestCollect Collect request sent by the client |
|
| 110 | + * @param string Path to the collected package on the hard drive |
|
| 111 | + */ |
|
| 112 | + abstract public function processPackage($request, $path_to_package); |
|
| 113 | 113 | |
| 114 | 114 | } |
@@ -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 | } |
@@ -16,15 +16,15 @@ discard block |
||
| 16 | 16 | * along with php-pens. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * PENSRequestHandler |
|
| 21 | - * |
|
| 22 | - * Provides the PENSRequestHandler abstract class |
|
| 23 | - * |
|
| 24 | - * @package PENS |
|
| 25 | - * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | - * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | - */ |
|
| 19 | + /** |
|
| 20 | + * PENSRequestHandler |
|
| 21 | + * |
|
| 22 | + * Provides the PENSRequestHandler abstract class |
|
| 23 | + * |
|
| 24 | + * @package PENS |
|
| 25 | + * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | + * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | + */ |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * PENSRequestHandler |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 38 | 38 | */ |
| 39 | 39 | abstract class PENSRequestHandler { |
| 40 | - /** |
|
| 41 | - * Processes the request. Must be implemented by subclasses |
|
| 42 | - * |
|
| 43 | - * @param PENSRequest Alert or Receipt request sent by the server |
|
| 44 | - * @param PENSResponse Response sent by the server (error, error-text etc...) |
|
| 45 | - */ |
|
| 46 | - abstract public function processRequest($request, $response); |
|
| 40 | + /** |
|
| 41 | + * Processes the request. Must be implemented by subclasses |
|
| 42 | + * |
|
| 43 | + * @param PENSRequest Alert or Receipt request sent by the server |
|
| 44 | + * @param PENSResponse Response sent by the server (error, error-text etc...) |
|
| 45 | + */ |
|
| 46 | + abstract public function processRequest($request, $response); |
|
| 47 | 47 | } |
| 48 | 48 | |
@@ -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 |
@@ -16,15 +16,15 @@ discard block |
||
| 16 | 16 | * along with php-pens. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * PENSServer |
|
| 21 | - * |
|
| 22 | - * Provides the PENSServer class |
|
| 23 | - * |
|
| 24 | - * @package PENS |
|
| 25 | - * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | - * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | - */ |
|
| 19 | + /** |
|
| 20 | + * PENSServer |
|
| 21 | + * |
|
| 22 | + * Provides the PENSServer class |
|
| 23 | + * |
|
| 24 | + * @package PENS |
|
| 25 | + * @author Guillaume Viguier-Just <[email protected]> |
|
| 26 | + * @licence http://www.gnu.org/licenses/gpl.txt |
|
| 27 | + */ |
|
| 28 | 28 | |
| 29 | 29 | require_once __DIR__ . '/pens_controller.php'; |
| 30 | 30 | require_once __DIR__ . '/pens_package_handler.php'; |
@@ -42,272 +42,272 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | class PENSServer extends PENSController { |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Instance of the PENSServer |
|
| 47 | - * @var PENSServer |
|
| 48 | - */ |
|
| 49 | - private static $_instance; |
|
| 45 | + /** |
|
| 46 | + * Instance of the PENSServer |
|
| 47 | + * @var PENSServer |
|
| 48 | + */ |
|
| 49 | + private static $_instance; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Package handler |
|
| 53 | - * @var PENSPackageHandler |
|
| 54 | - */ |
|
| 55 | - protected $_package_handler = null; |
|
| 51 | + /** |
|
| 52 | + * Package handler |
|
| 53 | + * @var PENSPackageHandler |
|
| 54 | + */ |
|
| 55 | + protected $_package_handler = null; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Private constructor |
|
| 59 | - */ |
|
| 60 | - private function __construct() { |
|
| 61 | - } |
|
| 57 | + /** |
|
| 58 | + * Private constructor |
|
| 59 | + */ |
|
| 60 | + private function __construct() { |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Singleton method |
|
| 65 | - */ |
|
| 66 | - public static function singleton() { |
|
| 67 | - if(!isset(self::$_instance)) { |
|
| 68 | - $c = __CLASS__; |
|
| 69 | - self::$_instance = new $c; |
|
| 70 | - } |
|
| 71 | - return self::$_instance; |
|
| 72 | - } |
|
| 63 | + /** |
|
| 64 | + * Singleton method |
|
| 65 | + */ |
|
| 66 | + public static function singleton() { |
|
| 67 | + if(!isset(self::$_instance)) { |
|
| 68 | + $c = __CLASS__; |
|
| 69 | + self::$_instance = new $c; |
|
| 70 | + } |
|
| 71 | + return self::$_instance; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Prevent users to clone the instance |
|
| 76 | - */ |
|
| 77 | - public function __clone() { |
|
| 78 | - trigger_error('Clone is not allowed', E_USER_ERROR); |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * Prevent users to clone the instance |
|
| 76 | + */ |
|
| 77 | + public function __clone() { |
|
| 78 | + trigger_error('Clone is not allowed', E_USER_ERROR); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - public function getPackageHandler() { |
|
| 82 | - return $this->_package_handler; |
|
| 83 | - } |
|
| 81 | + public function getPackageHandler() { |
|
| 82 | + return $this->_package_handler; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Sets the package handler. Does nothing if the argument is not an instance of PENSPackageHandler |
|
| 87 | - * |
|
| 88 | - * @param PENSPackageHandler Package handler |
|
| 89 | - */ |
|
| 90 | - public function setPackageHandler($package_handler) { |
|
| 91 | - if($package_handler instanceof PENSPackageHandler) { |
|
| 92 | - $this->_package_handler = $package_handler; |
|
| 93 | - } |
|
| 94 | - } |
|
| 85 | + /** |
|
| 86 | + * Sets the package handler. Does nothing if the argument is not an instance of PENSPackageHandler |
|
| 87 | + * |
|
| 88 | + * @param PENSPackageHandler Package handler |
|
| 89 | + */ |
|
| 90 | + public function setPackageHandler($package_handler) { |
|
| 91 | + if($package_handler instanceof PENSPackageHandler) { |
|
| 92 | + $this->_package_handler = $package_handler; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Receives a collect request and treats it |
|
| 98 | - */ |
|
| 99 | - public function receiveCollect() { |
|
| 100 | - $request = null; |
|
| 101 | - try { |
|
| 102 | - // First, try to parse the request |
|
| 103 | - $request = $this->parseRequest(); |
|
| 104 | - if($request->getCommand() == "collect") { |
|
| 105 | - if(isset($_REQUEST['process'])) { |
|
| 106 | - // Collect the package and process it |
|
| 107 | - $receipt = null; |
|
| 108 | - $path_to_package = null; |
|
| 109 | - try { |
|
| 110 | - // Collect the package |
|
| 111 | - $path_to_package = $this->collectPackage($request); |
|
| 112 | - $receipt = new PENSResponse(0, "package successfully collected"); |
|
| 113 | - } catch(PENSException $e) { |
|
| 114 | - $receipt = new PENSResponse($e); |
|
| 115 | - } |
|
| 116 | - // Send receipt |
|
| 117 | - $response = $this->sendReceipt($request, $receipt); |
|
| 118 | - if(!is_null($response) && !is_null($path_to_package)) { |
|
| 119 | - if($response->getError() === 0) { |
|
| 120 | - // Process package |
|
| 121 | - $this->processPackage($request, $path_to_package); |
|
| 122 | - } |
|
| 123 | - unlink($path_to_package); |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - // Then, send a success response to the client |
|
| 127 | - $this->sendResponse(new PENSResponse(0, "collect command received and understood")); |
|
| 128 | - // Send a request to process the package: fake multithreading |
|
| 129 | - $params = $_REQUEST; |
|
| 130 | - $params['process'] = 1; |
|
| 131 | - $scheme = "http"; |
|
| 132 | - if(!empty($_SERVER['HTTPS'])) { |
|
| 133 | - $scheme = "https"; |
|
| 134 | - } |
|
| 135 | - $ch = curl_init(); |
|
| 136 | - curl_setopt($ch, CURLOPT_URL, $scheme."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
| 137 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $params); |
|
| 138 | - curl_setopt($ch, CURLOPT_TIMEOUT, 1); |
|
| 139 | - curl_exec($ch); |
|
| 140 | - curl_close($ch); |
|
| 141 | - } |
|
| 142 | - } |
|
| 96 | + /** |
|
| 97 | + * Receives a collect request and treats it |
|
| 98 | + */ |
|
| 99 | + public function receiveCollect() { |
|
| 100 | + $request = null; |
|
| 101 | + try { |
|
| 102 | + // First, try to parse the request |
|
| 103 | + $request = $this->parseRequest(); |
|
| 104 | + if($request->getCommand() == "collect") { |
|
| 105 | + if(isset($_REQUEST['process'])) { |
|
| 106 | + // Collect the package and process it |
|
| 107 | + $receipt = null; |
|
| 108 | + $path_to_package = null; |
|
| 109 | + try { |
|
| 110 | + // Collect the package |
|
| 111 | + $path_to_package = $this->collectPackage($request); |
|
| 112 | + $receipt = new PENSResponse(0, "package successfully collected"); |
|
| 113 | + } catch(PENSException $e) { |
|
| 114 | + $receipt = new PENSResponse($e); |
|
| 115 | + } |
|
| 116 | + // Send receipt |
|
| 117 | + $response = $this->sendReceipt($request, $receipt); |
|
| 118 | + if(!is_null($response) && !is_null($path_to_package)) { |
|
| 119 | + if($response->getError() === 0) { |
|
| 120 | + // Process package |
|
| 121 | + $this->processPackage($request, $path_to_package); |
|
| 122 | + } |
|
| 123 | + unlink($path_to_package); |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + // Then, send a success response to the client |
|
| 127 | + $this->sendResponse(new PENSResponse(0, "collect command received and understood")); |
|
| 128 | + // Send a request to process the package: fake multithreading |
|
| 129 | + $params = $_REQUEST; |
|
| 130 | + $params['process'] = 1; |
|
| 131 | + $scheme = "http"; |
|
| 132 | + if(!empty($_SERVER['HTTPS'])) { |
|
| 133 | + $scheme = "https"; |
|
| 134 | + } |
|
| 135 | + $ch = curl_init(); |
|
| 136 | + curl_setopt($ch, CURLOPT_URL, $scheme."://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
| 137 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); |
|
| 138 | + curl_setopt($ch, CURLOPT_TIMEOUT, 1); |
|
| 139 | + curl_exec($ch); |
|
| 140 | + curl_close($ch); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - } catch(PENSException $e) { |
|
| 145 | - // If we could not parse the request, send the error back to the client |
|
| 146 | - $this->sendResponse(new PENSResponse($e)); |
|
| 147 | - } |
|
| 148 | - } |
|
| 144 | + } catch(PENSException $e) { |
|
| 145 | + // If we could not parse the request, send the error back to the client |
|
| 146 | + $this->sendResponse(new PENSResponse($e)); |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Collects the package onto the local server |
|
| 152 | - * |
|
| 153 | - * @param PENSRequest request |
|
| 154 | - * @return string Path to the package on the hard drive |
|
| 155 | - * @throws PENSException if an exception occured |
|
| 156 | - */ |
|
| 157 | - protected function collectPackage($request) { |
|
| 158 | - $supported_package_types = $this->_package_handler->getSupportedPackageTypes(); |
|
| 159 | - if(!in_array($request->getPackageType(), $supported_package_types)) { |
|
| 160 | - throw new PENSException(1430); |
|
| 161 | - } |
|
| 162 | - $supported_package_formats = $this->_package_handler->getSupportedPackageFormats(); |
|
| 163 | - if(!in_array($request->getPackageFormat(), $supported_package_formats)) { |
|
| 164 | - throw new PENSException(1431); |
|
| 165 | - } |
|
| 166 | - if(!$this->isExpiryDateValid($request->getPackageUrlExpiry())) { |
|
| 167 | - throw new PENSException(1322); |
|
| 168 | - } |
|
| 150 | + /** |
|
| 151 | + * Collects the package onto the local server |
|
| 152 | + * |
|
| 153 | + * @param PENSRequest request |
|
| 154 | + * @return string Path to the package on the hard drive |
|
| 155 | + * @throws PENSException if an exception occured |
|
| 156 | + */ |
|
| 157 | + protected function collectPackage($request) { |
|
| 158 | + $supported_package_types = $this->_package_handler->getSupportedPackageTypes(); |
|
| 159 | + if(!in_array($request->getPackageType(), $supported_package_types)) { |
|
| 160 | + throw new PENSException(1430); |
|
| 161 | + } |
|
| 162 | + $supported_package_formats = $this->_package_handler->getSupportedPackageFormats(); |
|
| 163 | + if(!in_array($request->getPackageFormat(), $supported_package_formats)) { |
|
| 164 | + throw new PENSException(1431); |
|
| 165 | + } |
|
| 166 | + if(!$this->isExpiryDateValid($request->getPackageUrlExpiry())) { |
|
| 167 | + throw new PENSException(1322); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - // Try to download the package in the temporary directory |
|
| 171 | - $tmp = null; |
|
| 172 | - if(function_exists("sys_get_temp_dir")) { |
|
| 173 | - $tmp = sys_get_temp_dir(); |
|
| 174 | - } else { |
|
| 175 | - $tmp = "/tmp"; |
|
| 176 | - } |
|
| 177 | - $path_to_file = $tmp."/".$request->getFilename(); |
|
| 178 | - $fp = fopen($path_to_file, 'w'); |
|
| 179 | - $ch = curl_init(); |
|
| 180 | - curl_setopt($ch, CURLOPT_URL, $request->getPackageUrl()); |
|
| 181 | - curl_setopt($ch, CURLOPT_HEADER, false); |
|
| 182 | - curl_setopt($ch, CURLOPT_FILE, $fp); |
|
| 183 | - if(!is_null($request->getPackageUrlUserId())) { |
|
| 184 | - curl_setopt($ch, CURLOPT_USERPWD, $request->getPackageUrlUserId().":".$request->getPackageUrlPassword()); |
|
| 185 | - } |
|
| 186 | - if(curl_exec($ch) === false) { |
|
| 187 | - $errno = curl_errno($ch); |
|
| 188 | - curl_close($ch); |
|
| 189 | - // Error occured. Throw an exception |
|
| 190 | - switch($errno) { |
|
| 191 | - case CURLE_UNSUPPORTED_PROTOCOL: |
|
| 192 | - throw new PENSException(1301); |
|
| 193 | - break; |
|
| 194 | - case CURLE_URL_MALFORMAT: |
|
| 195 | - case CURLE_COULDNT_RESOLVE_PROXY: |
|
| 196 | - case CURLE_COULDNT_RESOLVE_HOST: |
|
| 197 | - case CURLE_COULDNT_CONNECT: |
|
| 198 | - case CURLE_OPERATION_TIMEOUT: |
|
| 199 | - case CURLE_REMOTE_FILE_NOT_FOUND: |
|
| 200 | - throw new PENSException(1310); |
|
| 201 | - break; |
|
| 202 | - case CURLE_REMOTE_ACCESS_DENIED: |
|
| 203 | - throw new PENSException(1312); |
|
| 204 | - break; |
|
| 205 | - default: |
|
| 206 | - throw new PENSException(1301); |
|
| 207 | - break; |
|
| 208 | - } |
|
| 209 | - return null; |
|
| 170 | + // Try to download the package in the temporary directory |
|
| 171 | + $tmp = null; |
|
| 172 | + if(function_exists("sys_get_temp_dir")) { |
|
| 173 | + $tmp = sys_get_temp_dir(); |
|
| 174 | + } else { |
|
| 175 | + $tmp = "/tmp"; |
|
| 176 | + } |
|
| 177 | + $path_to_file = $tmp."/".$request->getFilename(); |
|
| 178 | + $fp = fopen($path_to_file, 'w'); |
|
| 179 | + $ch = curl_init(); |
|
| 180 | + curl_setopt($ch, CURLOPT_URL, $request->getPackageUrl()); |
|
| 181 | + curl_setopt($ch, CURLOPT_HEADER, false); |
|
| 182 | + curl_setopt($ch, CURLOPT_FILE, $fp); |
|
| 183 | + if(!is_null($request->getPackageUrlUserId())) { |
|
| 184 | + curl_setopt($ch, CURLOPT_USERPWD, $request->getPackageUrlUserId().":".$request->getPackageUrlPassword()); |
|
| 185 | + } |
|
| 186 | + if(curl_exec($ch) === false) { |
|
| 187 | + $errno = curl_errno($ch); |
|
| 188 | + curl_close($ch); |
|
| 189 | + // Error occured. Throw an exception |
|
| 190 | + switch($errno) { |
|
| 191 | + case CURLE_UNSUPPORTED_PROTOCOL: |
|
| 192 | + throw new PENSException(1301); |
|
| 193 | + break; |
|
| 194 | + case CURLE_URL_MALFORMAT: |
|
| 195 | + case CURLE_COULDNT_RESOLVE_PROXY: |
|
| 196 | + case CURLE_COULDNT_RESOLVE_HOST: |
|
| 197 | + case CURLE_COULDNT_CONNECT: |
|
| 198 | + case CURLE_OPERATION_TIMEOUT: |
|
| 199 | + case CURLE_REMOTE_FILE_NOT_FOUND: |
|
| 200 | + throw new PENSException(1310); |
|
| 201 | + break; |
|
| 202 | + case CURLE_REMOTE_ACCESS_DENIED: |
|
| 203 | + throw new PENSException(1312); |
|
| 204 | + break; |
|
| 205 | + default: |
|
| 206 | + throw new PENSException(1301); |
|
| 207 | + break; |
|
| 208 | + } |
|
| 209 | + return null; |
|
| 210 | 210 | |
| 211 | - } else { |
|
| 212 | - curl_close($ch); |
|
| 213 | - return $path_to_file; |
|
| 214 | - } |
|
| 215 | - } |
|
| 211 | + } else { |
|
| 212 | + curl_close($ch); |
|
| 213 | + return $path_to_file; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Verifies that the package url is not expired |
|
| 219 | - * |
|
| 220 | - * @param DateTime DateTime object to verify against current time |
|
| 221 | - */ |
|
| 222 | - protected function isExpiryDateValid($expiry) { |
|
| 223 | - date_default_timezone_set('UTC'); |
|
| 224 | - $current_time = time(); |
|
| 225 | - $expiry_time = strtotime($expiry->format(DateTime::ISO8601)); |
|
| 226 | - if($current_time > $expiry_time) { |
|
| 227 | - return false; |
|
| 228 | - } else { |
|
| 229 | - return true; |
|
| 230 | - } |
|
| 231 | - } |
|
| 217 | + /** |
|
| 218 | + * Verifies that the package url is not expired |
|
| 219 | + * |
|
| 220 | + * @param DateTime DateTime object to verify against current time |
|
| 221 | + */ |
|
| 222 | + protected function isExpiryDateValid($expiry) { |
|
| 223 | + date_default_timezone_set('UTC'); |
|
| 224 | + $current_time = time(); |
|
| 225 | + $expiry_time = strtotime($expiry->format(DateTime::ISO8601)); |
|
| 226 | + if($current_time > $expiry_time) { |
|
| 227 | + return false; |
|
| 228 | + } else { |
|
| 229 | + return true; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Sends an alert or a receipt. Called by sendReceipt and sendAlert |
|
| 235 | - * |
|
| 236 | - * @param PENSRequest Original collect request |
|
| 237 | - * @param PENSResponse Reponse to send in the receipt or the alert |
|
| 238 | - * @param string Mode (alert | receipt) |
|
| 239 | - * @return PENSResponse Response |
|
| 240 | - */ |
|
| 241 | - protected function sendAlertOrReceipt($request, $response, $mode) { |
|
| 242 | - if($mode == "alert") { |
|
| 243 | - $url = $request->getAlerts(); |
|
| 244 | - } else { |
|
| 245 | - $url = $request->getReceipt(); |
|
| 246 | - } |
|
| 247 | - if(!empty($url)) { |
|
| 248 | - $url_components = parse_url($url); |
|
| 249 | - $scheme = $url_components["scheme"]; |
|
| 250 | - if($scheme == "mailto") { |
|
| 251 | - $to = $url_components["path"]; |
|
| 252 | - if($mode == "alert") { |
|
| 253 | - $subject = "PENS Alert for ".$request->getPackageId(); |
|
| 254 | - } else { |
|
| 255 | - $subject = "PENS Receipt for ".$request->getPackageId(); |
|
| 256 | - } |
|
| 257 | - $message = $response->__toString(); |
|
| 258 | - mail($to, $subject, $message); |
|
| 259 | - return new PENSResponse(0, ""); |
|
| 260 | - } else if($scheme == "http" || $scheme == "https") { |
|
| 261 | - if($mode == "alert") { |
|
| 262 | - $params = array_merge($request->getSendAlertArray(), $response->getArray()); |
|
| 263 | - } else { |
|
| 264 | - $params = array_merge($request->getSendReceiptArray(), $response->getArray()); |
|
| 265 | - } |
|
| 266 | - $ch = curl_init($url); |
|
| 267 | - curl_setopt($ch, CURLOPT_POST, true); |
|
| 268 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $params); |
|
| 269 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 270 | - $data = curl_exec($ch); |
|
| 271 | - curl_close($ch); |
|
| 272 | - if($data === false) { |
|
| 273 | - return null; |
|
| 274 | - } else { |
|
| 275 | - return new PENSResponse($data); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 233 | + /** |
|
| 234 | + * Sends an alert or a receipt. Called by sendReceipt and sendAlert |
|
| 235 | + * |
|
| 236 | + * @param PENSRequest Original collect request |
|
| 237 | + * @param PENSResponse Reponse to send in the receipt or the alert |
|
| 238 | + * @param string Mode (alert | receipt) |
|
| 239 | + * @return PENSResponse Response |
|
| 240 | + */ |
|
| 241 | + protected function sendAlertOrReceipt($request, $response, $mode) { |
|
| 242 | + if($mode == "alert") { |
|
| 243 | + $url = $request->getAlerts(); |
|
| 244 | + } else { |
|
| 245 | + $url = $request->getReceipt(); |
|
| 246 | + } |
|
| 247 | + if(!empty($url)) { |
|
| 248 | + $url_components = parse_url($url); |
|
| 249 | + $scheme = $url_components["scheme"]; |
|
| 250 | + if($scheme == "mailto") { |
|
| 251 | + $to = $url_components["path"]; |
|
| 252 | + if($mode == "alert") { |
|
| 253 | + $subject = "PENS Alert for ".$request->getPackageId(); |
|
| 254 | + } else { |
|
| 255 | + $subject = "PENS Receipt for ".$request->getPackageId(); |
|
| 256 | + } |
|
| 257 | + $message = $response->__toString(); |
|
| 258 | + mail($to, $subject, $message); |
|
| 259 | + return new PENSResponse(0, ""); |
|
| 260 | + } else if($scheme == "http" || $scheme == "https") { |
|
| 261 | + if($mode == "alert") { |
|
| 262 | + $params = array_merge($request->getSendAlertArray(), $response->getArray()); |
|
| 263 | + } else { |
|
| 264 | + $params = array_merge($request->getSendReceiptArray(), $response->getArray()); |
|
| 265 | + } |
|
| 266 | + $ch = curl_init($url); |
|
| 267 | + curl_setopt($ch, CURLOPT_POST, true); |
|
| 268 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); |
|
| 269 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 270 | + $data = curl_exec($ch); |
|
| 271 | + curl_close($ch); |
|
| 272 | + if($data === false) { |
|
| 273 | + return null; |
|
| 274 | + } else { |
|
| 275 | + return new PENSResponse($data); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Sends a receipt. Returns a PENSResponse in case of success, null if a problem occured |
|
| 283 | - * |
|
| 284 | - * @param PENSRequest Original collect request |
|
| 285 | - * @param PENSResponse Response to send in the receipt |
|
| 286 | - * @return PENSResponse Response |
|
| 287 | - */ |
|
| 288 | - protected function sendReceipt($request, $receipt) { |
|
| 289 | - return $this->sendAlertOrReceipt($request, $receipt, "receipt"); |
|
| 290 | - } |
|
| 281 | + /** |
|
| 282 | + * Sends a receipt. Returns a PENSResponse in case of success, null if a problem occured |
|
| 283 | + * |
|
| 284 | + * @param PENSRequest Original collect request |
|
| 285 | + * @param PENSResponse Response to send in the receipt |
|
| 286 | + * @return PENSResponse Response |
|
| 287 | + */ |
|
| 288 | + protected function sendReceipt($request, $receipt) { |
|
| 289 | + return $this->sendAlertOrReceipt($request, $receipt, "receipt"); |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Processes the package using the handler provided |
|
| 294 | - * |
|
| 295 | - * @param PENSRequest Original collect request |
|
| 296 | - * @param string Path to the package on the hard drive |
|
| 297 | - */ |
|
| 298 | - protected function processPackage($request, $path_to_package) { |
|
| 299 | - return $this->_package_handler->processPackage($request, $path_to_package); |
|
| 300 | - } |
|
| 292 | + /** |
|
| 293 | + * Processes the package using the handler provided |
|
| 294 | + * |
|
| 295 | + * @param PENSRequest Original collect request |
|
| 296 | + * @param string Path to the package on the hard drive |
|
| 297 | + */ |
|
| 298 | + protected function processPackage($request, $path_to_package) { |
|
| 299 | + return $this->_package_handler->processPackage($request, $path_to_package); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Sends an alert to the client. Returns a PENSResponse in case of success, null if a problem occured |
|
| 304 | - * |
|
| 305 | - * @param PENSRequest Original collect request |
|
| 306 | - * @param PENSResponse Response to send in the alert |
|
| 307 | - * @return PENSResponse Response |
|
| 308 | - */ |
|
| 309 | - public function sendAlert($request, $alert) { |
|
| 310 | - return $this->sendAlertOrReceipt($request, $alert, "alert"); |
|
| 311 | - } |
|
| 302 | + /** |
|
| 303 | + * Sends an alert to the client. Returns a PENSResponse in case of success, null if a problem occured |
|
| 304 | + * |
|
| 305 | + * @param PENSRequest Original collect request |
|
| 306 | + * @param PENSResponse Response to send in the alert |
|
| 307 | + * @return PENSResponse Response |
|
| 308 | + */ |
|
| 309 | + public function sendAlert($request, $alert) { |
|
| 310 | + return $this->sendAlertOrReceipt($request, $alert, "alert"); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | 313 | } |
@@ -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); |
@@ -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 | } |