Beispiel #1
0
 function invokeService($serviceName, $methodName, $arguments, $extras = NULL)
 {
     $invoke_service_start_time = (double) microtime(TRUE);
     //Convert . to '/', then class name is basename()
     $className = TTgetPluginClassName(basename(str_replace('.', '/', $serviceName)));
     Debug::text('Service: ' . $serviceName . ' Method: ' . $methodName . ' Class: ' . $className, __FILE__, __LINE__, __METHOD__, 10);
     if (class_exists($className) == FALSE) {
         Debug::text('Service: ' . $serviceName . ' does not exist!', __FILE__, __LINE__, __METHOD__, 10);
         throw new Exception('Service: ' . $serviceName . ' does not exist!');
         return FALSE;
     }
     Debug::Arr($arguments, 'Arguments: ', __FILE__, __LINE__, __METHOD__, 10);
     if (PRODUCTION == FALSE and $this->hasObject($arguments) == TRUE) {
         $argument_var_dump = Debug::varDump($arguments);
         throw new Exception('ERROR: Passed an object as argument to: Method: ' . $methodName . ' as part of service: ' . $serviceName . '! -- Arguments: ' . $argument_var_dump);
         unset($argument_var_dump);
         return FALSE;
     }
     //Holds all objects in memory until the entire request is done, so multiple function calls in a single request can share data with each other.
     //This is necessary for getPageData() to work.
     if (!isset($this->object_cache[$className])) {
         $this->object_cache[$className] = new $className();
     }
     if (isset($extras['messageId']) and method_exists($this->object_cache[$className], 'setAMFMessageID')) {
         $this->object_cache[$className]->setAMFMessageID($extras['messageId']);
     }
     if (method_exists($this->object_cache[$className], $methodName) == FALSE) {
         throw new Exception('Method: ' . $methodName . ' as part of service: ' . $serviceName . ' does not exist!');
         return FALSE;
     }
     try {
         $retval = call_user_func_array(array(&$this->object_cache[$className], $methodName), $arguments);
     } catch (Exception $e) {
         $argument_var_dump = Debug::varDump($arguments);
         $backtrace = Debug::backTrace();
         Debug::Arr($backtrace, 'FAILED CALL... Service: ' . $serviceName . ' Method: ' . $methodName . ' Class: ' . $className . ' Message: ' . $e->getMessage(), __FILE__, __LINE__, __METHOD__, 10);
         throw new Exception('ERROR: Failed calling method: ' . $methodName . ' as part of serivce: ' . $serviceName . '! Exception: ' . $e->getMessage() . ' Arguments: ' . $argument_var_dump . ' BackTrace: ' . $backtrace);
         unset($argument_var_dump, $backtrace);
         return FALSE;
     }
     //Debug::Arr($retval, 'RetVal: ', __FILE__, __LINE__, __METHOD__, 10);
     Debug::text('Returning ' . strlen(serialize($retval)) . ' bytes of data... Response Time: ' . ((double) microtime(TRUE) - $invoke_service_start_time), __FILE__, __LINE__, __METHOD__, 10);
     return $retval;
 }
Beispiel #2
0
require_once '../../includes/API.inc.php';
Debug::setEnable(TRUE);
Debug::setEnableDisplay(TRUE);
Debug::setEnableLog(TRUE);
Debug::setEnableTidy(FALSE);
Debug::setVerbosity(10);
$class_prefix = 'API';
$soap_server = new SoapServer(NULL, array('uri' => "urn:api"));
if (isset($_GET['SessionID']) and $_GET['SessionID'] != '') {
    $authentication = new Authentication();
    Debug::text('SOAP Session ID: ' . $_GET['SessionID'] . ' Source IP: ' . $_SERVER['REMOTE_ADDR'], __FILE__, __LINE__, __METHOD__, 10);
    if ($authentication->Check($_GET['SessionID']) === TRUE) {
        //Class name is case sensitive!
        $class_factory = (isset($_GET['Class']) and $_GET['Class'] != '') ? $_GET['Class'] : 'Authentication';
        //Default to APIAuthentication class if none is specified.
        $class_name = TTgetPluginClassName($class_prefix . $class_factory);
        Debug::text('SOAP Class Factory: ' . $class_factory, __FILE__, __LINE__, __METHOD__, 10);
        if ($class_factory != '' and class_exists($class_name)) {
            $current_user = $authentication->getObject();
            if (is_object($current_user)) {
                $current_user->getUserPreferenceObject()->setDateTimePreferences();
                $current_user_prefs = $current_user->getUserPreferenceObject();
                Debug::text('Locale Cookie: ' . TTi18n::getLocaleCookie(), __FILE__, __LINE__, __METHOD__, 10);
                if (TTi18n::getLocaleCookie() != '' and $current_user_prefs->getLanguage() !== TTi18n::getLanguageFromLocale(TTi18n::getLocaleCookie())) {
                    Debug::text('Changing User Preference Language to match cookie...', __FILE__, __LINE__, __METHOD__, 10);
                    $current_user_prefs->setLanguage(TTi18n::getLanguageFromLocale(TTi18n::getLocaleCookie()));
                    if ($current_user_prefs->isValid()) {
                        $current_user_prefs->Save(FALSE);
                    }
                } else {
                    Debug::text('User Preference Language matches cookie!', __FILE__, __LINE__, __METHOD__, 10);
Beispiel #3
0
 Arguments:
	GET: SessionID
	GET: Class
	GET: Method
	POST: Arguments for method.
*/
$class_prefix = 'API';
$class_name = FALSE;
$method = FALSE;
if (isset($_GET['Class']) and $_GET['Class'] != '') {
    $class_name = $_GET['Class'];
    //If API wasn't already put on the class, add it manually.
    if (strtolower(substr($class_name, 0, 3)) != 'api') {
        $class_name = $class_prefix . $class_name;
    }
    $class_name = TTgetPluginClassName($class_name);
}
if (isset($_GET['Method']) and $_GET['Method'] != '') {
    $method = $_GET['Method'];
}
if (isset($_GET['MessageID']) and $_GET['MessageID'] != '') {
    $message_id = $_GET['MessageID'];
} else {
    $message_id = md5(time());
    //Random message_id
}
Debug::text('Handling JSON Call To API Factory: ' . $class_name . ' Method: ' . $method . ' Message ID: ' . $message_id, __FILE__, __LINE__, __METHOD__, 10);
//URL: api.php?SessionID=fc914bf32711bff031a6c80295bbff86&Class=APIPayStub&Method=getPayStub
/*
 RAW POST: data[filter_data][id][0]=101561&paging=TRUE&format=pdf
 JSON (URL encoded): %7B%22data%22%3A%7B%22filter_data%22%3A%7B%22id%22%3A%5B101561%5D%7D%7D%2C%22paging%22%3Atrue%2C%22format%22%3A%22pdf%22%7D
Beispiel #4
0
function TTnew($class_name)
{
    //Unlimited arguments are supported.
    $class_name = TTgetPluginClassName($class_name);
    if (func_num_args() > 1) {
        $params = func_get_args();
        array_shift($params);
        //Eliminate the class name argument.
        $reflection_class = new ReflectionClass($class_name);
        return $reflection_class->newInstanceArgs($params);
    } else {
        return new $class_name();
    }
}