From: Chuck Hagenbuch Date: Fri, 12 Jun 2009 20:06:53 +0000 (-0400) Subject: add a Horde_Rpc_Exception class; start PHP 5 code cleanup X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2034451a4a82bccd119fa5b2816785b4589337a6;p=horde.git add a Horde_Rpc_Exception class; start PHP 5 code cleanup --- diff --git a/framework/Rpc/lib/Horde/Rpc.php b/framework/Rpc/lib/Horde/Rpc.php index 0aa772106..fe2dddac7 100644 --- a/framework/Rpc/lib/Horde/Rpc.php +++ b/framework/Rpc/lib/Horde/Rpc.php @@ -1,6 +1,6 @@ - * $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'))); * * - * $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 @@ -26,10 +24,10 @@ * * @author Jan Schneider * @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 index 000000000..84b26ce36 --- /dev/null +++ b/framework/Rpc/lib/Horde/Rpc/Exception.php @@ -0,0 +1,4 @@ + - * @author Jan Schneider - * @since Horde 3.2 - * @package Horde_RPC + * @author Joey Hewitt + * @author Jan Schneider + * @since Horde 3.2 + * @category Horde + * @package Horde_Rpc */ /** @@ -22,11 +21,12 @@ * 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); diff --git a/framework/Rpc/lib/Horde/Rpc/Phpgw.php b/framework/Rpc/lib/Horde/Rpc/Phpgw.php index 7bee4be37..1bb0b9e77 100644 --- a/framework/Rpc/lib/Horde/Rpc/Phpgw.php +++ b/framework/Rpc/lib/Horde/Rpc/Phpgw.php @@ -1,18 +1,19 @@ - * @since Horde 3.2 - * @package Horde_RPC + * @author Michael Braun + * @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); diff --git a/framework/Rpc/lib/Horde/Rpc/Soap.php b/framework/Rpc/lib/Horde/Rpc/Soap.php index 72805424e..d0ac77dab 100644 --- a/framework/Rpc/lib/Horde/Rpc/Soap.php +++ b/framework/Rpc/lib/Horde/Rpc/Soap.php @@ -1,6 +1,6 @@ * @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. diff --git a/framework/Rpc/lib/Horde/Rpc/Syncml.php b/framework/Rpc/lib/Horde/Rpc/Syncml.php index 87494aef5..0696a7b03 100644 --- a/framework/Rpc/lib/Horde/Rpc/Syncml.php +++ b/framework/Rpc/lib/Horde/Rpc/Syncml.php @@ -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 * @author Anthony Mills * @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. diff --git a/framework/Rpc/lib/Horde/Rpc/Syncml/Wbxml.php b/framework/Rpc/lib/Horde/Rpc/Syncml/Wbxml.php index 28b6203bf..a0d5ad0af 100644 --- a/framework/Rpc/lib/Horde/Rpc/Syncml/Wbxml.php +++ b/framework/Rpc/lib/Horde/Rpc/Syncml/Wbxml.php @@ -1,13 +1,8 @@ * @author Anthony Mills * @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. * diff --git a/framework/Rpc/lib/Horde/Rpc/Webdav.php b/framework/Rpc/lib/Horde/Rpc/Webdav.php index ea1d7629d..36f786201 100644 --- a/framework/Rpc/lib/Horde/Rpc/Webdav.php +++ b/framework/Rpc/lib/Horde/Rpc/Webdav.php @@ -1,10 +1,8 @@ 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; diff --git a/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php b/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php index d1dca9527..461f5137a 100644 --- a/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php +++ b/framework/Rpc/lib/Horde/Rpc/Xmlrpc.php @@ -1,10 +1,8 @@ * @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); diff --git a/framework/Rpc/package.xml b/framework/Rpc/package.xml index 45a478289..7517c755e 100644 --- a/framework/Rpc/package.xml +++ b/framework/Rpc/package.xml @@ -6,7 +6,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> Rpc pear.horde.org Horde RPC API - The Horde_RPC:: class provides a common abstracted interface to + The Horde_Rpc:: class provides a common abstracted interface to various remote methods of accessing Horde functionality. @@ -42,6 +42,7 @@ various remote methods of accessing Horde functionality. + @@ -77,30 +78,15 @@ various remote methods of accessing Horde functionality. - + + - - - - 0.0.1 - 0.0.1 - - - beta - beta - - 2003-11-25 - LGPL - Initial release as a Horde package - - -