[ Index ]

PHP Cross Reference of JPSpan 0.4 (beta)

title

Body

[close]

/JPSpan/ -> Serializer.php (summary)

Library for serializing PHP variables into Javascript for use with Javascript eval()

File Size: 568 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 11 classes

JPSpan_Serializer:: (3 methods):
  serialize()
  addType()
  JPSpan_getTmpVar()

JPSpan_RootElement:: (2 methods):
  JPSpan_RootElement()
  generate()

JPSpan_SerializedElement:: (4 methods):
  setValue()
  setTmpVar()
  getReturn()
  generate()

JPSpan_SerializedString:: (1 method):
  generate()

JPSpan_SerializedBoolean:: (1 method):
  generate()

JPSpan_SerializedInteger:: (1 method):
  generate()

JPSpan_SerializedFloat:: (1 method):
  generate()

JPSpan_SerializedNull:: (1 method):
  generate()

JPSpan_SerializedArray:: (2 methods):
  setValue()
  generate()

JPSpan_SerializedObject:: (4 methods):
  setValue()
  setChildValues()
  generate()
  generateChildren()

JPSpan_SerializedError:: (4 methods):
  setValue()
  setTmpVar()
  getReturn()
  generate()


Class: JPSpan_Serializer  - X-Ref

Serializes PHP data types into a JavaScript string containing an Function
object for use with eval()<br>
Based on Frederic Saunier's JSserializerCLASS<br/>
Example:
<pre>
$myVar = 'Hello World!';
echo JPSpan_Serializer::serialize($myVar);
// Displays: new Function("var t1 = \'Hello World!\';return t1;");
</pre>
Use in Javascript would be;
<pre>
var data_serialized = 'new Function("var t1 = \'Hello World!\';return t1;");';
var data_func = eval(data_serialized);
var data = data_func(); // data now contains string: Hello World!
</pre>

serialize($data)   X-Ref
Serializes a PHP data structure into Javascript

access: public
param: mixed PHP data structure
return: string data as Javascript

addType($type,$class,$file=NULL)   X-Ref
Adds an entry to the type map

access: public
param: string name of type
param: string name of PHP class to map type to
param: string (optional) filename where class can be found
return: void

JPSpan_getTmpVar($refresh = FALSE)   X-Ref
No description

Class: JPSpan_RootElement  - X-Ref

Wraps the generated JavaScript in an anonymous function

JPSpan_RootElement($data)   X-Ref

access: protected
param: mixed data to be serialized

generate(&$code)   X-Ref
Triggers code generation for child data structure then wraps
in anonymous function

access: protected
param: CodeWriter
return: void

Class: JPSpan_SerializedElement  - X-Ref

Base of class hierarchy for generating Javascript

setValue($value)   X-Ref
Sets the value of the element

access: protected
param: mixed
return: void

setTmpVar()   X-Ref
Sets the temporary variable name

access: protected
return: void

getReturn()   X-Ref
JavaScript string to return if this is the root data element
Called from JPSpan_RootElement::generate

access: protected
return: string

generate(&$code)   X-Ref
Template method for generating code

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedString  - X-Ref

Generates the representation of a string in Javascript

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedBoolean  - X-Ref

Generates the representation of a boolean value in Javascript

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedInteger  - X-Ref

Generates the representation of an integer value in Javascript

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedFloat  - X-Ref

Generates the representation of a float value in Javascript

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedNull  - X-Ref

Generates the representation of a null value in Javascript

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedArray  - X-Ref

Generates the representation of an array in Javascript

setValue($value)   X-Ref

access: protected
param: mixed
return: void

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedObject  - X-Ref

Generates the representation of an object in Javascript

setValue($value)   X-Ref

access: protected
param: mixed
return: void

setChildValues($value)   X-Ref
Called from setValue. Sets the value of all children of
an object

access: protected
param: mixed value
return: void

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void

generateChildren(&$code)   X-Ref
Called from generate. Invokes generate on each child
of the object

access: protected
param: JPSpan_CodeWriter
return: void

Class: JPSpan_SerializedError  - X-Ref

Generates the representation of a JPSpan_Error object.
Note that you can only generate a single error and that it will
erase all other generated code (the first error in a data structure
will be that which be generated)

setValue($error)   X-Ref

access: protected
param: mixed
return: void

setTmpVar()   X-Ref
Conform to interface

access: protected
return: void

getReturn()   X-Ref
Errors do no return - exception thrown
@ return string empty

access: protected

generate(&$code)   X-Ref

access: protected
param: JPSpan_CodeWriter
return: void



Generated: Fri Nov 26 11:42:46 2004 Cross-referenced by PHPXref 0.6