Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ControllerRest Class Reference

Public Member Functions

 __construct (ServiceConfig $serviceConfig, PathProcessor $pathProcessor)
 
 beforeDispatch (\Magento\Webapi\Controller\Rest $subject, RequestInterface $request)
 

Detailed Description

Definition at line 16 of file ControllerRest.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ServiceConfig  $serviceConfig,
PathProcessor  $pathProcessor 
)

ControllerRest constructor.

Parameters
ServiceConfig$serviceConfig
PathProcessor$pathProcessor

Definition at line 34 of file ControllerRest.php.

37  {
38  $this->serviceConfig = $serviceConfig;
39  $this->pathProcessor = $pathProcessor;
40  }

Member Function Documentation

◆ beforeDispatch()

beforeDispatch ( \Magento\Webapi\Controller\Rest  $subject,
RequestInterface  $request 
)

Apply route customization.

Parameters
\Magento\Webapi\Controller\Rest$subject
RequestInterface$request
Returns
array @SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 49 of file ControllerRest.php.

50  {
51  $routeCustomizations = $this->serviceConfig->getServices()[Converter::KEY_ROUTES] ?? [];
52  if ($routeCustomizations) {
53  $originPath = $request->getPathInfo();
54  $requestMethod = $request->getMethod();
55  $routePath = ltrim($this->pathProcessor->process($originPath), '/');
56  if (array_key_exists($routePath, $routeCustomizations)) {
57  if (isset($routeCustomizations[$routePath][$requestMethod])) {
58  $path = ltrim($routeCustomizations[$routePath][$requestMethod], '/');
59  $request->setPathInfo(str_replace($routePath, $path, $originPath));
60  }
61  }
62  }
63  return [$request];
64  }

The documentation for this class was generated from the following file: