Description

We use gateway.php as endpoint for Remoting Calls from Flash player.
In order to expose a php file as a service we need to include it in the gateway.php file.
Strongly typed objects(class objects) when sent either from client side or server side do not work till we specify a classMapping on gateway.php
Something similar to:
$server->setClassMap('Entity', 'Entity');

Flex already has a remoteClass alias tag as a metadata on the client side classes which specifies its type on the server side.
Example:
package
{
[RemoteClass(alias="Entity")] // this is server side type
public class Entity
{
public var id:int;
}
}

This data is used while serializing and de-serializing the object.
So, Zend should not be requiring this mapping on the server, as it is assumed that the client will always send the data with the same typing as on the server.
If there is any other reason of keeping this mapping on gateway.php, at least the default behavior should be the one which is mentioned above for no mappings.

Also, otherwise, the $explicitType variable in php classes provide the information about the type on the server. This variable if not specified make the strong typed objects as generic objects when sent to the client. This should also default to the class name if it is not specified, and should work as strongly typed objects on either side.

Comments

Posted by Stanislav Malyshev (stas) on 2009-04-21T13:45:44.000+0000

I've changed the serializer methods so that they will return class name and not empty for unknown classes, unless the class is stdClass (which will be just Object).
Wade, if you could add test for that (I'm not sure how it's best to do it) that'd be great.

Posted by Wade Arnold (wadearnold) on 2009-04-21T14:01:08.000+0000

Looks like a pretty test case for the new functionality. Thanks stas! I'll put it in after work and merge it into the next mini release.

The fix provided is partial and works only if the function in php is not strongly typed like:
function update($ item)
{
return "something";
}

and we pass a class A say :
package
{
[RemoteClass(alias="A")]
public class A
{
public var i:int = 2;
public function A()
{

}
}

}

now since the class mapping is not done on the server, the php function receives a stdClass and works.
But the issue is that when the php function is strongly types say:
function update (A $item);

PHP starts complaining the passed argument is of type stdClass instead of A.

The fix for this can be achieved if the Deserializer figures out the type (specified by the remote class alias on the Actionscript class) and then instantiates the correct type on the server side.

Posted by Stanislav Malyshev (stas) on 2009-06-09T12:52:28.000+0000

The mapping works if the class in question (ARemote) exists or can be loaded. If it can not, then the mapping of course can not work. I tried your example and it worked for me just fine as soon as class ARemote is defined when server request is parsed. If you code does not work, please provide the full code.