1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Core
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Controller exception that can fork different actions, cause forward or redirect
29: *
30: */
31: class Mage_Core_Controller_Varien_Exception extends Exception
32: {
33: const RESULT_FORWARD = '_forward';
34: const RESULT_REDIRECT = '_redirect';
35:
36: protected $_resultCallback = null;
37: protected $_resultCallbackParams = array();
38: protected $_defaultActionName = 'noroute';
39: protected $_flags = array();
40:
41: /**
42: * Prepare data for forwarding action
43: *
44: * @param string $actionName
45: * @param string $controllerName
46: * @param string $moduleName
47: * @param array $params
48: * @return Mage_Core_Controller_Varien_Exception
49: */
50: public function prepareForward($actionName = null, $controllerName = null, $moduleName = null, array $params = array())
51: {
52: $this->_resultCallback = self::RESULT_FORWARD;
53: if (null === $actionName) {
54: $actionName = $this->_defaultActionName;
55: }
56: $this->_resultCallbackParams = array($actionName, $controllerName, $moduleName, $params);
57: return $this;
58: }
59:
60: /**
61: * Prepare data for redirecting
62: *
63: * @param string $path
64: * @param array $arguments
65: * @return Mage_Core_Controller_Varien_Exception
66: */
67: public function prepareRedirect($path, $arguments = array())
68: {
69: $this->_resultCallback = self::RESULT_REDIRECT;
70: $this->_resultCallbackParams($path, $arguments);
71: return $this;
72: }
73:
74: /**
75: * Prepare data for running a custom action
76: *
77: * @param string $actionName
78: * @return Mage_Core_Controller_Varien_Exception
79: */
80: public function prepareFork($actionName = null)
81: {
82: if (null === $actionName) {
83: $actionName = $this->_defaultActionName;
84: }
85: $this->_resultCallback = $actionName;
86: return $this;
87: }
88:
89: /**
90: * Prepare a flag data
91: *
92: * @param string $action
93: * @param string $flag
94: * @param bool $value
95: * @return Mage_Core_Controller_Varien_Exception
96: */
97: public function prepareFlag($action, $flag, $value)
98: {
99: $this->_flags[] = array($action, $flag, $value);
100: return $this;
101: }
102:
103: /**
104: * Return all set flags
105: *
106: * @return array
107: */
108: public function getResultFlags()
109: {
110: return $this->_flags;
111: }
112:
113: /**
114: * Return results as callback for a controller
115: *
116: * @return array
117: */
118: public function getResultCallback()
119: {
120: if (null === $this->_resultCallback) {
121: $this->prepareFork();
122: }
123: return array($this->_resultCallback, $this->_resultCallbackParams);
124: }
125: }
126: