[geeklog-cvs] Auth_Enterprise/Server AEXMLRPCHandler.class.php,NONE,1.1

tony at iowaoutdoors.org tony at iowaoutdoors.org
Sat Jun 19 16:13:53 EDT 2004


Update of /var/cvs/Auth_Enterprise/Server
In directory www:/tmp/cvs-serv16354

Added Files:
	AEXMLRPCHandler.class.php 
Log Message:
Initial release of Auth_Enterprise XMLRPC support. At this point it should work for all methods since all the hardest case is authenticate which returns a complex data type. Exceptions are quite handled yet.

--- NEW FILE: AEXMLRPCHandler.class.php ---
<?php

/**
* Auth_Enterprise
*
* This source file is subject to version 2.02 of the PHP license, that is bundled with this package
* in the file LICENSE, and is available at through the world-wide-web at
* http://www.php.net/license/2_02.txt. If you did not receive a copy of the PHP license and are
* unable to obtain it through the world-wide-web, please send a note to license at php.net so we can
* mail you a copy immediately.
*
* @author Tony Bibbs <tony at geeklog.net>
* @copyright 2004
* @version $Id: AEXMLRPCHandler.class.php,v 1.1 2004/06/19 20:13:49 tony Exp $
*
*/

/**
* The Auth_Enterprise Server Provider Factory 
*/
require_once 'Auth_Enterprise/Server/AEServerProviderFactory.class.php';

/**
* Auth_Enteprise's XMLRPC Handler
*
* This class is a simple proxy.  All it does is takes Auth_Enterprise request wrapped in XMLPRC and
* calls the method and returns a valid XMLRPC response to the calling application
*
* @author Tony Bibbs <tony at geeklog.net>
* @package net.geeklog.auth_enterprise.server
*
*/
class AEXMLRPCHandler {
    /**
    * Handles all XMLRPC requests made to Auth_Enterprise
    *
    * @author Tony Bibbs <tony at geeklog.net>
    * @access public
    * @param array XMLRPC argument values
    * @return string valid XMLPRC response
    *
    */
    public static function handleRequest($params)
    {
        $methodArgumentMapping = array(
                                       'authenticate' => 2,
                                       'createAccountByAdmin' => 4,
                                       'changePassword' => 2,
                                       'chnagePasswordByAdmin' =>4,
                                       'resetPassword' => 1,
                                       'getUserPrivilegesByAdmin' => 3,
                                       'setUserPrivilegesByAdmin' => 4,
                                       'listAppPrivilegesByAdmin' => 2,
                                       'getUserGroupsByAdmin' => 3,
                                       'setUserGroupsByAdmin' => 4
                                      );
                                      
        // Convert parameters into an array to be sent to
        // the provider method
        foreach ($params->params as $curParam) {
            $fnParams[] = $curParam->scalarval();
        }
        
        // Get provider method to call
        $methodToCall = $fnParams[0];
        
        // Get application ID
        $appId = $fnParams[1];
        
        // Create server provider
        try {
            $serverProvider = AEServerProviderFactory::getProvider($appId);
        } catch (Exception $e) {
            return new XML_RPC_Response(XML_RPC_encode(array(AE_XMLRPC_EXCEPTION,$e)));
        }
        
        // Get the number of arguments the method takes
        $numMethodArgs = $methodArgumentMapping[$methodToCall];
        
        // Call the method.
        try {
            switch ($numMethodArgs) {
                case 1:
                    $retVal = $serverProvider->$methodToCall($fnParams[2]);
                    break;
                case 2:
                    $retVal = $serverProvider->$methodToCall($fnParams[2], $fnParams[3]);
                    break;
                case 3:
                    $retVal = $serverProvider->$methodToCall($fnParams[2], $fnParams[3], $fnParams[4]);
                    break;
                case 4:
                    $retVal = $serverProvider->$methodToCall($fnParams[2], $fnParams[3], $fnParams[4], $fnParams[5]);
            }
        } catch (Exception $e) {
            // Something went wrong, send client an exception (i.e. XMLRPC fault)
            return new XML_RPC_Response(XML_RPC_encode(array(AE_XMLRPC_EXCEPTION,$e)));
        }
        // Because of a PHP5 incompatibility, we must convert any object to arrays before
        // encoding them
        if (is_object($retVal)) {
            $retVal = $retVal->toArray();
        }
        
        return new XML_RPC_Response(XML_RPC_encode($retVal));

    }
    
}

?>



More information about the geeklog-cvs mailing list