]> git.andy128k.dev Git - ipf-xmlrpc.git/commitdiff
introduce IPF_XmlRpc_Exception class
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 28 Jul 2013 11:39:25 +0000 (14:39 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 28 Jul 2013 11:39:25 +0000 (14:39 +0300)
xmlrpc/exception.php [new file with mode: 0644]
xmlrpc/fault.php
xmlrpc/request/http.php
xmlrpc/response.php
xmlrpc/server.php
xmlrpc/server/fault.php
xmlrpc/value.php
xmlrpc/value/collection.php
xmlrpc/value/datetime.php

diff --git a/xmlrpc/exception.php b/xmlrpc/exception.php
new file mode 100644 (file)
index 0000000..fb3bd1d
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+
+class IPF_XmlRpc_Exception extends Exception
+{
+}
+
index 7b1d7b78a5cf391c9b1bb0529ed6afa964ce91c4..40900dd263beb604dbd05e05984bf727adcfa855 100644 (file)
@@ -89,14 +89,14 @@ class IPF_XmlRpc_Fault
     public function loadXml($fault)
     {
         if (!is_string($fault)) {
-            throw new IPF_Exception('Invalid XML provided to fault');
+            throw new IPF_XmlRpc_Exception('Invalid XML provided to fault');
         }
 
         try {
             $xml = @new SimpleXMLElement($fault);
         } catch (Exception $e) {
             // Not valid XML
-            throw new IPF_Exception('Failed to parse XML fault: ' .  $e->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;
         }
 
index f66114ee53e7c5a9f77a3aa3c99a78e86b7a04bd..fc641aa729df30998526d86abf73effff0aee98c 100644 (file)
@@ -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;
         }
 
index 5f2f78a8e2ea57838d4d3adc732aa2e29e306285..e6de1b9b71f022874bcdba02872d1acd9fd8c3d7 100644 (file)
@@ -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;
index a3a5a3ab7c70cbc46244b117bf40d58132345183..5b9bf530ca0762bf653aca4989bed11b1598ce64 100644 (file)
@@ -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();
 
index 50db5ed347c07663a2cf211ba154d17e5299aee7..bd5ca0ef1cce65b6c2616b354e69f1f7efc051c9 100644 (file)
@@ -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)
index 5201bed492c8d81b4841c936f3583073feb131ec..7a2431b3a6039c36c64004523d833407b1e44664 100644 (file)
@@ -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 <data> 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());
index a720f10733fb2ecb6454e308b5eaabef482524a9..08f951ac01169e161a36f62f4040fbb23621d702 100644 (file)
@@ -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();
         }
index 569cd757f9fcc9743b358b3bfab292910b85a0e5..ed1c0ec14fe61584bc01c6b0a3c34e9a9ebf815e 100644 (file)
@@ -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