Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * Collect the list of services with routes and request types for use in REST.
  *
  * @return array
  */
 protected function initRoutesMetadata()
 {
     $routes = $this->getServicesConfig();
     foreach ($this->config->getServices()[Converter::KEY_ROUTES] as $url => $routeData) {
         foreach ($routeData as $method => $data) {
             $serviceClass = $data[Converter::KEY_SERVICE][Converter::KEY_SERVICE_CLASS];
             $version = explode('/', ltrim($url, '/'))[0];
             $serviceName = $this->getServiceName($serviceClass, $version);
             $methodName = $data[Converter::KEY_SERVICE][Converter::KEY_METHOD];
             $routes[$serviceName][Converter::KEY_ROUTES][$url][$method][Converter::KEY_METHOD] = $methodName;
             $routes[$serviceName][Converter::KEY_ROUTES][$url][$method][Converter::KEY_DATA_PARAMETERS] = $data[Converter::KEY_DATA_PARAMETERS];
         }
     }
     return $routes;
 }
Ejemplo n.º 3
0
 /**
  * Collect the list of services with their operations available in SOAP.
  *
  * @return array
  */
 protected function initServicesMetadata()
 {
     $soapServices = [];
     foreach ($this->config->getServices()[Converter::KEY_SERVICES] as $serviceClass => $serviceVersionData) {
         foreach ($serviceVersionData as $version => $serviceData) {
             $serviceName = $this->getServiceName($serviceClass, $version);
             foreach ($serviceData[Converter::KEY_METHODS] as $methodName => $methodMetadata) {
                 $soapServices[$serviceName][self::KEY_SERVICE_METHODS][$methodName] = [self::KEY_METHOD => $methodName, self::KEY_IS_REQUIRED => (bool) $methodMetadata[Converter::KEY_SECURE], self::KEY_IS_SECURE => $methodMetadata[Converter::KEY_SECURE], self::KEY_ACL_RESOURCES => $methodMetadata[Converter::KEY_ACL_RESOURCES]];
                 $soapServices[$serviceName][self::KEY_CLASS] = $serviceClass;
             }
             $reflectedMethodsMetadata = $this->classReflector->reflectClassMethods($serviceClass, $soapServices[$serviceName][self::KEY_SERVICE_METHODS]);
             $soapServices[$serviceName][self::KEY_SERVICE_METHODS] = array_merge_recursive($soapServices[$serviceName][self::KEY_SERVICE_METHODS], $reflectedMethodsMetadata);
         }
     }
     return $soapServices;
 }
Ejemplo n.º 4
0
 /**
  * Collect the list of services with their operations available in SOAP.
  *
  * @return array
  */
 protected function _initServicesMetadata()
 {
     // TODO: Implement caching if this approach is approved
     if (is_null($this->_soapServices)) {
         $this->_soapServices = [];
         foreach ($this->_config->getServices()[Converter::KEY_SERVICES] as $serviceClass => $serviceData) {
             $serviceName = $this->_helper->getServiceName($serviceClass);
             foreach ($serviceData as $methodName => $methodMetadata) {
                 $this->_soapServices[$serviceName][self::KEY_SERVICE_METHODS][$methodName] = [self::KEY_METHOD => $methodName, self::KEY_IS_REQUIRED => (bool) $methodMetadata[Converter::KEY_SECURE], self::KEY_IS_SECURE => $methodMetadata[Converter::KEY_SECURE], self::KEY_ACL_RESOURCES => $methodMetadata[Converter::KEY_ACL_RESOURCES]];
                 $this->_soapServices[$serviceName][self::KEY_CLASS] = $serviceClass;
             }
             $reflectedMethodsMetadata = $this->_classReflector->reflectClassMethods($serviceClass, $this->_soapServices[$serviceName][self::KEY_SERVICE_METHODS]);
             // TODO: Consider service documentation extraction via reflection
             $this->_soapServices[$serviceName][self::KEY_SERVICE_METHODS] = array_merge_recursive($this->_soapServices[$serviceName][self::KEY_SERVICE_METHODS], $reflectedMethodsMetadata);
         }
     }
     return $this->_soapServices;
 }