What is it?The callback server is a class that helps you go through the process parsing the flash remoting request and sending back a response. It's the easiest way to get a flash remoting gateway up and running. Setup<?php
// First we'll create the server object
require_once 'SabreAMF/CallbackServer.php';
$server = new SabreAMF_CallbackServer();
// setup the callback
$server->onInvokeService = 'myCallback';
// parse the request and spit out the response
$server->exec();
?> The previous example assumes that the SabreAMF directory is in your current working directory or include_path. If this is not the case, you can add it to the include_path using the following example: <?php
set_include_path( get_include_path() . PATH_SEPARATOR . '/path/to/sabreamf/directory');
?> Callback functionFor every methodcall made from flash, a 'callback' function is called. In the previous example the callback function was called myCallback. You have to create this function yourself. The function should have 3 arguments. For example: <?php
function myCallback($serviceName, $methodName, $arguments) {
// You can use the servicename to lookup and instantiate a service class
$serviceObject = new $serviceName;
// check the php manual if you don't know what this function does
return call_user_func_array(array($serviceObject,$methodName),$arguments);
}
?>Next stepsThe last example is actually a working example and is a basic amf gateway. It expects the class of the service objects to be the exact same as the servicepath, used from flash. I'd not recommend this, because it allows anyone to instantiate objects of any class and call any method; which could result in security holes.
|
It might be worth ensuring that "arguments" is an array before calling "call_user_func_array", like so:
I have found, under certain conditions, when the argument is a single object, that it can get split up on the way to the service method - each property in the object gets passed to the service method as a separate parameter instead of as a single object. This work-around should prevent that.
I found too that AMF allows non-arrays to be used for the arguments. Do you have any information on which these conditions are?
Evert
Hi Evert,
I don't think it's an AMF thing. More of a PHP thing - the call_user_func_array function expects an array for it's second argument and seems to mangle certain objects if passed directly into the second argument (and not wrapped in a single element array).
Sorry, don't have much more info. Objects of Type stdClass seem to go through OK, but certain objects of custom Classes get chopped apart (treated as if they were an array, where each property of the object gets passed as a separate parameter to the function).
If I get a chance I'll try to do some more concrete tests.
Cheers,