/** * Fetch data from request and prepare it for passing to specified action. * * @param object $controllerInstance * @param string $action * @return array */ public function fetchRequestData($controllerInstance, $action) { $methodReflection = Mage_Webapi_Helper_Data::createMethodReflection($controllerInstance, $action); $methodName = $this->_configHelper->getMethodNameWithoutVersionSuffix($methodReflection); $bodyParamName = $this->_configHelper->getOperationBodyParamName($methodReflection); $requestParams = array_merge($this->_request->getParams(), array($bodyParamName => $this->_getRequestBody($methodName))); /** Convert names of ID and Parent ID params in request to those which are used in method interface. */ $idArgumentName = $this->_configHelper->getOperationIdParamName($methodReflection); $parentIdParamName = Mage_Webapi_Controller_Router_Route_Rest::PARAM_PARENT_ID; $idParamName = Mage_Webapi_Controller_Router_Route_Rest::PARAM_ID; if (isset($requestParams[$parentIdParamName]) && $idArgumentName != $parentIdParamName) { $requestParams[$idArgumentName] = $requestParams[$parentIdParamName]; unset($requestParams[$parentIdParamName]); } elseif (isset($requestParams[$idParamName]) && $idArgumentName != $idParamName) { $requestParams[$idArgumentName] = $requestParams[$idParamName]; unset($requestParams[$idParamName]); } return $this->_apiHelper->prepareMethodParams($controllerInstance, $action, $requestParams, $this->_apiConfig); }
public function testGenerateRestRoutesInvalidMethod() { $this->setExpectedException('InvalidArgumentException', '"invalidMethodNameV2" is an invalid API resource method.'); $this->_model->generateRestRoutes(Mage_Webapi_Helper_Data::createMethodReflection('Vendor_Module_Controller_Webapi_Invalid_Interface', 'invalidMethodNameV2')); }
public function testGetIdParamException() { $className = 'Vendor_Module_Webapi_Resource_Invalid'; $this->setExpectedException('LogicException', sprintf('"%s" is not a valid resource class.', $className)); $this->_helper->getOperationIdParamName(Mage_Webapi_Helper_Data::createMethodReflection($className, 'updateV1')); }