From: João <lv...@us...> - 2008-06-22 04:09:18
|
Update of /cvsroot/os-sim/ossim-gsoc2008/include/xajax5/xajax_core/plugin_layer/support In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv2565/include/xajax5/xajax_core/plugin_layer/support Added Files: xajaxCallableObject.inc.php xajaxEvent.inc.php xajaxUserFunction.inc.php Log Message: Included missing xajax5 files --- NEW FILE: xajaxCallableObject.inc.php --- <?php /* File: xajaxCallableObject.inc.php Contains the xajaxCallableObject class Title: xajaxCallableObject class Please see <copyright.inc.php> for a detailed description, copyright and license information. */ /* @package xajax @version $Id: xajaxCallableObject.inc.php,v 1.1 2008/06/20 20:47:08 lvwr Exp $ @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson @license http://www.xajaxproject.org/bsd_license.txt BSD License */ /* Class: xajaxCallableObject A class that stores a reference to an object whose methods can be called from the client via a xajax request. <xajax> will call <xajaxCallableObject->generateClientScript> so that stub functions can be generated and sent to the browser. */ class xajaxCallableObject { /* Object: obj A reference to the callable object. */ var $obj; /* Array: aConfiguration An associative array that will contain configuration options for zero or more of the objects methods. These configuration options will define the call options for each request. The call options will be passed to the client browser when the function stubs are generated. */ var $aConfiguration; /* Function: xajaxCallableObject Constructs and initializes the <xajaxCallableObject> obj - (object): The object to reference. */ function xajaxCallableObject(&$obj) { $this->obj =& $obj; $this->aConfiguration = array(); } /* Function: getName Returns the name of this callable object. This is typically the class name of the object. */ function getName() { return get_class($this->obj); } /* Function: configure Used to set configuration options / call options for each method. sMethod - (string): The name of the method. sName - (string): The name of the configuration option. sValue - (string): The value to be set. */ function configure($sMethod, $sName, $sValue) { $sMethod = strtolower($sMethod); if (false == isset($this->aConfiguration[$sMethod])) $this->aConfiguration[$sMethod] = array(); $this->aConfiguration[$sMethod][$sName] = $sValue; } /* Function: generateRequests Produces an array of <xajaxRequest> objects, one for each method exposed by this callable object. sXajaxPrefix - (string): The prefix to be prepended to the javascript function names; this will correspond to the name used for the function stubs that are generated by the <xajaxCallableObject->generateClientScript> call. */ function generateRequests($sXajaxPrefix) { $aRequests = array(); $sClass = get_class($this->obj); foreach (get_class_methods($this->obj) as $sMethodName) { $bInclude = true; // exclude magic __call method if ("__call" == $sMethodName) $bInclude = false; // exclude constructor if ($sClass == $sMethodName) $bInclude = false; if ($bInclude) $aRequests[strtolower($sMethodName)] =& new xajaxRequest("{$sXajaxPrefix}{$sClass}.{$sMethodName}"); } return $aRequests; } /* Function: generateClientScript Called by <xajaxCallableObject->generateClientScript> while <xajax> is generating the javascript to be sent to the browser. sXajaxPrefix - (string): The prefix to be prepended to the javascript function names. */ function generateClientScript($sXajaxPrefix) { $sClass = get_class($this->obj); echo "{$sXajaxPrefix}{$sClass} = {};\n"; foreach (get_class_methods($this->obj) as $sMethodName) { $bInclude = true; // exclude magic __call method if ("__call" == $sMethodName) $bInclude = false; // exclude constructor if ($sClass == $sMethodName) $bInclude = false; if ($bInclude) { echo "{$sXajaxPrefix}{$sClass}.{$sMethodName} = function() { "; echo "return xajax.request( "; echo "{ xjxcls: '{$sClass}', xjxmthd: '{$sMethodName}' }, "; echo "{ parameters: arguments"; $sSeparator = ", "; if (isset($this->aConfiguration['*'])) foreach ($this->aConfiguration['*'] as $sKey => $sValue) echo "{$sSeparator}{$sKey}: {$sValue}"; if (isset($this->aConfiguration[strtolower($sMethodName)])) foreach ($this->aConfiguration[strtolower($sMethodName)] as $sKey => $sValue) echo "{$sSeparator}{$sKey}: {$sValue}"; echo " } ); "; echo "};\n"; } } } /* Function: isClass Determins if the specified class name matches the class name of the object referenced by <xajaxCallableObject->obj>. sClass - (string): The name of the class to check. Returns: boolean - True of the specified class name matches the class of the object being referenced; false otherwise. */ function isClass($sClass) { return is_a($this->obj, $sClass); } /* Function: hasMethod Determines if the specified method name is one of the methods of the object referenced by <xajaxCallableObject->obj>. sMethod - (object): The name of the method to check. Returns: boolean - True of the referenced object contains the specified method, false otherwise. */ function hasMethod($sMethod) { return method_exists($this->obj, $sMethod) || method_exists($this->obj, "__call"); } /* Function: call Call the specified method of the object being referenced using the specified array of arguments. sMethod - (string): The name of the method to call. aArgs - (array): The arguments to pass to the method. */ function call($sMethod, $aArgs) { $objResponseManager =& xajaxResponseManager::getInstance(); $objResponseManager->append( call_user_func_array( array(&$this->obj, $sMethod), $aArgs ) ); } } --- NEW FILE: xajaxUserFunction.inc.php --- <?php /* File: xajaxUserFunction.inc.php Contains the xajaxUserFunction class Title: xajaxUserFunction class Please see <copyright.inc.php> for a detailed description, copyright and license information. */ /* @package xajax @version $Id: xajaxUserFunction.inc.php,v 1.1 2008/06/20 20:47:08 lvwr Exp $ @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson @license http://www.xajaxproject.org/bsd_license.txt BSD License */ /* Class: xajaxUserFunction Construct instances of this class to define functions that will be registered with the <xajax> request processor. This class defines the parameters that are needed for the definition of a xajax enabled function. While you can still specify functions by name during registration, it is advised that you convert to using this class when you wish to register external functions or to specify call options as well. */ class xajaxUserFunction { /* String: sAlias An alias to use for this function. This is useful when you want to call the same xajax enabled function with a different set of call options from what was already registered. */ var $sAlias; /* Object: uf A string or array which defines the function to be registered. */ var $uf; /* String: sInclude The path and file name of the include file that contains the function. */ var $sInclude; /* Array: aConfiguration An associative array containing call options that will be sent to the browser curing client script generation. */ var $aConfiguration; /* Function: xajaxUserFunction Constructs and initializes the <xajaxUserFunction> object. $uf - (mixed): A function specification in one of the following formats: - a three element array: (string) Alternate function name: when a method of a class has the same name as another function in the system, you can provide an alias to help avoid collisions. (object or class name) Class: the name of the class or an instance of the object which contains the function to be called. (string) Method: the name of the method that will be called. - a two element array: (object or class name) Class: the name of the class or an instance of the object which contains the function to be called. (string) Method: the name of the method that will be called. - a string: the name of the function that is available at global scope (not in a class. $sInclude - (string, optional): The path and file name of the include file that contains the class or function to be called. $aConfiguration - (array, optional): An associative array of call options that will be used when sending the request from the client. Examples: $myFunction = array('alias', 'myClass', 'myMethod'); $myFunction = array('alias', &$myObject, 'myMethod'); $myFunction = array('myClass', 'myMethod'); $myFunction = array(&$myObject, 'myMethod'); $myFunction = 'myFunction'; $myUserFunction = new xajaxUserFunction($myFunction, 'myFile.inc.php', array( 'method' => 'get', 'mode' => 'synchronous' )); $xajax->register(XAJAX_FUNCTION, $myUserFunction); */ function xajaxUserFunction($uf, $sInclude=NULL, $aConfiguration=array()) { $this->sAlias = ''; $this->uf =& $uf; $this->sInclude = $sInclude; $this->aConfiguration = array(); foreach ($aConfiguration as $sKey => $sValue) $this->configure($sKey, $sValue); if (is_array($this->uf) && 2 < count($this->uf)) { $this->sAlias = $this->uf[0]; $this->uf = array_slice($this->uf, 1); } //SkipDebug if (is_array($this->uf) && 2 != count($this->uf)) trigger_error( 'Invalid function declaration for xajaxUserFunction.', E_USER_ERROR ); //EndSkipDebug } /* Function: getName Get the name of the function being referenced. Returns: string - the name of the function contained within this object. */ function getName() { // Do not use sAlias here! if (is_array($this->uf)) return $this->uf[1]; return $this->uf; } /* Function: configure Call this to set call options for this instance. */ function configure($sName, $sValue) { if ('alias' == $sName) $this->sAlias = $sValue; else $this->aConfiguration[$sName] = $sValue; } /* Function: generateRequest Constructs and returns a <xajaxRequest> object which is capable of generating the javascript call to invoke this xajax enabled function. */ function generateRequest($sXajaxPrefix) { $sAlias = $this->getName(); if (0 < strlen($this->sAlias)) $sAlias = $this->sAlias; return new xajaxRequest("{$sXajaxPrefix}{$sAlias}"); } /* Function: generateClientScript Called by the <xajaxPlugin> that is referencing this function reference during the client script generation phase. This function will generate the javascript function stub that is sent to the browser on initial page load. */ function generateClientScript($sXajaxPrefix) { $sFunction = $this->getName(); $sAlias = $sFunction; if (0 < strlen($this->sAlias)) $sAlias = $this->sAlias; echo "{$sXajaxPrefix}{$sAlias} = function() { "; echo "return xajax.request( "; echo "{ xjxfun: '{$sFunction}' }, "; echo "{ parameters: arguments"; $sSeparator = ", "; foreach ($this->aConfiguration as $sKey => $sValue) echo "{$sSeparator}{$sKey}: {$sValue}"; echo " } ); "; echo "};\n"; } /* Function: call Called by the <xajaxPlugin> that references this function during the request processing phase. This function will call the specified function, including an external file if needed and passing along the specified arguments. */ function call($aArgs=array()) { $objResponseManager =& xajaxResponseManager::getInstance(); if (NULL != $this->sInclude) { ob_start(); require_once $this->sInclude; $sOutput = ob_get_clean(); //SkipDebug if (0 < strlen($sOutput)) { $sOutput = 'From include file: ' . $this->sInclude . ' => ' . $sOutput; $objResponseManager->debug($sOutput); } //EndSkipDebug } $mFunction = $this->uf; $objResponseManager->append(call_user_func_array($mFunction, $aArgs)); } } ?> --- NEW FILE: xajaxEvent.inc.php --- <?php /* File: xajaxEvent.inc.php Definition of the xajax Event object. Title: xajaxEvent Please see <copyright.inc.php> for a detailed description, copyright and license information. */ /* @package xajax @version $Id: xajaxEvent.inc.php,v 1.1 2008/06/20 20:47:08 lvwr Exp $ @copyright Copyright (c) 2005-2006 by Jared White & J. Max Wilson @license http://www.xajaxproject.org/bsd_license.txt BSD License */ // require_once is necessary here as the function plugin also includes this //SkipAIO require_once dirname(__FILE__) . '/xajaxUserFunction.inc.php'; //EndSkipAIO /* Class: xajaxEvent A container class which holds a reference to handler functions and configuration options associated with a registered event. */ class xajaxEvent { /* String: sName The name of the event. */ var $sName; /* Array: aConfiguration Configuration / call options to be used when initiating a xajax request to trigger this event. */ var $aConfiguration; /* Array: aHandlers A list of <xajaxUserFunction> objects associated with this registered event. Each of these functions will be called when the event is triggered. */ var $aHandlers; /* Function: xajaxEvent Construct and initialize this <xajaxEvent> object. */ function xajaxEvent($sName) { $this->sName = $sName; $this->aConfiguration = array(); $this->aHandlers = array(); } /* Function: getName Returns the name of the event. Returns: string - the name of the event. */ function getName() { return $this->sName; } /* Function: configure Sets/stores configuration options that will be used when generating the client script that is sent to the browser. */ function configure($sName, $mValue) { $this->aConfiguration[$sName] = $mValue; } /* Function: addHandler Adds a <xajaxUserFunction> object to the list of handlers that will be fired when the event is triggered. */ function addHandler(&$xuf) { $this->aHandlers[] =& $xuf; } /* Function: generateRequest Generates a <xajaxRequest> object that corresponds to the event so that the client script can easily invoke this event. sXajaxPrefix - (string): The prefix that will be prepended to the client script stub function associated with this event. sEventPrefix - (string): The prefix prepended to the client script function stub and <xajaxRequest> script. */ function generateRequest($sXajaxPrefix, $sEventPrefix) { $sEvent = $this->sName; return new xajaxRequest("{$sXajaxPrefix}{$sEventPrefix}{$sEvent}"); } /* Function: generateClientScript Generates a block of javascript code that declares a stub function that can be used to easily trigger the event from the browser. */ function generateClientScript($sXajaxPrefix, $sEventPrefix) { $sMode = ''; $sMethod = ''; if (isset($this->aConfiguration['mode'])) $sMode = $this->aConfiguration['mode']; if (isset($this->aConfiguration['method'])) $sMethod = $this->aConfiguration['method']; if (0 < strlen($sMode)) $sMode = ", mode: '{$sMode}'"; if (0 < strlen($sMethod)) $sMethod = ", method: '{$sMethod}'"; $sEvent = $this->sName; echo "{$sXajaxPrefix}{$sEventPrefix}{$sEvent} = function() { return xajax.request( { xjxevt: '{$sEvent}' }, { parameters: arguments{$sMode}{$sMethod} } ); };\n"; } /* Function: fire Called by the <xajaxEventPlugin> when the event has been triggered. */ function fire($aArgs) { $objResponseManager =& xajaxResponseManager::getInstance(); foreach (array_keys($this->aHandlers) as $sKey) $this->aHandlers[$sKey]->call($aArgs); } } |