Example #1
0
 private static function standardMethodCall()
 {
     if ($_POST['action'] === "standardMethod") {
         if (isset($_POST['class']) === false || is_string($_POST['class']) === false) {
             throw new RuntimeException("Invalid Request");
         }
         if (isset($_POST['method']) === false || is_string($_POST['method']) === false) {
             throw new RuntimeException("Invalid Request");
         }
         $className = $_POST['class'];
         $methodName = $_POST['method'];
         $arguments = null;
         if (isset($_POST['arguments']) === true) {
             if (is_string($_POST['arguments']) === true || is_array($_POST['arguments']) === true) {
                 if (is_string($_POST['arguments']) === true) {
                     if (RootClass::isJson($_POST['arguments']) === true) {
                         $parsedArgs = json_decode($_POST['arguments'], true);
                     } else {
                         $parsedArgs = $_POST['arguments'];
                     }
                 } else {
                     $parsedArgs = $_POST['arguments'];
                 }
                 $arguments = $parsedArgs;
                 unset($parsedArgs);
             } else {
                 throw new RuntimeException("Invalid Request");
             }
         }
         $local = null;
         if (isset($_COOKIE['local'])) {
             $local = $_COOKIE['local'];
         } elseif (isset($_SERVER['HTTP_EMA_LOCALIZATION'])) {
             $local = $_SERVER['HTTP_EMA_LOCALIZATION'];
         }
         if ($local !== null) {
             $localizationHelper = new LocalizationHelper();
             if (!$localizationHelper->isCorrectPrefix($local)) {
                 $local = $localizationHelper->getDefault();
             }
             unset($localizationHelper);
         }
         $rpc = new RpcCall($className, $methodName, $arguments);
         $rpc->setLocalization($local);
         $result = $rpc->run();
         print json_encode($result);
         return self::APP_JSON_TYPE;
     }
 }
Example #2
0
 public static function rpcCheckAndRun(RpcCall $rpc, Slim $slim)
 {
     $localization = $slim->request->headers->get('Ema-Localization');
     if ($localization) {
         $rpc->setLocalization($localization);
     }
     $user = new UserAuth();
     $isValidCsrfToken = $user->checkCsrfToken($slim->request->headers->get('X-Ema-Csrftoken'));
     if (!$isValidCsrfToken) {
         throw new InputError('CSRF token not valid');
     }
     $result = $rpc->run();
     if (self::$isAddition) {
         self::$additionRouteBase .= $result;
     }
     if (self::$isGettingItem && empty($result)) {
         throw new NotFound('Item not found');
     }
     return $result;
 }