InterJinn

Development Framework For PHP

interJinn
Class JinnHttpRequestService (EXPERIMENTAL)

public class JinnHttpRequestService
extends JinnBaseService

This service provides a simple framework for managing XmlHttpRequest (Ajax for those who like hype) semantics as enabled by InterJinn's HttpRequest Javascript library. This service works in close relationship with InterJinn JavaScript's JinnHttpRequest class.

Direct Known Subclasses

Method Summary
public JinnHttpRequestService( )

Default constructor.
public ___jinnConstruct( )

Default constructor.
public string getHttpRequestData( )

Returns the raw unprocessed request data that was set by the requesting client.
public string getHttpRequestDataType( )

Returns the type of request data that was sent by the request client to the handling script.
public mixed getHttpRequestVar( string   $name , mixed   $dValue =null )

Returns the request variable denoted by the given name parameter.
public array getHttpRequestVars( )

Returns the array of all request variables that were set by the requesting client.
public sendResponse( mixed   $data , string   $type =javascript , bool   $purgeBuffers =true , bool   $halt =true )

It is simple enough to send response data to the remote client when all it expects is textual;

Methods Inherited from JinnBaseClassReal
JinnBaseClassReal , ___jinnConstruct , __destruct , applyCallbackRecursively , checkpoint , cleanPath , createClone , error , extractPairs , flattenPath , getBacktrace , getCharset , getCodeRoot , getCompileVar , getCompileVars , getCoreRoot , getFilename , getHttpCookieVar , getHttpCookieVars , getHttpEnvVar , getHttpEnvVars , getHttpGetOrPostVar , getHttpGetVar , getHttpGetVars , getHttpLinkVar , getHttpLinkVars , getHttpPostFile , getHttpPostFiles , getHttpPostOrGetVar , getHttpPostVar , getHttpPostVars , getHttpServerVar , getHttpServerVars , getImageBase , getInterJinnVar , getInterJinnVars , getLanguage , getLanguageDefault , getLibrary , getLibraryRef , getLoadInfo , getPageBase , getPageRoot , getPath , getPathPrefixType , getPrintData , getPrintFlat , getRunMode , getRunUid , getService , getServiceRef , getShellArg , getShellArgc , getShellArgv , getTime , getUniqueId , getVersion , getWebProfilingCategoryColour , getWebProfilingDataColour , getWebProfilingDefaultColour , halt , haltWithProfile , hashAppend , hashKeyDelete , hashKeyExists , hashKeyGet , hashKeyIsSet , hashKeySet , hashPathDelete , hashPathDeleteData , hashPathExists , hashPathGet , hashPathGetData , hashPathIsSet , hashPathSet , hashPathSetData , includeResource , isProfiling , libraryExists , localizeImage , localizePage , localizePath , logData , logFlat , makeRelativePath , markup , multilingualize , multilingualizeRef , normalizeArray , notice , overrideWarning , printData , printFlat , purgeOutputBuffers , redirect , refresh , serviceExists , setInterJinnVar , stripSlashes , stripSlashes_primitive , unwrapIfNecessary , unwrapObject , warning , wrapIfNecessary , wrapObject , xpathExists , xpathGet , xpathGetData , xpathIsSet  

Methods Inherited from JinnBaseClass
JinnBaseClass , ___jinnConstruct  

Methods Inherited from JinnBaseService
JinnBaseService , ___jinnConstruct , allowCopies , postLoadExecute  

Method Details
JinnHttpRequestService

public JinnHttpRequestService ( )

Default constructor.

Source Code
function JinnHttpRequestService()
{
   
$this->___jinnConstruct();
}

___jinnConstruct

public ___jinnConstruct ( )

Default constructor.

Source Code
function ___jinnConstruct()
{
   
parent::___jinnConstruct();

   
$this->requestRaw
       
= isset( $_POST[$this->requestPrefix.'DATA'] )
        ? 
$_POST[$this->requestPrefix.'DATA']
        : 
null;

   
$this->requestDataType
       
= isset( $_POST[$this->requestPrefix.'DATA_TYPE'] )
        ? 
$_POST[$this->requestPrefix.'DATA_TYPE']
        : 
'array';

    if( 
$this->requestRaw !== null )
    {
        if( 
ini_get'magic_quotes_gpc' ) )
        {
           
$this->requestRaw stripSlashes$this->requestRaw );
        }

        if( 
$this->requestDataType == 'array' )
        {
           
$this->requestArray unserialize$this->requestRaw );
        }
    }
}

getHttpRequestData

public string getHttpRequestData ( )

Returns:
The raw unprocessed request data.

Returns the raw unprocessed request data that was set by the requesting client.

Source Code
function getHttpRequestData()
{
    return 
$this->requestRaw;
}

getHttpRequestDataType

public string getHttpRequestDataType ( )

Returns:
The type of request data that was sent.

Returns the type of request data that was sent by the request client to the handling script. This value is used by the service to determine if the request data should be processed into a more palatable form. For instance the most common data type will be array which will enable this service to automatically convert the raw request data into an array which can be accessed via getHttpRequestVars() and getHttpRequestVar().

Source Code
function getHttpRequestDataType()
{
    return 
$this->requestDataType;
}

getHttpRequestVar

public mixed getHttpRequestVar
(
     string      $name ,
     mixed      $dValue = null
)


Parameters:
$name - The name of the desired request variable.
$dValue - The value to return when the desired variable doesn't exist.

Returns:
The named request variable.

Returns the request variable denoted by the given name parameter. Note that the Javascript counterpart serializes Javascript data into PHP data structures (excluding objects) and so the value can be any valid PHP datatype except an object. This method works in harmony with JinnHttpRequest::setVar().

Source Code
function getHttpRequestVar$name$dValue=null )
{
    if( isset( 
$this->requestArray[$name] ) )
    {
        return 
$this->requestArray[$name];
    }

    return 
$dValue;
}

getHttpRequestVars

public array getHttpRequestVars ( )

Returns:
The array of all set request variables.

Returns the array of all request variables that were set by the requesting client. This method works in harmony with JinnHttpRequest::setVar().

Source Code
function getHttpRequestVars()
{
    return 
$this->requestArray;
}

sendResponse

public sendResponse
(
     mixed      $data ,
     string      $type = javascript ,
     bool      $purgeBuffers = true ,
     bool      $halt = true
)


Parameters:
$data - The data to be sent as a response to the remote client.
$type - An optional datatype name to indicate how the data should be sent to the remote client.
$purgeBuffers - Forces all buffers to be purged to prevent any extraneous data being sent to the remote client. This is usually desireable but requires that output buffering be enabled.
$halt - Halts script execution after the response has been sent. This prevents any trailing extraneous data from being sent as part of the response.

It is simple enough to send response data to the remote client when all it expects is textual; however, when other types of responses are expected it can be useful to have the semantics encapsulated for ease of use. For instance the default action is to encode any passed data as a native javascript array declaration which can be eval'd on the remote client and used as one would normally use a Javascript associative array.

Source Code
function sendResponse
$data$type=null$purgeBuffers=true$halt=true )
{
    if( 
$type === null )
    {
       
$type 'javascript';
    }

    if( 
$purgeBuffers )
    {
       
$this->purgeOutputBuffers();
    }

    switch( 
strtolower$type ) )
    {
        case 
'js':
        case 
'javascript':
        {
           
$sJs = &$this->getServiceRef'javascript' );
            echo 
$sJs->createDeclaration$data );

            break;
        }

        default:
        {
            echo 
$data;
        }
    }

    if( 
$halt )
    {
        exit();
    }
}