Просмотр исходного кода

updated Response::sendTryCatchJson to read args from request body in json format

Piotr Labudda 9 лет назад
Родитель
Сommit
c2449e91a8

+ 3 - 1
SE/se-lib/Response.php

@@ -6,6 +6,7 @@
  * @example: Response::sendJsonExit($data);
  * @example: Response::sendPlainTextExit($data);
  * @example: Response::sendTryCatchJson(array($this, 'methodNameReponseCallback'), $args);
+ * @example: Response::sendTryCatchJson(array($this, 'methodNameReponseCallback'), $args = 'JSON_FROM_REQUEST_BODY');// try to read json from request body
  */
 class Response {
 
@@ -35,7 +36,8 @@ class Response {
 		$response = array();
 		try {
 			if (!is_callable($callback)) throw new Exception("#1L" . __LINE__ . " Callback is not callable");
-			$response = call_user_func_array($callback, $args);
+			if ('JSON_FROM_REQUEST_BODY' == $args) $args = Request::getRequestJson();
+			$response = call_user_func($callback, $args);
 		} catch (AlertDangerException $e) {
 			Http::sendHeaderByCode(200);
 			$response['type'] = 'error';

+ 4 - 1
SE/se-lib/Route/UrlAction/ProjektyKosztyWstepnychRobot.php

@@ -1803,7 +1803,10 @@ SQL_FUN;
 		$args['unitType'] = V::get('unitType', '', $_GET, 'word');
 		Response::sendTryCatchJson(array($this, 'updateProjektyOfertaAjax'), $args);
 	}
-	public function updateProjektyOfertaAjax($idProject, $idType, $unitType) {
+	public function updateProjektyOfertaAjax($args) {
+		$idProject = V::get('idProject', 0, $args, 'int');
+		$idType = V::get('idType', 0, $args, 'int');
+		$unitType = V::get('unitType', '', $args, 'word');
 		if (empty($idProject) || $idProject <= 0) throw new Exception("Wrong param idProject");
 		if (empty($idType) || $idType <= 0) throw new Exception("Wrong param idType");
 		if (empty($unitType) || !in_array($unitType, array('zasob', 'robocizna'))) throw new Exception("Wrong param unitType");