/**
  * Handles passing a request through the amf client
  * @param {string} $servicePath Service path i.e ServerController.connect
  * @param {object|array} $data Data to be sent with the request should be an array or an object
  * @return {array} Server response
  */
 protected function getAMFResponse($servicePath, $data = null)
 {
     require_once 'Zend/Amf/Request.php';
     require_once 'Zend/Amf/Constants.php';
     require_once 'Zend/Amf/Value/MessageBody.php';
     require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
     require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
     if ($data) {
         if (is_array($data)) {
             $data = $this->arrayToObject($data);
         } else {
             if (!is_object($data)) {
                 user_error('$data is not an array or object', E_USER_ERROR);
             }
         }
     }
     //Find the method and service
     $service = explode('.', $servicePath);
     $method = array_pop($service);
     $service = implode('.', $service);
     //Build the message
     $message = new Zend_Amf_Value_Messaging_RemotingMessage();
     $message->parameters = $data;
     $message->operation = $method;
     $message->source = $service;
     //Build the message body
     $body = new Zend_Amf_Value_MessageBody($servicePath, '/1', array($data));
     //Build the AMF Request
     $request = new Zend_Amf_Request();
     $request->addAmfBody($body);
     $request->setObjectEncoding(Zend_Amf_Constants::AMF3_OBJECT_ENCODING);
     //Init the client api
     $amfClient = new CodeBank_ClientAPI();
     $amfClient->setTestRequest($request);
     //Capture the response as an amf input stream
     ob_start();
     $response = $amfClient->index();
     ob_end_clean();
     //Get the amf bodies
     $bodies = $response->getAmfBodies();
     if (count($bodies) > 0) {
         $body = $bodies[0]->getData();
         if ($body instanceof Zend_Amf_Value_Messaging_ErrorMessage) {
             $this->fail('AMF Server returned an error: ' . $body->faultString . "\n\n" . $body->faultDetail);
             return false;
         }
         return $body;
     }
     return false;
 }