Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Router.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Cms\Controller;
7 
12 {
16  protected $actionFactory;
17 
23  protected $_eventManager;
24 
30  protected $_storeManager;
31 
37  protected $_pageFactory;
38 
44  protected $_appState;
45 
51  protected $_url;
52 
58  protected $_response;
59 
68  public function __construct(
69  \Magento\Framework\App\ActionFactory $actionFactory,
70  \Magento\Framework\Event\ManagerInterface $eventManager,
71  \Magento\Framework\UrlInterface $url,
72  \Magento\Cms\Model\PageFactory $pageFactory,
73  \Magento\Store\Model\StoreManagerInterface $storeManager,
74  \Magento\Framework\App\ResponseInterface $response
75  ) {
76  $this->actionFactory = $actionFactory;
77  $this->_eventManager = $eventManager;
78  $this->_url = $url;
79  $this->_pageFactory = $pageFactory;
80  $this->_storeManager = $storeManager;
81  $this->_response = $response;
82  }
83 
90  public function match(\Magento\Framework\App\RequestInterface $request)
91  {
92  $identifier = trim($request->getPathInfo(), '/');
93 
94  $condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]);
95  $this->_eventManager->dispatch(
96  'cms_controller_router_match_before',
97  ['router' => $this, 'condition' => $condition]
98  );
99  $identifier = $condition->getIdentifier();
100 
101  if ($condition->getRedirectUrl()) {
102  $this->_response->setRedirect($condition->getRedirectUrl());
103  $request->setDispatched(true);
104  return $this->actionFactory->create(\Magento\Framework\App\Action\Redirect::class);
105  }
106 
107  if (!$condition->getContinue()) {
108  return null;
109  }
110 
112  $page = $this->_pageFactory->create();
113  $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
114  if (!$pageId) {
115  return null;
116  }
117 
118  $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
119  $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
120 
121  return $this->actionFactory->create(\Magento\Framework\App\Action\Forward::class);
122  }
123 }
$response
Definition: 404.php:11
$storeManager
__construct(\Magento\Framework\App\ActionFactory $actionFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\UrlInterface $url, \Magento\Cms\Model\PageFactory $pageFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\ResponseInterface $response)
Definition: Router.php:68
$page
Definition: pages.php:8
match(RequestInterface $request)