/**
  * Process and resolve input parameters
  *
  * @return array
  * @throws \Magento\Framework\Webapi\Exception
  */
 public function resolve()
 {
     $this->requestValidator->validate();
     $route = $this->getRoute();
     $serviceMethodName = $route->getServiceMethod();
     $serviceClassName = $route->getServiceClass();
     /*
      * Valid only for updates using PUT when passing id value both in URL and body
      */
     if ($this->request->getHttpMethod() == RestRequest::HTTP_METHOD_PUT) {
         $inputData = $this->paramsOverrider->overrideRequestBodyIdWithPathParam($this->request->getParams(), $this->request->getBodyParams(), $serviceClassName, $serviceMethodName);
         $inputData = array_merge($inputData, $this->request->getParams());
     } else {
         $inputData = $this->request->getRequestData();
     }
     $inputData = $this->paramsOverrider->override($inputData, $route->getParameters());
     $inputParams = $this->serviceInputProcessor->process($serviceClassName, $serviceMethodName, $inputData);
     return $inputParams;
 }
Example #2
0
 /**
  * Generate the list of available REST routes. Current HTTP method is taken into account.
  *
  * @param \Magento\Framework\Webapi\Rest\Request $request
  * @return Route[] matched routes
  * @throws \Magento\Framework\Webapi\Exception
  */
 public function getRestRoutes(\Magento\Framework\Webapi\Rest\Request $request)
 {
     $requestHttpMethod = $request->getHttpMethod();
     $servicesRoutes = $this->_config->getServices()[Converter::KEY_ROUTES];
     $routes = [];
     // Return the route on exact match
     if (isset($servicesRoutes[$request->getPathInfo()][$requestHttpMethod])) {
         $methodInfo = $servicesRoutes[$request->getPathInfo()][$requestHttpMethod];
         $routes[] = $this->_createRoute([self::KEY_ROUTE_PATH => $request->getPathInfo(), self::KEY_CLASS => $methodInfo[Converter::KEY_SERVICE][Converter::KEY_SERVICE_CLASS], self::KEY_METHOD => $methodInfo[Converter::KEY_SERVICE][Converter::KEY_SERVICE_METHOD], self::KEY_IS_SECURE => $methodInfo[Converter::KEY_SECURE], self::KEY_ACL_RESOURCES => array_keys($methodInfo[Converter::KEY_ACL_RESOURCES]), self::KEY_PARAMETERS => $methodInfo[Converter::KEY_DATA_PARAMETERS]]);
         return $routes;
     }
     $serviceBaseUrl = $this->_getServiceBaseUrl($request);
     ksort($servicesRoutes, SORT_STRING);
     foreach ($servicesRoutes as $url => $httpMethods) {
         // skip if baseurl is not null and does not match
         if (!$serviceBaseUrl || strpos(trim($url, '/'), trim($serviceBaseUrl, '/')) !== 0) {
             // base url does not match, just skip this service
             continue;
         }
         foreach ($httpMethods as $httpMethod => $methodInfo) {
             if (strtoupper($httpMethod) == strtoupper($requestHttpMethod)) {
                 $aclResources = array_keys($methodInfo[Converter::KEY_ACL_RESOURCES]);
                 $routes[] = $this->_createRoute([self::KEY_ROUTE_PATH => $url, self::KEY_CLASS => $methodInfo[Converter::KEY_SERVICE][Converter::KEY_SERVICE_CLASS], self::KEY_METHOD => $methodInfo[Converter::KEY_SERVICE][Converter::KEY_SERVICE_METHOD], self::KEY_IS_SECURE => $methodInfo[Converter::KEY_SECURE], self::KEY_ACL_RESOURCES => $aclResources, self::KEY_PARAMETERS => $methodInfo[Converter::KEY_DATA_PARAMETERS]]);
             }
         }
     }
     return $routes;
 }