Constants

MAX_STORED_OBJECTS

MAX_STORED_OBJECTS

the maximum amount of objects stored for reference

Properties

$voConverter

$voConverter : \Amfphp_Core_Common_IVoConverter

converts VOs directly if set, rather than instanciating anonymous classes that are converted later

Type

\Amfphp_Core_Common_IVoConverter

$outBuffer

$outBuffer : String

Type

String — the output stream

$Amf0StoredObjects

$Amf0StoredObjects : array

used for Amf0 references

Type

array

$storedObjects

$storedObjects : array

used for Amf3 references

Type

array

$storedStrings

$storedStrings : array

amf3 references to strings

Type

array

$className2TraitsInfo

$className2TraitsInfo : array

used for traits references. key: class name. value: array(reference id, array(property names))

Type

array

Methods

serialize()

serialize(\Amfphp_Core_Amf_Packet $data) : String

converts from php object to binary

Parameters

\Amfphp_Core_Amf_Packet $data

Returns

String

getOutput()

getOutput() : string

get serialized data output

Returns

string

writeAmf3VectorValue()

writeAmf3VectorValue( $value,  $format)

Writes numeric values for int, uint and double (floating point) vectors to the AMF byte stream.

Parameters

$value
$format

resetReferences()

resetReferences()

initialize reference arrays and counters. Call before writing a body or a header, as the indices are local to each message body or header

writeByte()

writeByte(integer $b)

writeByte writes a singe byte to the output stream 0-255 range

Parameters

integer $b

An int that can be converted to a byte

writeInt()

writeInt(integer $n)

writeInt takes an int and writes it as 2 bytes to the output stream 0-65535 range

Parameters

integer $n

An integer to convert to a 2 byte binary string

writeLong()

writeLong(\long $l)

writeLong takes an int, float or double and converts it to a 4 byte binary string and adds it to the output buffer

Parameters

\long $l

A long to convert to a 4 byte binary string

writeDouble()

writeDouble(double $d)

writeDouble takes a float as the input and writes it to the output stream.

Then if the system is big-endian, it reverses the bytes order because all doubles passed via remoting are passed little-endian.

Parameters

double $d

The double to add to the output buffer

writeUtf()

writeUtf(string $s)

writeUTF takes and input string, writes the length as an int and then appends the string to the output buffer

Parameters

string $s

The string less than 65535 characters to add to the stream

writeLongUtf()

writeLongUtf(string $s)

writeLongUTF will write a string longer than 65535 characters.

It works exactly as writeUTF does except uses a long for the length flag.

Parameters

string $s

A string to add to the byte stream

writeBoolean()

writeBoolean(boolean $d)

writeBoolean writes the boolean code (0x01) and the data to the output stream

Parameters

boolean $d

The boolean value

writeString()

writeString(string $d)

writeString writes the string code (0x02) and the UTF8 encoded string to the output stream.

Note: strings are truncated to 64k max length. Use XML as type to send longer strings

Parameters

string $d

The string data

writeXML()

writeXML(\Amfphp_Core_Amf_Types_Xml $d)

writeXML writes the xml code (0x0F) and the XML string to the output stream Note: strips whitespace

Parameters

\Amfphp_Core_Amf_Types_Xml $d

writeDate()

writeDate(\Amfphp_Core_Amf_Types_Date $d)

writeDate writes the date code (0x0B) and the date value (milliseconds from 1 January 1970) to the output stream, along with an empty unsupported timezone

Parameters

\Amfphp_Core_Amf_Types_Date $d

The date value

writeNumber()

writeNumber(integer $d)

writeNumber writes the number code (0x00) and the numeric data to the output stream All numbers passed through remoting are floats.

Parameters

integer $d

The numeric data

writeNull()

writeNull()

writeNull writes the null code (0x05) to the output stream

writeUndefined()

writeUndefined()

writeUndefined writes the Undefined code (0x06) to the output stream

writeObjectEnd()

writeObjectEnd()

writeObjectEnd writes the object end code (0x009) to the output stream

writeArrayOrObject()

writeArrayOrObject(array $d)

writeArrayOrObject first determines if the PHP array contains all numeric indexes or a mix of keys. Then it either writes the array code (0x0A) or the object code (0x03) and then the associated data.

Parameters

array $d

The php array

writeReference()

writeReference(integer $num)

write reference

Parameters

integer $num

writeObjectFromArray()

writeObjectFromArray(array $d)

writeObjectFromArray handles writing a php array with string or mixed keys. It does not write the object code as that is handled by the writeArrayOrObject and this method is shared with the CustomClass writer which doesn't use the object code.

Parameters

array $d

The php array with string keys

writeAnonymousObject()

writeAnonymousObject(\stdClass $d)

handles writing an anoynous object (stdClass) can also be a reference

Parameters

\stdClass $d

The php object to write

writeTypedObject()

writeTypedObject(object $d)

writeTypedObject takes an instance of a class and writes the variables defined in it to the output stream.

To accomplish this we just blanket grab all of the object vars with get_object_vars, minus the Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE field, whiuch is used as class name

Parameters

object $d

The object to serialize the properties. The deserializer looks for Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE on this object and writes it as the class name.

writeData()

writeData(mixed $d)

writeData checks to see if the type was declared and then either auto negotiates the type or relies on the user defined type to serialize the data into Amf

Parameters

mixed $d

The data

writeAmf3Data()

writeAmf3Data(mixed $d)

write amf 3 data

Parameters

mixed $d

writeAmf3Undefined()

writeAmf3Undefined() : \nothing

Write undefined (Amf3).

Returns

\nothing

writeAmf3Null()

writeAmf3Null() : \nothing

Write NULL (Amf3).

Returns

\nothing

writeAmf3Bool()

writeAmf3Bool(boolean $d) : \nothing

Write a boolean (Amf3).

Parameters

boolean $d

the boolean to serialise

Returns

\nothing

writeAmf3Int()

writeAmf3Int(integer $d) : \nothing

Write an (un-)signed integer (Amf3).

Parameters

integer $d

the integer to serialise

Returns

\nothing

writeAmf3String()

writeAmf3String(string $d) : \The

Write a string (Amf3). Strings are stored in a cache and in case the same string is written again, a reference to the string is sent instead of the string itself.

note: Sending strings larger than 268435455 (2^28-1 byte) will (silently) fail!

note: The string marker is NOT sent here and has to be sent before, if needed.

Parameters

string $d

the string to send

Returns

\The —

reference index inside the lookup table is returned. In case of an empty string which is sent in a special way, NULL is returned.

writeAmf3AnonymousObject()

writeAmf3AnonymousObject(\stdClass $d,  $doReference)

handles writing an anoynous object (stdClass) can also be a reference Also creates a bogus traits entry, as even an anonymous object has traits. In this way a reference to a class trait will have the right id.

Parameters

\stdClass $d

The php object to write

$doReference

writeAmf3Array()

writeAmf3Array(array $d)

write amf3 array

Parameters

array $d

getAmf3Int()

getAmf3Int(integer $d) : string

Return the serialisation of the given integer (Amf3).

note: There does not seem to be a way to distinguish between signed and unsigned integers. This method just sends the lowest 29 bit as-is, and the receiver is responsible to interpret the result as signed or unsigned based on some context.

note: The limit imposed by Amf3 is 29 bit. So in case the given integer is longer than 29 bit, only the lowest 29 bits will be serialised. No error will be logged!

Parameters

integer $d

the integer to serialise

Returns

string

writeAmf3Number()

writeAmf3Number(\number $d)

write Amf3 Number

Parameters

\number $d

writeAmf3Xml()

writeAmf3Xml(\Amfphp_Core_Amf_Types_Xml $d)

write Amfphp_Core_Amf_Types_Xml in amf3

Parameters

\Amfphp_Core_Amf_Types_Xml $d

writeAmf3XmlDocument()

writeAmf3XmlDocument(\Amfphp_Core_Amf_Types_XmlDocument $d)

write Amfphp_Core_Amf_Types_XmlDocument in amf3

Parameters

\Amfphp_Core_Amf_Types_XmlDocument $d

writeAmf3Date()

writeAmf3Date(\Amfphp_Core_Amf_Types_Date $d)

write Amfphp_Core_Amf_Types_Date in amf 3

Parameters

\Amfphp_Core_Amf_Types_Date $d

writeAmf3ByteArray()

writeAmf3ByteArray(\Amfphp_Core_Amf_Types_ByteArray $d)

write Amfphp_Core_Amf_Types_ByteArray in amf3

Parameters

\Amfphp_Core_Amf_Types_ByteArray $d

handleReference()

handleReference(mixed $obj, array $references)

looks if $obj already has a reference. If it does, write it, and return true. If not, add it to the references array.

Depending on whether or not the spl_object_hash function can be used ( available (PHP >= 5.2), and can only be used on an object) things are handled a bit differently:

  • if possible, objects are hashed and the hash is used as a key to the references array. So the array has the structure hash => reference
  • if not, the object is pushed to the references array, and array_search is used. So the array has the structure reference => object. maxing out the number of stored references improves performance(tested with an array of 9000 identical objects). This may be because isset's performance is linked to the size of the array. weird... note on using $references[$count] = &$obj; rather than $references[] = &$obj; the first one is right, the second is not, as with the second one we could end up with the following: some object hash => 0, 0 => array. (it should be 1 => array)

This also means that 2 completely separate instances of a class but with the same values will be written fully twice if we can't use the hash system

Parameters

mixed $obj
array $references

writeAmf3TypedObject()

writeAmf3TypedObject(object $d)

writes a typed object. Type is determined by having an "explicit type" field. If this field is not set, call writeAmf3AnonymousObject write all properties as sealed members.

Parameters

object $d