add a Horde_Rpc_Exception class; start PHP 5 code cleanup
authorChuck Hagenbuch <chuck@horde.org>
Fri, 12 Jun 2009 20:06:53 +0000 (16:06 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Fri, 12 Jun 2009 20:06:58 +0000 (16:06 -0400)
framework/Rpc/lib/Horde/Rpc.php
framework/Rpc/lib/Horde/Rpc/Exception.php [new file with mode: 0644]
framework/Rpc/lib/Horde/Rpc/Jsonrpc.php
framework/Rpc/lib/Horde/Rpc/Phpgw.php
framework/Rpc/lib/Horde/Rpc/Soap.php
framework/Rpc/lib/Horde/Rpc/Syncml.php
framework/Rpc/lib/Horde/Rpc/Syncml/Wbxml.php
framework/Rpc/lib/Horde/Rpc/Webdav.php
framework/Rpc/lib/Horde/Rpc/Xmlrpc.php
framework/Rpc/package.xml

index 0aa7721..fe2ddda 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * The Horde_RPC:: class provides a set of server and client methods for
+ * The Horde_Rpc:: class provides a set of server and client methods for
  * RPC communication.
  *
  * TODO:
@@ -8,7 +8,7 @@
  *
  * EXAMPLE:
  * <code>
- * $response = Horde_RPC::request('xmlrpc',
+ * $response = Horde_Rpc::request('xmlrpc',
  *                                'http://localhost:80/horde/rpc.php',
  *                                'contacts.search',
  *                                array(array('jan'), array('localsql'),
@@ -17,8 +17,6 @@
  *                                      'pass' => Auth::getCredential('password')));
  * </code>
  *
- * $Horde: framework/RPC/RPC.php,v 1.30 2009/01/06 17:49:37 jan Exp $
- *
  * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (LGPL). If you
  *
  * @author  Jan Schneider <jan@horde.org>
  * @since   Horde 3.0
- * @package Horde_RPC
+ * @package Horde_Rpc
  */
-class Horde_RPC {
-
+class Horde_Rpc
+{
     /**
      * All driver-specific parameters.
      *
@@ -58,9 +56,9 @@ class Horde_RPC {
      * @param array $config  A hash containing any additional configuration or
      *                       connection parameters a subclass might need.
      *
-     * @return Horde_RPC  An RPC server instance.
+     * @return Horde_Rpc  An RPC server instance.
      */
-    function Horde_RPC($params = array())
+    public function __construct($params = array())
     {
         $this->_params = $params;
 
@@ -173,19 +171,14 @@ class Horde_RPC {
      * @return mixed            The returned result from the method or a PEAR
      *                          error object on failure.
      */
-    function request($driver, $url, $method, $params = null, $options = array())
+    public static function request($driver, $url, $method, $params = null, $options = array())
     {
         $driver = basename($driver);
-        $class = 'Horde_RPC_' . $driver;
-        if (!class_exists($class)) {
-            include 'Horde/RPC/' . $driver . '.php';
-        }
-
+        $class = 'Horde_Rpc_' . $driver;
         if (class_exists($class)) {
             return call_user_func(array($class, 'request'), $url, $method, $params, $options);
         } else {
-            include_once 'PEAR.php';
-            return PEAR::raiseError('Class definition of ' . $class . ' not found.');
+            throw new Horde_Rpc_Exception('Class definition of ' . $class . ' not found.');
         }
     }
 
@@ -193,33 +186,21 @@ class Horde_RPC {
      * Attempts to return a concrete RPC server instance based on
      * $driver.
      *
-     * @param mixed $driver  The type of concrete RPC subclass to return. If
-     *                       $driver is an array, then we will look in
-     *                       $driver[0]/lib/RPC/ for the subclass
-     *                       implementation named $driver[1].php.
+     * @param mixed $driver  The type of concrete Horde_Rpc subclass to return.
      * @param array $params  A hash containing any additional configuration or
      *                       connection parameters a subclass might need.
      *
-     * @return Horde_RPC  The newly created concrete Horde_RPC server instance,
-     *                    or PEAR_Error on error.
+     * @return Horde_Rpc  The newly created concrete Horde_Rpc server instance,
+     *                    or an exception if there is an error.
      */
-    function factory($driver, $params = null)
+    public static function factory($driver, $params = null)
     {
         $driver = basename($driver);
-        if ($driver == 'soap' && class_exists('SoapServer')) {
-            $driver = 'PhpSoap';
-        }
-
-        $class = 'Horde_RPC_' . $driver;
-        if (!class_exists($class)) {
-            include 'Horde/RPC/' . $driver . '.php';
-        }
-
+        $class = 'Horde_Rpc_' . $driver;
         if (class_exists($class)) {
             return new $class($params);
         } else {
-            include_once 'PEAR.php';
-            return PEAR::raiseError('Class definition of ' . $class . ' not found.');
+            throw new Horde_Rpc_Exception('Class definition of ' . $class . ' not found.');
         }
     }
 
diff --git a/framework/Rpc/lib/Horde/Rpc/Exception.php b/framework/Rpc/lib/Horde/Rpc/Exception.php
new file mode 100644 (file)
index 0000000..84b26ce
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+class Horde_Rpc_Exception extends Exception
+{
+}
index 2f2fbd3..cc7d929 100644 (file)
@@ -1,16 +1,15 @@
 <?php
 /**
- * $Horde: framework/RPC/RPC/jsonrpc.php,v 1.9 2009/02/21 01:58:14 chuck Exp $
- *
  * Copyright 2007-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (LGPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  *
- * @author  Joey Hewitt <joey@joeyhewitt.com>
- * @author  Jan Schneider <jan@horde.org>
- * @since   Horde 3.2
- * @package Horde_RPC
+ * @author   Joey Hewitt <joey@joeyhewitt.com>
+ * @author   Jan Schneider <jan@horde.org>
+ * @since    Horde 3.2
+ * @category Horde
+ * @package  Horde_Rpc
  */
 
 /**
  *   works with positional parameters.
  * - Service Descriptions are not supported yet.
  *
- * @link http://json-rpc.org
- * @package Horde_RPC
+ * @link     http://json-rpc.org
+ * @category Horde
+ * @package  Horde_RPC
  */
-class Horde_RPC_jsonrpc extends Horde_RPC {
-
+class Horde_Rpc_Jsonrpc extends Horde_Rpc
+{
     /**
      * Returns the Content-Type of the response.
      *
@@ -165,7 +165,7 @@ class Horde_RPC_jsonrpc extends Horde_RPC {
             $options = array_merge($options, $GLOBALS['conf']['http']['proxy']);
         }
 
-        require_once 'HTTP/Request.php';
+        /*@TODO Use Horde_Http_Request */
         $http = new HTTP_Request($url, $options);
         if (!empty($language)) {
             $http->addHeader('Accept-Language', $language);
index 7bee4be..1bb0b9e 100644 (file)
@@ -1,18 +1,19 @@
 <?php
 /**
- * The Horde_RPC_phpgw class provides an XMLRPC implementation of the
+ * The Horde_Rpc_Phpgw class provides an XMLRPC implementation of the
  * Horde RPC system compatible with phpgw. It is based on the
  * xmlrpc.php implementation by Jan Schneider.
  *
  * See the enclosed file COPYING for license information (LGPL). If you
  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  *
- * @author  Michael Braun <mi.braun@onlinehome.de>
- * @since   Horde 3.2
- * @package Horde_RPC
+ * @author   Michael Braun <mi.braun@onlinehome.de>
+ * @since    Horde 3.2
+ * @category Horde
+ * @package  Horde_Rpc
  */
-class Horde_RPC_phpgw extends Horde_RPC {
-
+class Horde_Rpc_Phpgw extends Horde_Rpc
+{
     /**
      * Resource handler for the XML-RPC server.
      *
@@ -23,9 +24,9 @@ class Horde_RPC_phpgw extends Horde_RPC {
     /**
      * XMLRPC server constructor.
      */
-    function Horde_RPC_phpgw()
+    function __construct()
     {
-        parent::Horde_RPC();
+        parent::__construct();
 
         $this->_server = xmlrpc_server_create();
 
@@ -34,7 +35,7 @@ class Horde_RPC_phpgw extends Horde_RPC {
             $methods = explode('/', $method);
             array_shift($methods);
             $method = implode('.', $methods);
-            xmlrpc_server_register_method($this->_server, $method, array('Horde_RPC_phpgw', '_dispatcher'));
+            xmlrpc_server_register_method($this->_server, $method, array('Horde_Rpc_Phpgw', '_dispatcher'));
         }
     }
 
@@ -152,7 +153,6 @@ class Horde_RPC_phpgw extends Horde_RPC {
             $options = array_merge($options, $GLOBALS['conf']['http']['proxy']);
         }
 
-        require_once 'HTTP/Request.php';
         $http = new HTTP_Request($url, $options);
         if (!empty($language)) {
             $http->addHeader('Accept-Language', $language);
index 7280542..d0ac77d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * The Horde_RPC_PhpSoap class provides a PHP 5 Soap implementation
+ * The Horde_Rpc_Soap class provides a PHP 5 Soap implementation
  * of the Horde RPC system.
  *
  * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
  *
  * @author  Chuck Hagenbuch <chuck@horde.org>
  * @since   Horde 3.2
- * @package Horde_RPC
+ * @package Horde_Rpc
  */
 class Horde_Rpc_Soap extends Horde_Rpc
 {
     /**
-     * Resource handler for the RPC server.
+     * Resource handler for the SOAP server.
      *
      * @var object
      */
@@ -51,7 +51,7 @@ class Horde_Rpc_Soap extends Horde_Rpc
     {
         NLS::setCharset('UTF-8');
 
-        parent::Horde_RPC($params);
+        parent::__construct($params);
 
         if (!empty($params['allowedTypes'])) {
             $this->_allowedTypes = $params['allowedTypes'];
@@ -65,11 +65,11 @@ class Horde_Rpc_Soap extends Horde_Rpc
 
         $this->_server = new SoapServer(null, array('uri' => Horde::url($GLOBALS['registry']->get('webroot', 'horde') . '/rpc.php', true, false)));
         $this->_server->addFunction(SOAP_FUNCTIONS_ALL);
-        $this->_server->setClass('Horde_RPC_PhpSoap_Caller', $params);
+        $this->_server->setClass('Horde_Rpc_Soap_Caller', $params);
     }
 
     /**
-     * Takes an RPC request and returns the result.
+     * Takes a SOAP request and returns the result.
      *
      * @param string  The raw request string.
      *
@@ -78,13 +78,9 @@ class Horde_Rpc_Soap extends Horde_Rpc
     function getResponse($request)
     {
         if ($request == 'disco' || $request == 'wsdl') {
-            /* TODO - replace PEAR here? For now fall back to the PEAR
-             * server. */
-            if (!class_exists('Horde_RPC_soap')) {
-                include dirname(__FILE__) . '/soap.php';
-            }
-            $handler = new Horde_RPC_soap($this->_params);
-            return $handler->getResponse($request);
+            /*@TODO Replace with subcalls for disco and wsdl generation from the old SOAP driver. */
+            //$handler = new Horde_Rpc_Soap($this->_params);
+            //return $handler->getResponse($request);
         }
 
         /* We can't use Horde_Util::bufferOutput() here for some reason. */
@@ -161,7 +157,7 @@ class Horde_Rpc_Soap extends Horde_Rpc
 
 }
 
-class Horde_RPC_PhpSoap_Caller {
+class Horde_Rpc_Soap_Caller {
 
     /**
      * List of method names to allow.
index 87494ae..0696a7b 100644 (file)
@@ -4,11 +4,9 @@ require_once 'SyncML.php';
 require_once 'SyncML/Backend.php';
 
 /**
- * The Horde_RPC_syncml class provides a SyncML implementation of the Horde
+ * The Horde_Rpc_Syncml class provides a SyncML implementation of the Horde
  * RPC system.
  *
- * $Horde: framework/RPC/RPC/syncml.php,v 1.45 2009/01/06 17:49:38 jan Exp $
- *
  * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (LGPL). If you
@@ -17,11 +15,10 @@ require_once 'SyncML/Backend.php';
  * @author  Chuck Hagenbuch <chuck@horde.org>
  * @author  Anthony Mills <amills@pyramid6.com>
  * @since   Horde 3.0
- * @package Horde_RPC
+ * @package Horde_Rpc
  */
-
-class Horde_RPC_syncml extends Horde_RPC {
-
+class Horde_Rpc_Syncml extends Horde_Rpc
+{
     /**
      * SyncML handles authentication internally, so bypass the RPC framework
      * auth check by just returning true here.
index 28b6203..a0d5ad0 100644 (file)
@@ -1,13 +1,8 @@
 <?php
-
-require_once dirname(__FILE__) . '/syncml.php';
-
 /**
- * The Horde_RPC_syncml_wbxml class provides a SyncML implementation of the
+ * The Horde_Rpc_Syncml_Wbxml class provides a SyncML implementation of the
  * Horde RPC system using WBXML encoding.
  *
- * $Horde: framework/RPC/RPC/syncml_wbxml.php,v 1.29 2009/01/06 17:49:38 jan Exp $
- *
  * Copyright 2003-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (LGPL). If you
@@ -16,10 +11,10 @@ require_once dirname(__FILE__) . '/syncml.php';
  * @author  Chuck Hagenbuch <chuck@horde.org>
  * @author  Anthony Mills <amills@pyramid6.com>
  * @since   Horde 3.0
- * @package Horde_RPC
+ * @package Horde_Rpc
  */
-class Horde_RPC_syncml_wbxml extends Horde_RPC_syncml {
-
+class Horde_Rpc_Syncml_Wbxml extends Horde_Rpc_Syncml
+{
     /**
      * Returns the Content-Type of the response.
      *
index ea1d762..36f7862 100644 (file)
@@ -1,10 +1,8 @@
 <?php
 /**
- * The Horde_RPC_webdav class provides a WebDAV implementation of the
+ * The Horde_Rpc_Webdav class provides a WebDAV implementation of the
  * Horde RPC system.
  *
- * $Horde: framework/RPC/RPC/webdav.php,v 1.49 2009/03/05 04:20:33 slusarz Exp $
- *
  * Copyright 2008-2009 The Horde Project (http://www.horde.org/)
  *
  * Derived from the HTTP_WebDAV_Server PEAR package:
  * @author  Hartmut Holzgraefe
  * @author  Christian Stocker
  * @since   Horde 3.0
- * @package Horde_RPC
+ * @package Horde_Rpc
  */
-
-// Use Horde's Xml_Element to construct the DAV responses
-require_once 'Horde/Xml/Element.php';
-
-class Horde_RPC_webdav extends Horde_RPC {
-
+class Horde_Rpc_Webdav extends Horde_Rpc
+{
     /**
      * CalDAV XML namespace
      *
@@ -223,16 +217,16 @@ class Horde_RPC_webdav extends Horde_RPC {
      *
      * @access private
      */
-    function Horde_RPC_webdav()
+    public function __construct()
     {
         // PHP messages destroy XML output -> switch them off
-        ini_set("display_errors", 0);
+        ini_set('display_errors', 0);
 
         // copy $_SERVER variables to local _SERVER array
         // so that derived classes can simply modify these
         $this->_SERVER = $_SERVER;
 
-        parent::Horde_RPC();
+        parent::__construct();
     }
 
     /**
@@ -265,7 +259,6 @@ class Horde_RPC_webdav extends Horde_RPC {
         exit;
     }
 
-
     /**
      * GET implementation.
      *
@@ -734,8 +727,7 @@ Horde::logMessage(print_r($list, true), __FILE__, __LINE__, PEAR_LOG_ERR);
             $timeout = 600;
         }
 
-        require_once 'Horde/Lock.php';
-        $locks = &Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']);
+        $locks = Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']);
         if (is_a($locks, 'PEAR_Error')) {
             Horde::logMessage($locks, __FILE__, __LINE__, PEAR_LOG_ERR);
             return 500;
@@ -780,8 +772,7 @@ Horde::logMessage(print_r($list, true), __FILE__, __LINE__, PEAR_LOG_ERR);
             return 500;
         }
 
-        require_once 'Horde/Lock.php';
-        $locks = &Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']);
+        $locks = Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']);
         if (is_a($locks, 'PEAR_Error')) {
             Horde::logMessage($locks, __FILE__, __LINE__, PEAR_LOG_ERR);
             return 500;
@@ -810,8 +801,7 @@ Horde::logMessage(print_r($list, true), __FILE__, __LINE__, PEAR_LOG_ERR);
             return false;
         }
 
-        require_once 'Horde/Lock.php';
-        $locks = &Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']);
+        $locks = Horde_Lock::singleton($GLOBALS['conf']['lock']['driver']);
         if (is_a($locks, 'PEAR_Error')) {
             Horde::logMessage($locks, __FILE__, __LINE__, PEAR_LOG_ERR);
             return false;
index d1dca95..461f513 100644 (file)
@@ -1,10 +1,8 @@
 <?php
 /**
- * The Horde_RPC_xmlrpc class provides an XMLRPC implementation of the
+ * The Horde_Rpc_xmlrpc class provides an XMLRPC implementation of the
  * Horde RPC system.
  *
- * $Horde: framework/RPC/RPC/xmlrpc.php,v 1.24 2009/01/06 17:49:38 jan Exp $
- *
  * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (LGPL). If you
  *
  * @author  Jan Schneider <jan@horde.org>
  * @since   Horde 3.0
- * @package Horde_RPC
+ * @package Horde_Rpc
  */
-class Horde_RPC_xmlrpc extends Horde_RPC {
-
+class Horde_Rpc_Xmlrpc extends Horde_Rpc
+{
     /**
      * Resource handler for the XMLRPC server.
      *
@@ -28,14 +26,14 @@ class Horde_RPC_xmlrpc extends Horde_RPC {
      *
      * @access private
      */
-    function Horde_RPC_xmlrpc()
+    public function __construct()
     {
-        parent::Horde_RPC();
+        parent::__construct();
 
         $this->_server = xmlrpc_server_create();
 
         foreach ($GLOBALS['registry']->listMethods() as $method) {
-            xmlrpc_server_register_method($this->_server, str_replace('/', '.', $method), array('Horde_RPC_xmlrpc', '_dispatcher'));
+            xmlrpc_server_register_method($this->_server, str_replace('/', '.', $method), array('Horde_Rpc_Xmlrpc', '_dispatcher'));
         }
     }
 
@@ -122,7 +120,7 @@ class Horde_RPC_xmlrpc extends Horde_RPC {
             $options = array_merge($options, $GLOBALS['conf']['http']['proxy']);
         }
 
-        require_once 'HTTP/Request.php';
+        /*@TODO Use Horde_Http_Request */
         $http = new HTTP_Request($url, $options);
         if (!empty($language)) {
             $http->addHeader('Accept-Language', $language);
index 45a4782..7517c75 100644 (file)
@@ -6,7 +6,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
  <name>Rpc</name>
  <channel>pear.horde.org</channel>
  <summary>Horde RPC API</summary>
- <description>The Horde_RPC:: class provides a common abstracted interface to
+ <description>The Horde_Rpc:: class provides a common abstracted interface to
 various remote methods of accessing Horde functionality.
  </description>
  <lead>
@@ -42,6 +42,7 @@ various remote methods of accessing Horde functionality.
       <dir name="Syncml">
        <file name="Wbxml.php" role="php" />
       </dir> <!-- /lib/Horde/Rpc/Syncml -->
+      <file name="Exception.php" role="php" />
       <file name="Jsonrpc.php" role="php" />
       <file name="Phpgw.php" role="php" />
       <file name="Soap.php" role="php" />
@@ -77,30 +78,15 @@ various remote methods of accessing Horde functionality.
  </dependencies>
  <phprelease>
   <filelist>
-   <install name="lib/Horde/Rpc/Syncml/Wbxml.php" as="Horde/Rpc/Syncml/Wbxml.php" />
+   <install name="lib/Horde/Rpc/Exception.php" as="Horde/Rpc/Exception.php" />
    <install name="lib/Horde/Rpc/Jsonrpc.php" as="Horde/Rpc/Jsonrpc.php" />
    <install name="lib/Horde/Rpc/Phpgw.php" as="Horde/Rpc/Phpgw.php" />
    <install name="lib/Horde/Rpc/Soap.php" as="Horde/Rpc/Soap.php" />
+   <install name="lib/Horde/Rpc/Syncml/Wbxml.php" as="Horde/Rpc/Syncml/Wbxml.php" />
    <install name="lib/Horde/Rpc/Syncml.php" as="Horde/Rpc/Syncml.php" />
    <install name="lib/Horde/Rpc/Webdav.php" as="Horde/Rpc/Webdav.php" />
    <install name="lib/Horde/Rpc/Xmlrpc.php" as="Horde/Rpc/Xmlrpc.php" />
    <install name="lib/Horde/Rpc.php" as="Horde/Rpc.php" />
   </filelist>
  </phprelease>
- <changelog>
-  <release>
-   <version>
-    <release>0.0.1</release>
-    <api>0.0.1</api>
-   </version>
-   <stability>
-    <release>beta</release>
-    <api>beta</api>
-   </stability>
-   <date>2003-11-25</date>
-   <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
-   <notes>Initial release as a Horde package
-   </notes>
-  </release>
- </changelog>
 </package>