Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ControllerRest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
15 
17 {
21  private $serviceConfig;
22 
26  private $pathProcessor;
27 
34  public function __construct(
35  ServiceConfig $serviceConfig,
36  PathProcessor $pathProcessor
37  ) {
38  $this->serviceConfig = $serviceConfig;
39  $this->pathProcessor = $pathProcessor;
40  }
41 
49  public function beforeDispatch(\Magento\Webapi\Controller\Rest $subject, RequestInterface $request)
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  }
65 }
__construct(ServiceConfig $serviceConfig, PathProcessor $pathProcessor)
beforeDispatch(\Magento\Webapi\Controller\Rest $subject, RequestInterface $request)