From: Andrey Kutejko Date: Sun, 28 Jul 2013 11:39:25 +0000 (+0300) Subject: introduce IPF_XmlRpc_Exception class X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=8fad97eb72a26297f9ecf3f930bc1411b8462f65;p=ipf-xmlrpc.git introduce IPF_XmlRpc_Exception class --- diff --git a/xmlrpc/exception.php b/xmlrpc/exception.php new file mode 100644 index 0000000..fb3bd1d --- /dev/null +++ b/xmlrpc/exception.php @@ -0,0 +1,6 @@ +getMessage(), 500); + throw new IPF_XmlRpc_Exception('Failed to parse XML fault: ' . $e->getMessage(), 500); } // Check for fault @@ -107,7 +107,7 @@ class IPF_XmlRpc_Fault if (!$xml->fault->value->struct) { // not a proper fault - throw new IPF_Exception('Invalid fault structure', 500); + throw new IPF_XmlRpc_Exception('Invalid fault structure', 500); } $structXml = $xml->fault->value->asXML(); @@ -123,7 +123,7 @@ class IPF_XmlRpc_Fault } if (empty($code) && empty($message)) { - throw new IPF_Exception('Fault code and string required'); + throw new IPF_XmlRpc_Exception('Fault code and string required'); } if (empty($code)) { @@ -149,7 +149,7 @@ class IPF_XmlRpc_Fault $fault = new self(); try { $isFault = $fault->loadXml($xml); - } catch (IPF_Exception $e) { + } catch (IPF_XmlRpc_Exception $e) { $isFault = false; } diff --git a/xmlrpc/request/http.php b/xmlrpc/request/http.php index f66114e..fc641aa 100644 --- a/xmlrpc/request/http.php +++ b/xmlrpc/request/http.php @@ -8,7 +8,7 @@ class IPF_XmlRpc_Request_Http extends IPF_XmlRpc_Request { $fh = fopen('php://input', 'r'); if (!$fh) { - $this->_fault = new IPF_Exception(630); + $this->_fault = new IPF_XmlRpc_Exception(630); return; } diff --git a/xmlrpc/response.php b/xmlrpc/response.php index 5f2f78a..e6de1b9 100644 --- a/xmlrpc/response.php +++ b/xmlrpc/response.php @@ -83,12 +83,12 @@ class IPF_XmlRpc_Response try { if (!isset($xml->params) || !isset($xml->params->param) || !isset($xml->params->param->value)) { - throw new IPF_Exception('Missing XML-RPC value in XML'); + throw new IPF_XmlRpc_Exception('Missing XML-RPC value in XML'); } $valueXml = $xml->params->param->value->asXML(); $valueXml = preg_replace('/<\?xml version=.*?\?>/i', '', $valueXml); $value = IPF_XmlRpc_Value::getXmlRpcValue(trim($valueXml), IPF_XmlRpc_Value::XML_STRING); - } catch (IPF_Exception $e) { + } catch (IPF_XmlRpc_Exception $e) { $this->_fault = new IPF_XmlRpc_Fault(653); $this->_fault->setEncoding($this->getEncoding()); return false; diff --git a/xmlrpc/server.php b/xmlrpc/server.php index a3a5a3a..5b9bf53 100644 --- a/xmlrpc/server.php +++ b/xmlrpc/server.php @@ -80,7 +80,7 @@ class IPF_XmlRpc_Server $name = empty($ns) ? $name : $ns . '.' . $name; if (isset($table[$name])) { - throw new IPF_Exception('Duplicate method registered: ' . $name); + throw new IPF_XmlRpc_Exception('Duplicate method registered: ' . $name); } $table[$name] = $dispatchable; $this->_fixTypes($dispatchable); @@ -95,7 +95,7 @@ class IPF_XmlRpc_Server $name = empty($ns) ? $name : $ns . '.' . $name; if (isset($table[$name])) { - throw new IPF_Exception('Duplicate method registered: ' . $name); + throw new IPF_XmlRpc_Exception('Duplicate method registered: ' . $name); } $table[$name] = $method; $this->_fixTypes($method); @@ -121,7 +121,7 @@ class IPF_XmlRpc_Server public function addFunction($function, $namespace = '') { if (!is_string($function) && !is_array($function)) { - throw new IPF_Exception('Unable to attach function; invalid', 611); + throw new IPF_XmlRpc_Exception('Unable to attach function; invalid', 611); } $argv = null; @@ -133,7 +133,7 @@ class IPF_XmlRpc_Server $function = (array) $function; foreach ($function as $func) { if (!is_string($func) || !function_exists($func)) { - throw new IPF_Exception('Unable to attach function; invalid', 611); + throw new IPF_XmlRpc_Exception('Unable to attach function; invalid', 611); } $this->_methods[] = IPF_Server_Reflection::reflectFunction($func, $argv, $namespace); } @@ -144,14 +144,14 @@ class IPF_XmlRpc_Server public function loadFunctions($array) { if (!is_array($array)) { - throw new IPF_Exception('Unable to load array; not an array', 612); + throw new IPF_XmlRpc_Exception('Unable to load array; not an array', 612); } foreach ($array as $key => $value) { if (!$value instanceof IPF_Server_Reflection_Function_Abstract && !$value instanceof IPF_Server_Reflection_Class) { - throw new IPF_Exception('One or more method records are corrupt or otherwise unusable', 613); + throw new IPF_XmlRpc_Exception('One or more method records are corrupt or otherwise unusable', 613); } if ($value->system) { @@ -174,7 +174,7 @@ class IPF_XmlRpc_Server { if (is_string($class) && !class_exists($class)) { if (!class_exists($class)) { - throw new IPF_Exception('Invalid method class', 610); + throw new IPF_XmlRpc_Exception('Invalid method class', 610); } } @@ -193,11 +193,11 @@ class IPF_XmlRpc_Server if (is_string($request) && class_exists($request)) { $request = new $request(); if (!$request instanceof IPF_XmlRpc_Request) { - throw new IPF_Exception('Invalid request class'); + throw new IPF_XmlRpc_Exception('Invalid request class'); } $request->setEncoding($this->getEncoding()); } elseif (!$request instanceof IPF_XmlRpc_Request) { - throw new IPF_Exception('Invalid request object'); + throw new IPF_XmlRpc_Exception('Invalid request object'); } $this->_request = $request; @@ -213,7 +213,7 @@ class IPF_XmlRpc_Server { if (!$fault instanceof Exception) { $fault = (string) $fault; - $fault = new IPF_Exception($fault, $code); + $fault = new IPF_XmlRpc_Exception($fault, $code); } return IPF_XmlRpc_Server_Fault::getInstance($fault); } @@ -224,7 +224,7 @@ class IPF_XmlRpc_Server // Check for valid method if (!isset($this->_table[$method])) { - throw new IPF_Exception('Method "' . $method . '" does not exist', 620); + throw new IPF_XmlRpc_Exception('Method "' . $method . '" does not exist', 620); } $info = $this->_table[$method]; @@ -260,7 +260,7 @@ class IPF_XmlRpc_Server } } if (!$matched) { - throw new IPF_Exception('Calling parameters do not match signature', 623); + throw new IPF_XmlRpc_Exception('Calling parameters do not match signature', 623); } if ($info instanceof IPF_Server_Reflection_Function) { @@ -283,13 +283,13 @@ class IPF_XmlRpc_Server try { $object = $info->getDeclaringClass()->newInstance(); } catch (Exception $e) { - throw new IPF_Exception('Error instantiating class ' . $class . ' to invoke method ' . $info->getName(), 621); + throw new IPF_XmlRpc_Exception('Error instantiating class ' . $class . ' to invoke method ' . $info->getName(), 621); } $return = $info->invokeArgs($object, $params); } } else { - throw new IPF_Exception('Method missing implementation ' . get_class($info), 622); + throw new IPF_XmlRpc_Exception('Method missing implementation ' . get_class($info), 622); } $response = new ReflectionClass($this->_responseClass); @@ -359,7 +359,7 @@ class IPF_XmlRpc_Server public function methodHelp($method) { if (!isset($this->_table[$method])) { - throw new IPF_Exception('Method "' . $method . '"does not exist', 640); + throw new IPF_XmlRpc_Exception('Method "' . $method . '"does not exist', 640); } return $this->_table[$method]->getDescription(); @@ -368,7 +368,7 @@ class IPF_XmlRpc_Server public function methodSignature($method) { if (!isset($this->_table[$method])) { - throw new IPF_Exception('Method "' . $method . '"does not exist', 640); + throw new IPF_XmlRpc_Exception('Method "' . $method . '"does not exist', 640); } $prototypes = $this->_table[$method]->getPrototypes(); diff --git a/xmlrpc/server/fault.php b/xmlrpc/server/fault.php index 50db5ed..bd5ca0e 100644 --- a/xmlrpc/server/fault.php +++ b/xmlrpc/server/fault.php @@ -3,7 +3,7 @@ class IPF_XmlRpc_Server_Fault extends IPF_XmlRpc_Fault { protected $_exception; - protected static $_faultExceptionClasses = array('IPF_Exception' => true); + protected static $_faultExceptionClasses = array('IPF_Server_Exception' => true, 'IPF_XmlRpc_Exception' => true); protected static $_observers = array(); public function __construct(Exception $e) diff --git a/xmlrpc/value.php b/xmlrpc/value.php index 5201bed..7a2431b 100644 --- a/xmlrpc/value.php +++ b/xmlrpc/value.php @@ -86,7 +86,7 @@ abstract class IPF_XmlRpc_Value return new IPF_XmlRpc_Value_Struct($value); default: - throw new IPF_Exception('Given type is not a '. __CLASS__ .' constant'); + throw new IPF_XmlRpc_Exception('Given type is not a '. __CLASS__ .' constant'); } } @@ -140,7 +140,7 @@ abstract class IPF_XmlRpc_Value $simple_xml = @new SimpleXMLElement($simple_xml); } catch (Exception $e) { // The given string is not a valid XML - throw new IPF_Exception('Failed to create XML-RPC value from XML string: '.$e->getMessage(),$e->getCode()); + throw new IPF_XmlRpc_Exception('Failed to create XML-RPC value from XML string: '.$e->getMessage(),$e->getCode()); } } @@ -178,7 +178,7 @@ abstract class IPF_XmlRpc_Value case self::XMLRPC_TYPE_ARRAY: // If the XML is valid, $value must be an SimpleXML element and contain the tag if (!$value instanceof SimpleXMLElement) { - throw new IPF_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type'); + throw new IPF_XmlRpc_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type'); } // PHP 5.2.4 introduced a regression in how empty($xml->value) @@ -192,7 +192,7 @@ abstract class IPF_XmlRpc_Value } if (null === $data) { - throw new IPF_Exception('Invalid XML for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type: ARRAY tag must contain DATA tag'); + throw new IPF_XmlRpc_Exception('Invalid XML for XML-RPC native '. self::XMLRPC_TYPE_ARRAY .' type: ARRAY tag must contain DATA tag'); } $values = array(); // Parse all the elements of the array from the XML string @@ -205,7 +205,7 @@ abstract class IPF_XmlRpc_Value case self::XMLRPC_TYPE_STRUCT: // If the XML is valid, $value must be an SimpleXML if ((!$value instanceof SimpleXMLElement)) { - throw new IPF_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_STRUCT .' type'); + throw new IPF_XmlRpc_Exception('XML string is invalid for XML-RPC native '. self::XMLRPC_TYPE_STRUCT .' type'); } $values = array(); // Parse all the memebers of the struct from the XML string @@ -222,7 +222,7 @@ abstract class IPF_XmlRpc_Value $xmlrpc_val = new IPF_XmlRpc_Value_Struct($values); break; default: - throw new IPF_Exception('Value type \''. $type .'\' parsed from the XML string is not a known XML-RPC native type'); + throw new IPF_XmlRpc_Exception('Value type \''. $type .'\' parsed from the XML string is not a known XML-RPC native type'); break; } $xmlrpc_val->_setXML($simple_xml->asXML()); diff --git a/xmlrpc/value/collection.php b/xmlrpc/value/collection.php index a720f10..08f951a 100644 --- a/xmlrpc/value/collection.php +++ b/xmlrpc/value/collection.php @@ -21,7 +21,7 @@ abstract class IPF_XmlRpc_Value_Collection extends IPF_XmlRpc_Value foreach ($values as $key => $value) { /* @var $value IPF_XmlRpc_Value */ if (!$value instanceof parent) { - throw new IPF_Exception('Values of '. get_class($this) .' type must be IPF_XmlRpc_Value objects'); + throw new IPF_XmlRpc_Exception('Values of '. get_class($this) .' type must be IPF_XmlRpc_Value objects'); } $values[$key] = $value->getValue(); } diff --git a/xmlrpc/value/datetime.php b/xmlrpc/value/datetime.php index 569cd75..ed1c0ec 100644 --- a/xmlrpc/value/datetime.php +++ b/xmlrpc/value/datetime.php @@ -12,7 +12,7 @@ class IPF_XmlRpc_Value_DateTime extends IPF_XmlRpc_Value_Scalar } else { $value = strtotime($value); if ($value === false || $value == -1) { // cannot convert the value to a timestamp - throw new IPF_Exception('Cannot convert given value \''. $value .'\' to a timestamp'); + throw new IPF_XmlRpc_Exception('Cannot convert given value \''. $value .'\' to a timestamp'); } } $value = date('c', $value); // Convert the timestamp to iso8601 format