/usr/share/php/xajax/xajax_core/plugin_layer/support/xajaxCallableObject.inc.php is in php-xajax 0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | <?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 362 2007-05-29 15:32:24Z calltoconstruct $
@copyright Copyright (c) 2005-2007 by Jared White & J. Max Wilson
@copyright Copyright (c) 2008-2009 by Joseph Woolley, Steffen Konerow, 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, __construct, __destruct methods
if (2 < strlen($sMethodName))
if ("__" == substr($sMethodName, 0, 2))
$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)
{
if(get_class($this->obj) === $sClass)
return true;
return false;
}
/*
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
)
);
}
}
|