xajax.inc.php

Main xajax class and setup file.

Summary
xajax.inc.phpMain xajax class and setup file.
xajax classPlease see copyright.inc.php for a detailed description, copyright and license information.
Standard Definitions
Variables
XAJAX_DEFAULT_CHAR_ENCODINGDefault character encoding used by both the xajax and xajaxResponse classes.
XAJAX_PROCESSING_EVENTString: XAJAX_PROCESSING_EVENT_BEFORE String: XAJAX_PROCESSING_EVENT_AFTER String: XAJAX_PROCESSING_EVENT_INVALID
xajaxThe xajax class uses a modular plug-in system to facilitate the processing of special Ajax requests made by a PHP page.
Variables
aSettingsThis array is used to store all the configuration settings that are set during the run of the script.
bErrorHandlerThis is a configuration setting that the main xajax object tracks.
aProcessingEventsStores the processing event handlers that have been assigned during this run of the script.
bExitAllowedA configuration option that is tracked by the main <xajax>object.
bCleanBufferA configuration option that is tracked by the main xajax object.
sLogFileA configuration setting tracked by the main xajax object.
sCoreIncludeOutputThis is populated with any errors or warnings produced while including the xajax core components.
objPluginManagerThis stores a reference to the global xajaxPluginManager
objArgumentManagerStores a reference to the global xajaxArgumentManager
objResponseManagerStores a reference to the global xajaxResponseManager
objLanguageManagerStores a reference to the global xajaxLanguageManager
Functions
xajaxConstructs a xajax instance and initializes the plugin system.
__sleep
__wakeup
getGlobalResponseReturns the xajaxResponse object preconfigured with the encoding and entity settings from this instance of xajax.
getVersion
registerCall this function to register request handlers, including functions, callable objects and events.
configureCall this function to set options that will effect the processing of xajax requests.
configureManySet an array of configuration options.
getConfigurationGet the current value of a configuration setting that was previously set via xajax->configure or xajax->configureMany
canProcessRequestDetermines if a call is a xajax request or a page load request.
processRequestIf this is a xajax request (see <xajax->canProcessRequest>), call the requested PHP function, build the response and send it back to the browser.
printJavascriptPrints the xajax Javascript header and wrapper code into your page.
getJavascriptSee xajax->printJavascript for more information.
autoCompressJavascriptCreates a new xajax_core, xajax_debug, etc...
_detectURIReturns the current requests URL based upon the SERVER vars.
setCharEncodingSets the character encoding that will be used for the HTTP output.
getCharEncodingReturns the current character encoding.
setFlagsSets a series of flags.
setFlagSets a single flag (boolean true or false).
getFlagReturns the current value of the flag.
setRequestURISets the URI to which requests will be sent.
getRequestURI
setDefaultModeSets the default mode for requests from the browser.
getDefaultModeGet the default request mode that will be used by the browser for submitting requests to the server.
setDefaultMethod
getDefaultMethodGets the default method for making xajax requests.
setWrapperPrefixSets the prefix that will be prepended to the javascript wrapper functions.
getWrapperPrefixGets the current javascript wrapper prefix.
setLogFileSpecifies a log file that will be written to by xajax during a request.
getLogFileReturns the current log file path.
registerFunctionRegisters a PHP function or method with the xajax request processor.
registerCallableObjectRegisters an object whose methods will be searched for a match to the incoming request.
registerEventAssigns a callback function with the specified xajax event.
Available events:
Global functions

xajax class

Please see copyright.inc.php for a detailed description, copyright and license information.

Standard Definitions

Summary
Variables
XAJAX_DEFAULT_CHAR_ENCODINGDefault character encoding used by both the xajax and xajaxResponse classes.
XAJAX_PROCESSING_EVENTString: XAJAX_PROCESSING_EVENT_BEFORE String: XAJAX_PROCESSING_EVENT_AFTER String: XAJAX_PROCESSING_EVENT_INVALID

Variables

XAJAX_DEFAULT_CHAR_ENCODING

if (
   !defined ('XAJAX_DEFAULT_CHAR_ENCODING')
) define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8')

Default character encoding used by both the xajax and xajaxResponse classes.

XAJAX_PROCESSING_EVENT

if (
   !defined ('XAJAX_PROCESSING_EVENT')
) define ('XAJAX_PROCESSING_EVENT', 'xajax processing event')

String: XAJAX_PROCESSING_EVENT_BEFORE String: XAJAX_PROCESSING_EVENT_AFTER String: XAJAX_PROCESSING_EVENT_INVALID

Identifiers used to register processing events.  Processing events are essentially hooks into the xajax core that can be used to add functionality into the request processing sequence.

xajax

The xajax class uses a modular plug-in system to facilitate the processing of special Ajax requests made by a PHP page.  It generates Javascript that the page must include in order to make requests.  It handles the output of response commands (see <xajaxResponse>).  Many flags and settings can be adjusted to effect the behavior of the xajax class as well as the client-side javascript.

Summary
Variables
aSettingsThis array is used to store all the configuration settings that are set during the run of the script.
bErrorHandlerThis is a configuration setting that the main xajax object tracks.
aProcessingEventsStores the processing event handlers that have been assigned during this run of the script.
bExitAllowedA configuration option that is tracked by the main <xajax>object.
bCleanBufferA configuration option that is tracked by the main xajax object.
sLogFileA configuration setting tracked by the main xajax object.
sCoreIncludeOutputThis is populated with any errors or warnings produced while including the xajax core components.
objPluginManagerThis stores a reference to the global xajaxPluginManager
objArgumentManagerStores a reference to the global xajaxArgumentManager
objResponseManagerStores a reference to the global xajaxResponseManager
objLanguageManagerStores a reference to the global xajaxLanguageManager
Functions
xajaxConstructs a xajax instance and initializes the plugin system.
__sleep
__wakeup
getGlobalResponseReturns the xajaxResponse object preconfigured with the encoding and entity settings from this instance of xajax.
getVersion
registerCall this function to register request handlers, including functions, callable objects and events.
configureCall this function to set options that will effect the processing of xajax requests.
configureManySet an array of configuration options.
getConfigurationGet the current value of a configuration setting that was previously set via xajax->configure or xajax->configureMany
canProcessRequestDetermines if a call is a xajax request or a page load request.
processRequestIf this is a xajax request (see <xajax->canProcessRequest>), call the requested PHP function, build the response and send it back to the browser.
printJavascriptPrints the xajax Javascript header and wrapper code into your page.
getJavascriptSee xajax->printJavascript for more information.
autoCompressJavascriptCreates a new xajax_core, xajax_debug, etc...
_detectURIReturns the current requests URL based upon the SERVER vars.
setCharEncodingSets the character encoding that will be used for the HTTP output.
getCharEncodingReturns the current character encoding.
setFlagsSets a series of flags.
setFlagSets a single flag (boolean true or false).
getFlagReturns the current value of the flag.
setRequestURISets the URI to which requests will be sent.
getRequestURI
setDefaultModeSets the default mode for requests from the browser.
getDefaultModeGet the default request mode that will be used by the browser for submitting requests to the server.
setDefaultMethod
getDefaultMethodGets the default method for making xajax requests.
setWrapperPrefixSets the prefix that will be prepended to the javascript wrapper functions.
getWrapperPrefixGets the current javascript wrapper prefix.
setLogFileSpecifies a log file that will be written to by xajax during a request.
getLogFileReturns the current log file path.
registerFunctionRegisters a PHP function or method with the xajax request processor.
registerCallableObjectRegisters an object whose methods will be searched for a match to the incoming request.
registerEventAssigns a callback function with the specified xajax event.
Available events:

Variables

aSettings

var $aSettings

This array is used to store all the configuration settings that are set during the run of the script.  This provides a single data store for the settings in case we need to return the value of a configuration option for some reason.

It is advised that individual plugins store a local copy of the settings they wish to track, however, settings are available via a reference to the xajax object using xajax->getConfiguration.

bErrorHandler

var $bErrorHandler

This is a configuration setting that the main xajax object tracks.  It is used to enable an error handler function which will trap php errors and return them to the client as part of the response.  The client can then display the errors to the user if so desired.

aProcessingEvents

var $aProcessingEvents

Stores the processing event handlers that have been assigned during this run of the script.

bExitAllowed

var $bExitAllowed

A configuration option that is tracked by the main <xajax>object.  Setting this to true allows xajax to exit immediatly after processing a xajax request.  If this is set to false, xajax will allow the remaining code and HTML to be sent as part of the response.  Typically this would result in an error, however, a response processor on the client side could be designed to handle this condition.

bCleanBuffer

var $bCleanBuffer

A configuration option that is tracked by the main xajax object.  Setting this to true allows xajax to clear out any pending output buffers so that the xajaxResponse is (virtually) the only output when handling a request.

sLogFile

var $sLogFile

A configuration setting tracked by the main xajax object.  Set the name of the file on the server that you wish to have php error messages written to during the processing of xajax requests.

sCoreIncludeOutput

var $sCoreIncludeOutput

This is populated with any errors or warnings produced while including the xajax core components.  This is useful for debugging core updates.

objPluginManager

var $objPluginManager

This stores a reference to the global xajaxPluginManager

objArgumentManager

var $objArgumentManager

Stores a reference to the global xajaxArgumentManager

objResponseManager

var $objResponseManager

Stores a reference to the global xajaxResponseManager

objLanguageManager

var $objLanguageManager

Stores a reference to the global xajaxLanguageManager

Functions

xajax

function xajax($sRequestURI = null,
$sLanguage = null)

Constructs a xajax instance and initializes the plugin system.

sRequestURI(optional): The <xajax->sRequestURI> to be used for calls back to the server.  If empty, xajax fills in the current URI that initiated this request.

__sleep

function __sleep()

__wakeup

function __wakeup()

getGlobalResponse

function &getGlobalResponse()

Returns the xajaxResponse object preconfigured with the encoding and entity settings from this instance of xajax.  This is used for singleton-pattern response development.

Returns

<xajaxResponse>A xajaxResponse object which can be used to return response commands.  See also the xajaxResponseManager class.

getVersion

function getVersion()

Returns

stringThe current xajax version.

register

function register($sType,
$mArg)

Call this function to register request handlers, including functions, callable objects and events.  New plugins can be added that support additional registration methods and request processors.

$sType(string): Type of request handler being registered; standard options include: XAJAX_FUNCTION: a function declared at global scope.  XAJAX_CALLABLE_OBJECT: an object who’s methods are to be registered.  XAJAX_EVENT: an event which will cause zero or more event handlers to be called.  XAJAX_EVENT_HANDLER: register an event handler function.
$sFunction || $objObject || $sEvent(mixed): when registering a function, this is the name of the function when registering a callable object, this is the object being registered when registering an event or event handler, this is the name of the event

$sIncludeFile || $aCallOptions || $sEventHandler when registering a function, this is the (optional) include file. when registering a callable object, this is an (optional) array of call options for the functions being registered. when registering an event handler, this is the name of the function.

configure

function configure($sName,
$mValue)

Call this function to set options that will effect the processing of xajax requests.  Configuration settings can be specific to the xajax core, request processor plugins and response plugins.

Options include

javascript URI(string): The path to the folder that contains the xajax javascript files.
errorHandler(boolean): true to enable the xajax error handler, see xajax->bErrorHandler
exitAllowed(boolean): true to allow xajax to exit after processing a request.  See xajax->bExitAllowed for more information.

configureMany

function configureMany($aOptions)

Set an array of configuration options.

$aOptions(array): Associative array of configuration settings

getConfiguration

function getConfiguration($sName)

Get the current value of a configuration setting that was previously set via xajax->configure or xajax->configureMany

Returns

$mValue(mixed): The value of the setting if set, null otherwise.

canProcessRequest

function canProcessRequest()

Determines if a call is a xajax request or a page load request.

Return

booleanTrue if this is a xajax request, false otherwise.

processRequest

function processRequest()

If this is a xajax request (see <xajax->canProcessRequest>), call the requested PHP function, build the response and send it back to the browser.

This is the main server side engine for xajax.  It handles all the incoming requests, including the firing of events and handling of the response.  If your RequestURI is the same as your web page, then this function should be called before ANY headers or HTML is output from your script.

This function may exit, if a request is processed.  See <xajax->bAllowExit>

printJavascript

function printJavascript($sJsURI = "",
$aJsFiles = array())

Prints the xajax Javascript header and wrapper code into your page.  This should be used to print the javascript code between the HEAD and /HEAD tags at the top of the page.

The javascript code output by this function is dependent on the plugins that are included and the functions that are registered.

$sJsURI(string, optional, deprecated): the path to the xajax javascript file(s) This option is deprecated and will be removed in future versions; instead please use xajax->configure with the option name ‘javascript URI’
$aJsFiles(array, optional, deprecated): an array of xajax javascript files that will be loaded via SCRIPT tags.  This option is deprecated and will be removed in future versions; please use xajax->configure with the option name ‘javascript files’ instead.

getJavascript

function getJavascript($sJsURI = '',
$aJsFiles = array())

See xajax->printJavascript for more information.

autoCompressJavascript

function autoCompressJavascript($sJsFullFilename = NULL,
$bAlways = false)

Creates a new xajax_core, xajax_debug, etc... file out of the _uncompressed file with a similar name.  This strips out the comments and extraneous whitespace so the file is as small as possible without modifying the function of the code.

sJsFullFilename(string): The relative path and name of the file to be compressed.
bAlways(boolean): Compress the file, even if it already exists.

_detectURI

function _detectURI()

Returns the current requests URL based upon the SERVER vars.

Returns

stringThe URL of the current request.

setCharEncoding

function setCharEncoding($sEncoding)

Sets the character encoding that will be used for the HTTP output.  Typically, you will not need to use this method since the default character encoding can be configured using the constant XAJAX_DEFAULT_CHAR_ENCODING.

sEncoding(string): The encoding to use.
  • examples include (UTF-8, ISO-8859-1)
deprecatedThis function will be removed in future versions.  Please use xajax->configure instead.

getCharEncoding

function getCharEncoding()

Returns the current character encoding.  See also xajax->setCharEncoding and XAJAX_DEFAULT_CHAR_ENCODING

Returns

stringThe character encoding.
deprecatedThis function will be removed in future versions.  Please use xajax->getConfiguration instead.

setFlags

function setFlags($flags)

Sets a series of flags.  See also, xajax->setFlag.

flags(array): An associative array containing the name of the flag and the value to set.
deprecatedThis function will be removed in future versions.  Please use xajax->configureMany instead.

setFlag

function setFlag($name,
$value)

Sets a single flag (boolean true or false).

Available flags are as follows (flag, default value)

  • debug, false
  • verbose, false
  • statusMessages, false
  • waitCursor, true
  • scriptDeferral, false
  • exitAllowed, true
  • errorHandler, false
  • cleanBuffer, false
  • decodeUTF8Input, false
  • outputEntities, false
  • allowBlankResponse, false
  • allowAllResponseTypes, false
  • generateStubs, true
name(string): The name of the flag to set.
value(boolean): The value to set.
deprecatedThis function will be removed in future versions.  Please use xajax->configure instead.

getFlag

function getFlag($name)

Returns the current value of the flag.  See also xajax->setFlag.

name(string): The name of the flag.

Returns

booleanThe value currently associated with the flag.
deprecatedThis function will be removed in future versions.  Instead, use xajax->getConfiguration.

setRequestURI

function setRequestURI($sRequestURI)

Sets the URI to which requests will be sent.

sRequestURI(string): The URI

Note: Usage

$xajax->setRequestURI(“http://www.xajaxproject.org”);

deprecatedThis function will be removed in future versions.  Please use xajax->configure instead.

getRequestURI

function getRequestURI()

Returns

stringThe current request URI that will be configured on the client side.  This is the default URI for all requests made from the current page.  See xajax->setRequestURI.
deprecatedThis function will be removed in future versions.  Please use xajax->getConfiguration instead.

setDefaultMode

function setDefaultMode($sDefaultMode)

Sets the default mode for requests from the browser.

sDefaultMode(string): The mode to set as the default.
  • ’synchronous’
  • ’asynchronous’

Example

$xajax->setDefaultMode(“synchronous”);

deprecatedThis function will be removed in future versions.  Please use xajax->configure instead.

getDefaultMode

function getDefaultMode()

Get the default request mode that will be used by the browser for submitting requests to the server.  See also xajax->setDefaultMode

Returns

stringThe default mode to be used by the browser for each request.
deprecatedThis function will be removed in future versions.  Please use xajax->getConfiguration instead.

setDefaultMethod

function setDefaultMethod($sMethod)

Sets the default method for making xajax requests

sMethod(string): The name of the method.
  • ’GET’
  • ’POST’
deprecatedThis function will be removed in future versions.  Please use xajax->configure instead.

getDefaultMethod

function getDefaultMethod()

Gets the default method for making xajax requests.

Returns

stringThe current method configured.
deprecatedThis function will be removed in future versions.  Please use xajax->getConfiguration instead.

setWrapperPrefix

function setWrapperPrefix($sPrefix)

Sets the prefix that will be prepended to the javascript wrapper functions.  This allows a little flexibility in setting the naming for the wrapper functions.

sPrefix(string): The prefix to be used.
  • default is ‘xajax_’
deprecatedThis function will be removed in future versions.  Please use xajax->configure instead.

getWrapperPrefix

function getWrapperPrefix()

Gets the current javascript wrapper prefix.  See also, xajax->setWrapperPrefix

Returns

stringThe current wrapper prefix.
deprecatedThis function will be removed in future versions.  Please use xajax->getConfiguration instead.

setLogFile

function setLogFile($sFilename)

Specifies a log file that will be written to by xajax during a request.  This is only used by the error handling system at this point.  If you do not invoke this method or you pass in an empty string, then no log file will be written to.

sFilename(string): The full or reletive path to the log file.
deprecatedThis function will be removed in future versions.  Please use xajax->configure instead.

getLogFile

function getLogFile()

Returns the current log file path.  See also xajax->setLogFile.

Returns

stringThe log file path.
deprecatedThis function will be removed in future versions.  Please use xajax->getConfiguration instead.

registerFunction

function registerFunction($mFunction,  
$sIncludeFile = null)

Registers a PHP function or method with the xajax request processor.  This makes the function available to the browser via an asynchronous (or synchronous) javascript call.

mFunction(string or array): The string containing the function name or an array containing the following:
  • (string) The function name as it will be called from javascript.
  • (object, by reference) A reference to an instance of a class containing the specified function.
  • (string) The function as it is found in the class passed in the second parameter.
sIncludeFile(string, optional): The server path to the PHP file to include when calling this function.  This will enable xajax to load only the include file that is needed for this function call, thus reducing server load.

Examples

  • $xajax->registerFunction(“myFunction”);
  • $xajax->registerFunction(array(“myFunctionName”, &$myObject, “myMethod”));
deprecatedThis function will be removed in future versions.  Please use xajax->register instead.

registerCallableObject

function registerCallableObject(&$oObject)

Registers an object whose methods will be searched for a match to the incoming request.  If more than one callable object is registered, the first on that contains the requested method will be used.

oObject(object, by reference): The object whose methods will be registered.
deprecatedThis function will be removed in future versions.  Please use xajax->register instead.

registerEvent

Assigns a callback function with the specified xajax event.  Events are triggered during the processing of a request.

Available events:

  • beforeProcessing: triggered before the request is processed.
  • afterProcessing: triggered after the request is processed.
  • invalidRequest: triggered if no matching function/method is found.
mCallback(function): The function or object callback to be assigned.
sEventName(string): The name of the event.
deprecatedThis function will be removed in future versions.  Please use xajax->register instead.

Global functions

This file contains detailed information regarding the xajax project, current version, copyrights, licnese and documentation.
if (
   !defined ('XAJAX_DEFAULT_CHAR_ENCODING')
) define ('XAJAX_DEFAULT_CHAR_ENCODING', 'utf-8')
Default character encoding used by both the xajax and xajaxResponse classes.
The xajax class uses a modular plug-in system to facilitate the processing of special Ajax requests made by a PHP page.
Collect commands to be sent back to the browser in response to a xajax request.
if (
   !defined ('XAJAX_PROCESSING_EVENT')
) define ('XAJAX_PROCESSING_EVENT', 'xajax processing event')
String: XAJAX_PROCESSING_EVENT_BEFORE String: XAJAX_PROCESSING_EVENT_AFTER String: XAJAX_PROCESSING_EVENT_INVALID
var $aSettings
This array is used to store all the configuration settings that are set during the run of the script.
var $bErrorHandler
This is a configuration setting that the main xajax object tracks.
var $aProcessingEvents
Stores the processing event handlers that have been assigned during this run of the script.
var $bExitAllowed
A configuration option that is tracked by the main <xajax>object.
var $bCleanBuffer
A configuration option that is tracked by the main xajax object.
function xajax($sRequestURI = null,
$sLanguage = null)
Constructs a xajax instance and initializes the plugin system.
var $sLogFile
A configuration setting tracked by the main xajax object.
var $sCoreIncludeOutput
This is populated with any errors or warnings produced while including the xajax core components.
var $objPluginManager
This stores a reference to the global xajaxPluginManager
var $objArgumentManager
Stores a reference to the global xajaxArgumentManager
This class processes the input arguments from the GET or POST data of the request.
var $objResponseManager
Stores a reference to the global xajaxResponseManager
This class stores and tracks the response that will be returned after processing a request.
var $objLanguageManager
Stores a reference to the global xajaxLanguageManager
This class contains the default language (english) and the code used to supply debug and error messages upon request; as well as the code used to load alternate language text as requested via the xajax::configure function.
function __sleep()
function __wakeup()
function &getGlobalResponse()
Returns the xajaxResponse object preconfigured with the encoding and entity settings from this instance of xajax.
function getVersion()
function register($sType,
$mArg)
Call this function to register request handlers, including functions, callable objects and events.
function configure($sName,
$mValue)
Call this function to set options that will effect the processing of xajax requests.
function configureMany($aOptions)
Set an array of configuration options.
function getConfiguration($sName)
Get the current value of a configuration setting that was previously set via xajax->configure or xajax->configureMany
function canProcessRequest()
Determines if a call is a xajax request or a page load request.
function processRequest()
If this is a xajax request (see <xajax->canProcessRequest>), call the requested PHP function, build the response and send it back to the browser.
function printJavascript($sJsURI = "",
$aJsFiles = array())
Prints the xajax Javascript header and wrapper code into your page.
function getJavascript($sJsURI = '',
$aJsFiles = array())
See xajax->printJavascript for more information.
function autoCompressJavascript($sJsFullFilename = NULL,
$bAlways = false)
Creates a new xajax_core, xajax_debug, etc...
function _detectURI()
Returns the current requests URL based upon the SERVER vars.
function setCharEncoding($sEncoding)
Sets the character encoding that will be used for the HTTP output.
function getCharEncoding()
Returns the current character encoding.
function setFlags($flags)
Sets a series of flags.
function setFlag($name,
$value)
Sets a single flag (boolean true or false).
function getFlag($name)
Returns the current value of the flag.
function setRequestURI($sRequestURI)
Sets the URI to which requests will be sent.
function getRequestURI()
function setDefaultMode($sDefaultMode)
Sets the default mode for requests from the browser.
function getDefaultMode()
Get the default request mode that will be used by the browser for submitting requests to the server.
function setDefaultMethod($sMethod)
function getDefaultMethod()
Gets the default method for making xajax requests.
function setWrapperPrefix($sPrefix)
Sets the prefix that will be prepended to the javascript wrapper functions.
function getWrapperPrefix()
Gets the current javascript wrapper prefix.
function setLogFile($sFilename)
Specifies a log file that will be written to by xajax during a request.
function getLogFile()
Returns the current log file path.
function registerFunction($mFunction,  
$sIncludeFile = null)
Registers a PHP function or method with the xajax request processor.
function registerCallableObject(&$oObject)
Registers an object whose methods will be searched for a match to the incoming request.
Close