Vo Converter

This plugin converts data from incoming packets with explicit types to custom classes, and vice versa for the outgoing packets. It can be deactivated if the project doesn’t use custom classes.

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 custom class.

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.

If after deserialization the custom class 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.

The explicit type marker is defined in Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE. At time of writing it is ‘_explicitType’.

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.

You should put your typed classes in the Services/Vo folder as that is where the plugin will look for them by default. If you want to use another folder, you could something like the following in your config class:

$this->pluginsConfig["AmfphpCustomClassConverter"] =
array(“customClassFolderPaths” => array(AMFPHP_ROOTPATH . “MyVoFolder”));

registerClassAlias doc
Flex MetaData RemoteClass doc

See here for the generated doc.

Comments

  1. Deleu

    25 Fév 13

    The last line of code gives an Syntax error. I used it like the following to make it work:

    $this->pluginsConfig[« AmfphpCustomClassConverter »] = array(« customClassFolderPaths » => array(AMFPHP_ROOTPATH . « Model »));

  2. Anton

    30 Sep 13

    OMG just spent an hour + wondering why I could not get my custom classes to work. It turns out, they have to be put in the Vo folder. In my logic, because the example is VoService.php, the classes go in Vo folder. If it is AlbumService.php (in my case), they should go into Album folder. Apparently my logic is weak.

  3. Ariel Sommeria-Klein

    30 Sep 13

    you weren’t helped though. Right now custom class mapping fails silently which is right for production, but for development it should point you in the right direction. It’s planned for the next version.

  4. marcusio

    17 Oct 13

    thanks

  5. Mario Morales

    26 Nov 14

    Please update the example with the current property names:

    $this->pluginsConfig[« AmfphpVoConverter »][« voFolders »] = array(AMFPHP_ROOTPATH . « MyVoFolder/ »);

Laissez un commentaire

News letter

Evénements Silex Labs sur Paris et sa région: Inscrivez vous à la Newsletter mensuelle

Silex Labs community Tweets

Facebook page