Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Action.php
Go to the documentation of this file.
1 <?php
7 
12 
25 abstract class Action extends AbstractAction
26 {
30  protected $_objectManager;
31 
38  protected $_sessionNamespace;
39 
43  protected $_eventManager;
44 
48  protected $_actionFlag;
49 
53  protected $_redirect;
54 
58  protected $_view;
59 
63  protected $_url;
64 
68  protected $messageManager;
69 
73  public function __construct(Context $context)
74  {
75  parent::__construct($context);
76  $this->_objectManager = $context->getObjectManager();
77  $this->_eventManager = $context->getEventManager();
78  $this->_url = $context->getUrl();
79  $this->_actionFlag = $context->getActionFlag();
80  $this->_redirect = $context->getRedirect();
81  $this->_view = $context->getView();
82  $this->messageManager = $context->getMessageManager();
83  }
84 
93  {
94  $this->_request = $request;
95  $profilerKey = 'CONTROLLER_ACTION:' . $request->getFullActionName();
96  $eventParameters = ['controller_action' => $this, 'request' => $request];
97  $this->_eventManager->dispatch('controller_action_predispatch', $eventParameters);
98  $this->_eventManager->dispatch('controller_action_predispatch_' . $request->getRouteName(), $eventParameters);
99  $this->_eventManager->dispatch(
100  'controller_action_predispatch_' . $request->getFullActionName(),
101  $eventParameters
102  );
103  \Magento\Framework\Profiler::start($profilerKey);
104 
105  $result = null;
106  if ($request->isDispatched() && !$this->_actionFlag->get('', self::FLAG_NO_DISPATCH)) {
107  \Magento\Framework\Profiler::start('action_body');
108  $result = $this->execute();
109  \Magento\Framework\Profiler::start('postdispatch');
110  if (!$this->_actionFlag->get('', self::FLAG_NO_POST_DISPATCH)) {
111  $this->_eventManager->dispatch(
112  'controller_action_postdispatch_' . $request->getFullActionName(),
113  $eventParameters
114  );
115  $this->_eventManager->dispatch(
116  'controller_action_postdispatch_' . $request->getRouteName(),
117  $eventParameters
118  );
119  $this->_eventManager->dispatch('controller_action_postdispatch', $eventParameters);
120  }
121  \Magento\Framework\Profiler::stop('postdispatch');
122  \Magento\Framework\Profiler::stop('action_body');
123  }
124  \Magento\Framework\Profiler::stop($profilerKey);
125  return $result ?: $this->_response;
126  }
127 
137  protected function _forward($action, $controller = null, $module = null, array $params = null)
138  {
139  $request = $this->getRequest();
140 
141  $request->initForward();
142 
143  if (isset($params)) {
144  $request->setParams($params);
145  }
146 
147  if (isset($controller)) {
148  $request->setControllerName($controller);
149 
150  // Module should only be reset if controller has been specified
151  if (isset($module)) {
152  $request->setModuleName($module);
153  }
154  }
155 
156  $request->setActionName($action);
157  $request->setDispatched(false);
158  }
159 
167  protected function _redirect($path, $arguments = [])
168  {
169  $this->_redirect->redirect($this->getResponse(), $path, $arguments);
170  return $this->getResponse();
171  }
172 
176  public function getActionFlag()
177  {
178  return $this->_actionFlag;
179  }
180 }
_redirect($path, $arguments=[])
Definition: Action.php:167
_forward($action, $controller=null, $module=null, array $params=null)
Definition: Action.php:137
$arguments
__construct(Context $context)
Definition: Action.php:73
dispatch(RequestInterface $request)
Definition: Action.php:92
$controller
Definition: info.phtml:14
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18