function reportExceptions($code, $descr, $filename, $line)
{
    // obey error_level set by system/user
    if (!($code & error_reporting())) {
        return;
    }
    // init a new error info object
    $error = new MessageException($code, $descr, $filename, $line, "AMFPHP_RUNTIME_ERROR");
    // add the error object to the body of the AMFObject
    $amfbody = new MessageBody(NULL, $GLOBALS['amfphp']['lastMethodCall']);
    MessageException::throwException($amfbody, $error);
    //$amfbody->setResults($error);
    if ($GLOBALS['amfphp']['encoding'] == 'amf0' || $GLOBALS['amfphp']['encoding'] == 'amf3') {
        // build a new AMFObject
        $amfout = new AMFObject("");
        $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;
    } else {
        serializationAction($amfbody);
        print $amfbody->getResults();
        exit;
    }
}
Exemple #2
0
 /**
  * Constructor
  *
  * @param scalar|array|PayloadInterface $payload
  * @param string $id
  * @param int $timestamp
  * @param float $version
  * @throws 
  */
 public function __construct($payload = null, $id = null, $timestamp = null, $version = 1.0)
 {
     if (!is_null($payload)) {
         if ($payload instanceof PayloadInterface) {
             $this->payload = $payload->getArrayCopy();
         } else {
             if (is_array($payload) || is_scalar($payload)) {
                 $this->payload = $payload;
             } else {
                 throw MessageException::payloadTypeError('Payload must be a scalar value, an array or an instance of PayloadInterface');
             }
         }
     }
     if (is_null($id)) {
         $this->id = uniqid();
     } else {
         $this->id = $id;
     }
     if (is_null($timestamp)) {
         $this->timestamp = date_timestamp_get(date_create());
     } else {
         $this->timestamp = $timestamp;
     }
     $this->version = $version;
 }
 /**
  * Constructor for the Exception class. This is how you build a new
  * error instance.
  * 
  * @param string $code The code string to return to the flash client :: THIS SHOULD PROBABLY BE SET AUTOMATICALLY ::
  * @param string $description A short reason why the error occured
  * @param string $file The file name that the error occured
  * @param int $line The line number where the error was detected
  */
 function MessageException($code, $description, $file, $line, $detailCode = 'AMFPHP_RUNTIME_ERROR')
 {
     $this->code = $detailCode;
     $this->description = $description;
     // pass the description
     $this->details = $file;
     // pass the details
     $this->level = MessageException::getFriendlyError($code);
     $this->line = $line;
     // pass the line number
 }
function CakeClassLoaderAction(&$amfbody)
{
    if (!$amfbody->noExec) {
        // change to the gateway.php script directory
        // now change to the directory of the classpath.  Possible relative to gateway.php
        $dirname = dirname($amfbody->classPath);
        if (is_dir($dirname)) {
            chdir($dirname);
        } else {
            $ex = new MessageException(E_USER_ERROR, "The classpath folder {" . $amfbody->classPath . "} does not exist. You probably misplaced your service.", __FILE__, __LINE__, "AMFPHP_CLASSPATH_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        $fileExists = @file_exists(basename($amfbody->classPath));
        // see if the file exists
        if (!$fileExists) {
            $ex = new MessageException(E_USER_ERROR, "The class {" . $amfbody->className . "} could not be found under the class path {" . $amfbody->classPath . "}", __FILE__, __LINE__, "AMFPHP_FILE_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        $fileIncluded = Executive::includeClass($amfbody, "./" . basename($amfbody->classPath));
        if (!$fileIncluded) {
            $ex = new MessageException(E_USER_ERROR, "The class file {" . $amfbody->className . "} exists but could not be included. The file may have syntax errors, or includes at the top of the file cannot be resolved.", __FILE__, __LINE__, "AMFPHP_FILE_NOT_INCLUDED");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        if (!class_exists($amfbody->className)) {
            // Just make sure the class name is the same as the file name
            $ex = new MessageException(E_USER_ERROR, "The file {" . $amfbody->className . ".php} exists and was included correctly but a class by that name could not be found in that file. Perhaps the class is misnamed.", __FILE__, __LINE__, "AMFPHP_CLASS_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //Let executive handle building the class
        //The executive can handle making exceptions and all that, that's why
        $classConstruct = Executive::buildClass($amfbody, $amfbody->className);
        if ($classConstruct !== '__amfphp_error') {
            $amfbody->setClassConstruct($classConstruct);
            setupCakeController($classConstruct);
        } else {
            return false;
        }
    }
    return true;
}
/**
 * Class loader action loads the class from which we will get the remote method
 */
function cakeClassLoaderAction(&$amfbody)
{
    if (!$amfbody->noExec) {
        // change to the gateway.php script directory
        // now change to the directory of the classpath.  Possible relative to gateway.php
        $dirname = dirname($amfbody->classPath);
        if (is_dir($dirname)) {
            //chdir($dirname);
        } else {
            $ex = new MessageException(E_USER_ERROR, "The classpath folder {" . $amfbody->classPath . "} does not exist. You probably misplaced your service.", __FILE__, __LINE__, "AMFPHP_CLASSPATH_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //$fileExists = @file_exists(basename($amfbody->classPath)); // see if the file exists
        $fileExists = @file_exists($amfbody->classPath);
        // see if the file exists
        if (!$fileExists) {
            $ex = new MessageException(E_USER_ERROR, "The class {" . $amfbody->className . "} could not be found under the class path {" . $amfbody->classPath . "}", __FILE__, __LINE__, "AMFPHP_FILE_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        global $amfphp;
        $time = microtime_float();
        //$fileIncluded = Executive::includeClass($amfbody, "./" . basename($amfbody->classPath));
        $fileIncluded = Executive::includeClass($amfbody, $amfbody->classPath);
        $amfphp['includeTime'] += microtime_float() - $time;
        if (!$fileIncluded) {
            $ex = new MessageException(E_USER_ERROR, "The class file {" . $amfbody->className . "} exists but could not be included. The file may have syntax errors, or includes at the top of the file cannot be resolved.", __FILE__, __LINE__, "AMFPHP_FILE_NOT_INCLUDED");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        if (!class_exists($amfbody->className)) {
            // Just make sure the class name is the same as the file name
            $ex = new MessageException(E_USER_ERROR, "The file {" . $amfbody->className . ".php} exists and was included correctly but a class by that name could not be found in that file. Perhaps the class is misnamed.", __FILE__, __LINE__, "AMFPHP_CLASS_NOT_FOUND");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //Let executive handle building the class
        //The executive can handle making exceptions and all that, that's why
        $classConstruct = Executive::buildClass($amfbody, $amfbody->className);
        $classConstruct->params['controller'] = Inflector::underscore(str_replace('Controller', '', $amfbody->className));
        $classConstruct->params['action'] = strtolower($amfbody->methodName);
        //We need exception handling when initializing CakePHP controllers,
        // (AmfAuth component, beforeFilters can throw exceptions). This way exceptions
        // are handled correctly, and returned through amf message
        $object = null;
        $init = Executive::doMethodCall($amfbody, $object, 'initCakeController', array($classConstruct));
        if ($init === '__amfphp_error') {
            return false;
        }
        if ($classConstruct !== '__amfphp_error') {
            $amfbody->setClassConstruct($classConstruct);
        } else {
            return false;
        }
    }
    return true;
}
 /**
  * Include a class
  * If there is an error, catch and return to caller
  */
 function includeClass(&$bodyObj, $location)
 {
     $included = false;
     try {
         include_once $location;
         $included = true;
     } catch (Exception $fault) {
         $included = false;
         if (get_class($fault) == "VerboseException") {
             $ex = new MessageException($fault->code, $fault->getMessage(), $fault->file, $fault->line, 'AMFPHP_INCLUDE_ERROR');
         } else {
             $ex = new MessageException(E_USER_ERROR, $fault->getMessage(), $fault->getFile(), $fault->getLine(), 'AMFPHP_INCLUDE_ERROR');
         }
         MessageException::throwException($bodyObj, $ex);
     }
     return $included;
 }
/**
 * MetaDataAction loads the required info from the methodTable
 */
function securityAction(&$amfbody)
{
    if (!$amfbody->noExec) {
        $classConstruct =& $amfbody->getClassConstruct();
        $methodName = $amfbody->methodName;
        $className = $amfbody->className;
        //Check if method exists
        if (!method_exists($classConstruct, $methodName)) {
            // check to see if the method exists
            $ex = new MessageException(E_USER_ERROR, "The method  {" . $methodName . "} does not exist in class {" . $className . "}.", __FILE__, __LINE__, "AMFPHP_INEXISTANT_METHOD");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //Check if method is private (PHP4)
        if (strpos($methodName, '_') === 0) {
            // check to see if the method exists
            $ex = new MessageException(E_USER_ERROR, "The method  {" . $methodName . "} starts with an underscore and is therefore considered private, so it cannot be remotely called.", __FILE__, __LINE__, "AMFPHP_PRIVATE_METHOD");
            MessageException::throwException($amfbody, $ex);
            return false;
        }
        //Check to see if method is private or protected (PHP5)
        if (class_exists('ReflectionMethod')) {
            $method = new ReflectionMethod($className, $methodName);
            if (!$method->isPublic()) {
                $ex = new MessageException(E_USER_ERROR, "The method  {" . $methodName . "} in {" . $className . "} is not public and therefore cannot be called.", __FILE__, __LINE__, "AMFPHP_PRIVATE_METHOD");
                MessageException::throwException($amfbody, $ex);
                return false;
            }
        }
        $classConstruct =& $amfbody->getClassConstruct();
        $methodName = $amfbody->methodName;
        $className = $amfbody->className;
        if (method_exists($classConstruct, "beforeFilter")) {
            //Pass throught the executive
            $allow = Executive::doMethodCall($amfbody, $classConstruct, 'beforeFilter', array($methodName));
            if ($allow === '__amfphp_error' || $allow === false) {
                $ex = new MessageException(E_USER_ERROR, "Method access blocked by beforeFilter in " . $className . " class", __FILE__, __LINE__, "AMFPHP_AUTHENTICATE_ERROR");
                MessageException::throwException($amfbody, $ex);
                return false;
            }
        }
    }
    return true;
}
Exemple #8
0
 public function __construct($message, Message $response)
 {
     parent::__construct($message);
     $this->response = $response;
 }