コード例 #1
0
ファイル: EmaRpcApi.php プロジェクト: indiwine/EMA-engine
 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;
     }
 }
コード例 #2
0
 public static function findFilesInDataStructure($structure)
 {
     return RootClass::findAttrInDataStructure($structure, "file", "true");
 }
コード例 #3
0
ファイル: EmaRestApi.php プロジェクト: indiwine/EMA-engine
 public static function rpcFactory(array $wildcard, $httpMethod, Slim $slim)
 {
     $lastElement = end($wildcard);
     if (empty($lastElement)) {
         array_pop($wildcard);
     }
     $numOfRoutesElements = count($wildcard);
     if ($numOfRoutesElements > 2 || $numOfRoutesElements < 1) {
         throw new InputError('Route is not valid');
     }
     if ($numOfRoutesElements === 1) {
         $wildcard[1] = null;
     } else {
         if (!is_numeric($wildcard[1])) {
             throw new InputError('Invalid item ID');
         }
     }
     list($className, $id) = $wildcard;
     $methodName = '';
     $arguments = '';
     switch ($httpMethod) {
         case 'GET':
             if ($numOfRoutesElements === 1) {
                 $methodName = 'getList';
                 if (!empty($_GET['where']) && is_string($_GET['where']) && RootClass::isJson($_GET['where'])) {
                     $arguments = json_decode($_GET['where'], true);
                 }
             } else {
                 $methodName = 'get';
                 $arguments = $id;
                 self::$isGettingItem = true;
             }
             break;
         case 'POST':
             $contentType = $slim->request->getMediaType();
             if (!in_array($contentType, self::$allowedPostContentTypes, true)) {
                 throw new Unsupported('Invalid content type');
             }
             if ($contentType === 'application/json') {
                 $arguments = json_decode($slim->request->getBody(), true);
             } else {
                 $arguments = $_POST;
             }
             if (empty($arguments) || !is_array($arguments)) {
                 throw new InputError('A POST body is empty or not correctly formatted');
             }
             if ($numOfRoutesElements === 1) {
                 $methodName = 'saveNew';
                 self::$isAddition = true;
                 self::$additionRouteBase .= $className . '/';
             } else {
                 $methodName = 'save';
                 $arguments['id'] = $id;
             }
             break;
         case 'DELETE':
             if (empty($id)) {
                 throw new InputError('Invalid item ID');
             } else {
                 $methodName = 'delete';
                 $arguments = $id;
             }
             break;
     }
     return new RpcCall($className, $methodName, $arguments);
 }
コード例 #4
0
 /**
  * @param $structure
  * @return array
  */
 public static function findImagesInDataStructure($structure)
 {
     return RootClass::findAttrInDataStructure($structure, 'file', 'image');
 }