Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Router Class Reference
Inheritance diagram for Router:
RouterInterface

Public Member Functions

 __construct (\Magento\Framework\App\ActionFactory $actionFactory, UrlInterface $url, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\ResponseInterface $response, UrlFinderInterface $urlFinder)
 
 match (RequestInterface $request)
 

Protected Member Functions

 processRedirect ($request, $rewrite)
 
 redirect ($request, $url, $code)
 
 getRewrite ($requestPath, $storeId)
 

Protected Attributes

 $actionFactory
 
 $url
 
 $storeManager
 
 $response
 
 $urlFinder
 

Detailed Description

UrlRewrite Controller Router

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 23 of file Router.php.

Constructor & Destructor Documentation

◆ __construct()

Parameters
\Magento\Framework\App\ActionFactory$actionFactory
UrlInterface$url
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\App\ResponseInterface$response
UrlFinderInterface$urlFinder

Definition at line 57 of file Router.php.

63  {
64  $this->actionFactory = $actionFactory;
65  $this->url = $url;
66  $this->storeManager = $storeManager;
67  $this->response = $response;
68  $this->urlFinder = $urlFinder;
69  }

Member Function Documentation

◆ getRewrite()

getRewrite (   $requestPath,
  $storeId 
)
protected
Parameters
string$requestPath
int$storeId
Returns
UrlRewrite|null

Definition at line 142 of file Router.php.

143  {
144  return $this->urlFinder->findOneByData([
145  UrlRewrite::REQUEST_PATH => ltrim($requestPath, '/'),
147  ]);
148  }

◆ match()

match ( RequestInterface  $request)

Match corresponding URL Rewrite and modify request.

Parameters
RequestInterface | HttpRequest$request
Returns
ActionInterface|null

Implements RouterInterface.

Definition at line 78 of file Router.php.

79  {
80  $rewrite = $this->getRewrite(
81  $request->getPathInfo(),
82  $this->storeManager->getStore()->getId()
83  );
84 
85  if ($rewrite === null) {
86  //No rewrite rule matching current URl found, continuing with
87  //processing of this URL.
88  return null;
89  }
90  if ($rewrite->getRedirectType()) {
91  //Rule requires the request to be redirected to another URL
92  //and cannot be processed further.
93  return $this->processRedirect($request, $rewrite);
94  }
95  //Rule provides actual URL that can be processed by a controller.
96  $request->setAlias(
98  $rewrite->getRequestPath()
99  );
100  $request->setPathInfo('/' . $rewrite->getTargetPath());
101  return $this->actionFactory->create(
102  \Magento\Framework\App\Action\Forward::class
103  );
104  }
processRedirect($request, $rewrite)
Definition: Router.php:112
getRewrite($requestPath, $storeId)
Definition: Router.php:142

◆ processRedirect()

processRedirect (   $request,
  $rewrite 
)
protected
Parameters
RequestInterface$request
UrlRewrite$rewrite
Returns
ActionInterface|null

Definition at line 112 of file Router.php.

113  {
114  $target = $rewrite->getTargetPath();
115  if ($rewrite->getEntityType() !== Rewrite::ENTITY_TYPE_CUSTOM
116  || ($prefix = substr($target, 0, 6)) !== 'http:/' && $prefix !== 'https:'
117  ) {
118  $target = $this->url->getUrl('', ['_direct' => $target]);
119  }
120  return $this->redirect($request, $target, $rewrite->getRedirectType());
121  }
$target
Definition: skip.phtml:8
$prefix
Definition: name.phtml:25
redirect($request, $url, $code)
Definition: Router.php:129

◆ redirect()

redirect (   $request,
  $url,
  $code 
)
protected
Parameters
RequestInterface | HttpRequest$request
string$url
int$code
Returns
ActionInterface

Definition at line 129 of file Router.php.

130  {
131  $this->response->setRedirect($url, $code);
132  $request->setDispatched(true);
133 
134  return $this->actionFactory->create(Redirect::class);
135  }
$code
Definition: info.phtml:12

Field Documentation

◆ $actionFactory

$actionFactory
protected

Definition at line 28 of file Router.php.

◆ $response

$response
protected

Definition at line 43 of file Router.php.

◆ $storeManager

$storeManager
protected

Definition at line 38 of file Router.php.

◆ $url

Magento Framework UrlInterface $url
protected

Definition at line 33 of file Router.php.

◆ $urlFinder

$urlFinder
protected

Definition at line 48 of file Router.php.


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