AMF Data Types

Amfphp tries wherever possible to convert an AMF object to its PHP equivalent. However there are types where this equivalence doesn’t exist. In such cases you’ll have to use special Amfphp classes that you’ll find in Amfphp/Core/Types.

Note that you can’t return a PHP resource directly, you have to convert it to an array!

Here is a summary of the cases and types:

  • Undefined. AMF has an Undefined type. There is however not such a type in PHP. So an AMF Undefined is converted to a Amfphp_Core_Amf_Types_Undefined, and you must use this same class to send back an Undefined.
  • ByteArray. AMF has a ByteArray type. There is however not such a type in PHP. So an AMF ByteArray is converted to a Amfphp_Core_Amf_Types_ByteArray, and you must use this same class to send back an ByteArray.
  • Date. AMF has a Date type, which contains a timestamp. PHP has a DateTime type, but it is for PHP 5.2 and more, and the timestamp functionality is for PHP 5.3 and more. So for the time being an AMF date is converted to and from an Amfphp_Core_Amf_Types_Date.
  • XML. AMF has 2 XML types: XML and XMLDocument. PHP has many XML types and serializers and deserializers. So rather than to try to mix and match, the choice is left to the user. Amfphp will convert an AMF XML object to and from Amfphp_Core_Amf_Types_Xml, and a XMLDocument to and from Amfphp_Core_Amf_Types_XmlDocument. These classes both contain the XML data on the “data” property in string form, so the user can convert the data using whichever XML tools suits his purposes.
  • Flex Array Collection. A Flex array collection is deserialized to an array. To return an array collection to Flex, use the following code:

    $ret = new stdClass();
    $explicitTypeField = Amfphp_Core_Amf_Constants::FIELD_EXPLICIT_TYPE;
    $ret->$explicitTypeField = "flex.messaging.io.ArrayCollection";
    $ret->source = $yourData;
    return $ret;

Comments

  1. Avatar of erikmoreno

    erikmoreno

    April 27, 2012

    Se me hace extraño que digan que AmfPHP no soporta el envio de un ArrayCollection al Cliente. Por ejemplo, yo lo he hecho con Flex. Tengo una clase en php llamada ArrayCollection, con una variable $_explicitType = “flex.messaging.io.ArrayCollection”, tiene varios de los métodos que se usan. Flex lo recibe sin ningun problema como un ArrayCollection

    • Avatar of Ariel Sommeria-Klein

      Ariel Sommeria-Klein

      April 27, 2012

      like the doc says: AmfPHP does not however support sending an ArrayCollection to the client.

  2. Avatar of Deleu

    Deleu

    February 15, 2013

    But Amfphp sends back an Array which you can pass as constructor to the ArrayCollection and voalà

Add a comment

Warning!

This content
is outdated.

Discover Silex v2,
online website builder.

Upcoming Events

  1. Haxepéro #18 : Apéropen source

    October 23 @ 7:00 pm - 11:00 pm
  2. Atelier Vim #4 : Vim fait sa rentrée !

    October 27 @ 7:00 pm - 9:00 pm
  3. Haxetelier #8 : Trucs et Haxetuces

    October 29 @ 7:00 pm - 9:00 pm

Sign up for Silex Labs news by email

SilexLabs community Tweets