123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- /**
- *
- * Cube Framework $Id$ CBEPj2TttQrY75HSDT6Q9fJrsTTxInXqMo0cRpSl3jY=
- *
- * @link http://codecu.be/framework
- * @copyright Copyright (c) 2014 CodeCube SRL
- * @license http://codecu.be/framework/license Commercial License
- *
- * @version 1.0
- */
- /**
- * abstract action controller class
- * application controllers will extend from this class
- */
- namespace Cube\Controller\Action;
- use Cube\Controller\Request\AbstractRequest,
- Cube\Controller\Response\ResponseInterface;
- abstract class AbstractAction
- {
- /**
- *
- * request object
- *
- * @var \Cube\Controller\Request\AbstractRequest
- */
- protected $_request;
- /**
- *
- * response object
- *
- * @var \Cube\Controller\Response\ResponseInterface
- */
- protected $_response;
- /**
- *
- * action helper broker
- *
- * @var \Cube\Controller\Action\Helper\Broker
- */
- protected $_helper;
- /**
- *
- * class constructor
- *
- * @param \Cube\Controller\Request\AbstractRequest $request
- * @param \Cube\Controller\Response\ResponseInterface $response
- */
- public function __construct(AbstractRequest $request, ResponseInterface $response)
- {
- $this->setRequest($request)
- ->setResponse($response);
- $this->_helper = new Helper\Broker($this);
- $this->init();
- }
- /**
- *
- * function run when controller is initialized, can be overridden if functionality is needed to apply for
- * all actions
- */
- public function init()
- {
- }
- /**
- *
- * return request object
- *
- * @return \Cube\Controller\Request\AbstractRequest
- */
- public function getRequest()
- {
- return $this->_request;
- }
- /**
- *
- * set request object
- *
- * @param \Cube\Controller\Request\AbstractRequest $request
- *
- * @return \Cube\Controller\Action\AbstractAction
- */
- public function setRequest(AbstractRequest $request)
- {
- $this->_request = $request;
- return $this;
- }
- /**
- *
- * get response object
- *
- * @return \Cube\Controller\Response\ResponseInterface
- */
- public function getResponse()
- {
- return $this->_response;
- }
- /**
- *
- * set response object
- *
- * @param \Cube\Controller\Response\ResponseInterface $response
- *
- * @return \Cube\Controller\Action\AbstractAction
- */
- public function setResponse(ResponseInterface $response)
- {
- $this->_response = $response;
- return $this;
- }
- /**
- *
- * forward to another action/controller/module
- *
- * used by the front controller dispatcher and initiates a dispatch loop
- * the pre-dispatch and post-dispatch plugins will be run on each loop
- *
- * @param string $action
- * @param string $controller
- * @param string $module
- * @param array|null $params
- */
- final protected function _forward($action, $controller = null, $module = null, $params = null)
- {
- $request = $this->getRequest();
- if ($controller !== null) {
- $request->setController($controller);
- }
- if ($module !== null) {
- $request->setModule($module);
- }
- if ($params !== null) {
- $request->setParams($params);
- }
- $request->setAction($action)
- ->setDispatched(false);
- }
- }
|