Exemplo n.º 1
0
 /**
  * throwException provides the means to raise an exception.  This method will 
  * stop the further execution of the remote method, but not hault the execution
  * of the entire process.  Using the built in PHP exception system will stop
  * the entire process and not allow us to report very detailed information back
  * to the client, especially if there are multiple methods.
  * 
  * When we upgrade to PHP 5, using the try...catch syntax will make this much easier.
  * 
  * @static
  * @param AMFBody $body The AMFBody object to apply the exception to.
  * @param AMFException @exception The exception object to throw
  * @see AMFBody
  */
 function throwException(&$body, $exception)
 {
     $body->responseURI = $body->responseIndex . "/onStatus";
     $results =& $body->getResults();
     $results["description"] = $exception->description;
     $results["details"] = $exception->details;
     $results["level"] = $exception->level;
     $results["line"] = $exception->line;
     $results["code"] = $exception->code;
 }
 /**
  * throwException provides the means to raise an exception.  This method will 
  * stop the further execution of the remote method, but not hault the execution
  * of the entire process.  Using the built in PHP exception system will stop
  * the entire process and not allow us to report very detailed information back
  * to the client, especially if there are multiple methods.
  * 
  * When we upgrade to PHP 5, using the try...catch syntax will make this much easier.
  * 
  * @static
  * @param AMFBody $body The AMFBody object to apply the exception to.
  * @param AMFException @exception The exception object to throw
  * @see AMFBody
  */
 function throwException(&$body, $exception)
 {
     $body->responseURI = $body->responseIndex . "/onStatus";
     $results =& $body->getResults();
     if ($GLOBALS['amfphp']['encoding'] == 'amf3') {
         $results = new ErrorMessage();
         $results->correlationId = $GLOBALS['amfphp']['lastMessageId'];
         $results->faultCode = $exception->code;
         $results->faultDetail = $exception->details . ' on line ' . $exception->line;
         $results->faultString = $exception->description;
     } elseif ($GLOBALS['amfphp']['encoding'] == 'amf0') {
         $results["description"] = $exception->description;
         $results["details"] = $exception->details;
         $results["level"] = $exception->level;
         $results["line"] = $exception->line;
         $results["code"] = $exception->code;
     } else {
         $results['faultCode'] = $exception->code;
         $results['faultDetail'] = $exception->details . ' on line ' . $exception->line;
         $results['faultString'] = $exception->description;
     }
 }
Exemplo n.º 3
0
function reportExceptions($code, $descr, $filename, $line)
{
    // obey error_level set by system/user
    if (!($code & error_reporting())) {
        return;
    }
    // build a new AMFObject
    $amfout = new AMFObject("");
    // init a new error info object
    $error = array();
    // pass the code
    $error["code"] = "AMFPHP_RUNTIME_ERROR";
    // pass the description
    $error["description"] = $descr;
    // pass the details
    $error["details"] = $filename;
    // pass the level
    $error["level"] = AMFException::getFriendlyError($code);
    // pass the line number
    $error["line"] = $line;
    // add the error object to the body of the AMFObject
    $amfbody = new AMFBody(NULL, $GLOBALS['amfphp']['lastMethodCall']);
    $amfbody->setResults($error);
    $amfout->addBody($amfbody);
    // Add the trace headers we have so far while we're at it
    debugFilter($amfout);
    // create a new serializer
    $serializer = new AMFSerializer();
    // serialize the data
    $data = $serializer->serialize($amfout);
    // send the correct header
    header('Content-type: application/x-amf');
    // flush the amf data to the client.
    print $data;
    // kill the system after we find a single error
    exit;
}
Exemplo n.º 4
0
 /**
  * Wraps a string into an error AMF message
  * @param $data the original AMF data (needed to get the response index
  * @param $error The error to send back
  * @returns String containing the AMF data
  */
 function sendError($data, $error)
 {
     //Get the last response index, otherwise the error will not register
     //In the NetConnection debugger
     $amf = new AMFObject($data);
     // create the amf object
     $deserializer = new AMFDeserializer($data);
     $deserializer->deserialize($amf);
     $lastBody =& $amf->getBodyAt($amf->numBody() - 1);
     $lastIndex = $lastBody->responseIndex;
     // add the error object to the body of the AMFObject
     $amfout = new AMFObject(NULL);
     $amfbody = new AMFBody($lastIndex . "/onStatus", $lastIndex);
     //Get line number
     preg_match("/in ([A-Za-z0-9\\/\\.\\:]+) on line ([0-9]+)/", str_replace('\\', '/', $error), $matches);
     $file = $matches[1];
     $line = $matches[2];
     $level = substr($error, 0, strpos($error, ': '));
     $amfbody->setResults(array('description' => $error, 'line' => $line, 'file' => $file, 'level' => $level, 'code' => 'AMFPHP_DEBUG_ERROR'));
     $amfout->addBody($amfbody);
     // create a new serializer
     $serializer = new AMFSerializer();
     // serialize the data
     $result = $serializer->serialize($amfout);
     return $result;
 }
Exemplo n.º 5
0
/**
 * Adds debugging information to outgoing packet
 */
function debugFilter(&$amf)
{
    //Add trace headers before outputting
    if (!$GLOBALS['amfphp']['isFlashComm'] && !$GLOBALS['amfphp']['disableTrace'] && count(NetDebug::getTraceStack()) != 0) {
        //Get the last body in the stack
        $body =& $amf->getBodyAt($amf->numBody() - 1);
        $headers = new AMFBody(NULL, $body->responseIndex, NULL);
        // create a new amf body
        $headers->responseURI = $body->responseIndex . "/onDebugEvents";
        // set the response uri of this body
        $headerresults = array();
        // create a result array
        $headerresults[0] = array();
        // create a sub array in results (CF seems to do this, don't know why)
        $ts = NetDebug::getTraceStack();
        $headerresults[0][] = new TraceHeader($ts);
        $headers->setResults($headerresults);
        // set the results.
        $amf->addBodyAt(0, $headers);
    }
}