\AmfphpVoConverter

Converts data from incoming packets with explicit types to Value Objects(Vos), and vice versa for the outgoing packets.

This plugin can be deactivated if the project doesn't use Value Objects.

The AMF deserializer reads a typed AMF object as a stdObj class, and sets the AMF type to a reserved "explicit type" field. This plugin will look at deserialized data and try to convert any such objects to a real Value Object.

It works in the opposite way on the way out: The AMF serializer needs a stdObj class with the explicit type marker set to write a typed AMF object. This plugin will convert any typed PHP objects to a stdObj with the explicit type marker set.

The explicit type marker is defined in Amfphp_Core_Amf_Constants

If after deserialization the Value Object is not found, the object is unmodified and the explicit type marker is left set. If the explicit type marker is already set in an outgoing object, the value is left as is.

This works for nested objects.

If you don't need strong typing in PHP but would like the objects in your client to be strongly typed, you can: For example a stdObj like this will be returned in AMF as MyVO $returnObj = new stdObj(); $explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE; $returnObj->$explicitTypeField = "MyVO";

If you are using Flash, remember that you need to register the class alias so that Flash converts the MyVO AMF object to a Flash MyVO object. If you are using Flex you can do this with the RemoteClass metadata tag.

Summary

Methods
Properties
Constants
__construct()
filterVoConverter()
filterDeserializedRequest()
filterDeserializedResponse()
setScanEnabled()
getScanEnabled()
convertToTyped()
getNewVoInstance()
markExplicitType()
$voFolders
$enforceConversion
No constants found
No protected methods found
$scanEnabled
N/A
No private methods found
No private properties found
N/A

Properties

$voFolders

$voFolders : array

paths to folders containing Value Objects(relative or absolute) default is /Services/Vo/ if you need a namespace, use an array instead. First value is the path, second is the root namespace.

for example: array(AMFPHP_ROOTPATH . '/Services/Vo/', 'namespace');

Type

array — of folders

$enforceConversion

$enforceConversion : boolean

Set this to true if you want an exception to be thrown when a Value Object is not found.

Avoid setting this to true on a public server as the exception contains details about your server configuration.

Type

boolean

$scanEnabled

$scanEnabled : boolean

should objects be scanned or converted.

Type

boolean

Methods

__construct()

__construct(array $config)

constructor.

Parameters

array $config

optional key/value pairs in an associative array. Used to override default configuration values.

filterVoConverter()

filterVoConverter() : \AmfphpVoConverter

provides this as a default vo converter

Returns

\AmfphpVoConverter

filterDeserializedRequest()

filterDeserializedRequest(mixed $deserializedRequest) : mixed

converts untyped objects to their typed counterparts. Loads the class if necessary

Parameters

mixed $deserializedRequest

Returns

mixed

filterDeserializedResponse()

filterDeserializedResponse(mixed $deserializedResponse) : mixed

looks at the outgoing packet and sets the explicit type field so that the serializer sends it properly

Parameters

mixed $deserializedResponse

Returns

mixed

setScanEnabled()

setScanEnabled(boolean $enabled)

for some protocols it is possible to call convertToType and markExplicitObject directly during deserialization and serialization.

This is typically the case of AMF, but not JSON. In that case this function must be called with enabled set to false, so the plugin does not scan the objects to do it itself. By default scanning is enabled

Parameters

boolean $enabled

getScanEnabled()

getScanEnabled() : boolean

get scan enabled.

Returns

boolean

convertToTyped()

convertToTyped(mixed $obj) : mixed

if the object contains an explicit type marker, this method attempts to convert it to its typed counterpart If then the class is still not available, the object is not converted note: This is not a recursive function. Rather the recusrion is handled by Amfphp_Core_Amf_Util::applyFunctionToContainedObjects.

must be public so that Amfphp_Core_Amf_Util::applyFunctionToContainedObjects can call it

Parameters

mixed $obj

Returns

mixed

getNewVoInstance()

getNewVoInstance(\type $voName) : \typed

creates and returns an instance of of $voName.

if the Vo class is already available, then simply creates a new instance of it. If not, attempts to load the file from the available service folders. If all fails, there is the option to throw an error.

Parameters

\type $voName

Returns

\typed —

object or null

markExplicitType()

markExplicitType(mixed $obj) : mixed

sets the the explicit type marker on the object. This is only done if it not already set, as in some cases the service class might want to do this manually.

note: This is not a recursive function. Rather the recusrion is handled by Amfphp_Core_Amf_Util::applyFunctionToContainedObjects. must be public so that Amfphp_Core_Amf_Util::applyFunctionToContainedObjects can call it

Parameters

mixed $obj

Returns

mixed