Ejemplo n.º 1
0
 /**
  * createRequest takes the class, method, args and auth info and creates a ready to
  * send AMF message
  * 
  * @param $class The name of the class
  * @param $method The name of the remote method
  * @param $args An array of arguments
  * @param $username An optional username for Authentication
  * @param $password An optional password for Authentication
  * @returns A String representing the AMF data
  */
 function createRequest($class, $method, $args, $username = "", $password = "")
 {
     $amf = new AMFObject("");
     //Create the body of the request
     $body = new AMFBody($class . '.' . $method, '/1', null, null, null, null);
     $body->setResults($args);
     $body->responseURI = $class . '.' . $method;
     $body->responseTarget = '/1';
     $amf->addBody($body);
     //Add authentication info
     if ($username != "" || $password != "") {
         $header = new AMFHeader(AMFPHP_CREDENTIALS_HEADER, false, array('userid' => $username, 'password' => $password));
         $amf->addOutgoingHeader($header);
     }
     $serializer = new AMFSerializer();
     // Create a serailizer around the output stream
     $contents = $serializer->serialize($amf);
     // serialize the data
     //go in and change the ÿÿÿÿ with actual length of message
     $loc = strpos($contents, 'ÿÿÿÿ');
     $serializer->outBuffer = "";
     $serializer->writeLong(strlen($contents) - $loc - 4);
     $contents = str_replace('ÿÿÿÿ', $serializer->outBuffer, $contents);
     return $contents;
 }