Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /**
  * Identify if method expects Resource ID to be present in the request.
  *
  * @param Zend\Server\Reflection\ReflectionMethod $methodReflection
  * @return bool
  */
 protected function _isResourceIdExpected(ReflectionMethod $methodReflection)
 {
     $isIdFieldExpected = false;
     $methodsWithId = array(Mage_Webapi_Controller_ActionAbstract::METHOD_GET, Mage_Webapi_Controller_ActionAbstract::METHOD_UPDATE, Mage_Webapi_Controller_ActionAbstract::METHOD_DELETE);
     $methodName = $this->_helper->getMethodNameWithoutVersionSuffix($methodReflection);
     if (in_array($methodName, $methodsWithId)) {
         $isIdFieldExpected = true;
     }
     return $isIdFieldExpected;
 }
Ejemplo n.º 3
0
 /**
  * Retrieve method metadata.
  *
  * @param Zend\Server\Reflection\ReflectionMethod $methodReflection
  * @return array
  * @throws InvalidArgumentException If specified method was not previously registered in API config.
  */
 public function getMethodMetadata(ReflectionMethod $methodReflection)
 {
     $resourceName = $this->_helper->translateResourceName($methodReflection->getDeclaringClass()->getName());
     $resourceVersion = $this->_getMethodVersion($methodReflection);
     $methodName = $this->_helper->getMethodNameWithoutVersionSuffix($methodReflection);
     if (!isset($this->_data['resources'][$resourceName]['versions'][$resourceVersion]['methods'][$methodName])) {
         throw new InvalidArgumentException(sprintf('The "%s" method of "%s" resource in version "%s" is not registered.', $methodName, $resourceName, $resourceVersion));
     }
     return $this->_data['resources'][$resourceName]['versions'][$resourceVersion]['methods'][$methodName];
 }