Service
Now we’re ready to implement the service for our Hello World example. First, remove (or comment out) the mock service that you created above. Next, open ./app/services/test_service.php and create a new service method like the one below:
/*
* @Service(request = "hello.world.request", response = "hello.world.response")
*/
function helloWorld (&$request,&$response)
{
$responseData = &$response["data"];
$requestData = $request["data"];
$responseData["message"] = $requestData["your_message"];
}
The PHP5 annotation @Service tells the service broker that this method is the one that should respond to the message hello.world.request. The message payload is passed into your message in &$request['data']. This will be a hash representing the JSON object sent by the message sender.
The annotation also specifies that the response of this method will be hello.world.response. You can set the message payload of the response by adding to $response['data']
Appcelerator also includes support for running in PHP4. The syntax remains the same, Appcelerator seamlessly changes the annotation parser depending on the version of PHP.