Controller/Action/Helper/ContextSwitch.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Controller
- Subpackage
- Zend_Controller_Action_Helper
- Version
- $Id: ContextSwitch.php 24864 2012-06-02 00:51:50Z adamlundrigan $
\Zend_Controller_Action_Helper_ContextSwitch
Simplify context switching based on requested format
- Parent(s)
- \Zend_Controller_Action_Helper_Abstract
- Children
- \Zend_Controller_Action_Helper_AjaxContext
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Uses
- \global\Zend_Controller_Action_Helper_Abstract
Constants
Properties

\Zend_Controller_Action $_actionController = null$_actionController
Inherited from: \Zend_Controller_Action_Helper_Abstract::$$_actionControllernullDetails- Type
- \Zend_Controller_Action
- Inherited_from
- \Zend_Controller_Action_Helper_Abstract::$$_actionController

boolean $_autoJsonSerialization = trueJSON auto-serialization flag
trueDetails- Type
- boolean

string $_contextKey = 'contexts'Controller property key to utilize for context switching
'contexts'Details- Type
- string

string $_contextParam = 'format'Request parameter containing requested context
'format'Details- Type
- string

boolean $_disableLayout = trueWhether or not to disable layouts when switching contexts
trueDetails- Type
- boolean

mixed $_frontController = nullnullDetails- Type
- mixed
- Inherited_from
- \Zend_Controller_Action_Helper_Abstract::$$_frontController

array $_specialConfig = array('setSuffix', 'setHeaders', 'setCallbacks')Methods that require special configuration
array('setSuffix', 'setHeaders', 'setCallbacks')Details- Type
- array

array $_unconfigurable = array('setOptions', 'setConfig', 'setHeader', 'setCallback', 'setContext', 'setActionContext', 'setActionContexts')Methods that are not configurable via setOptions and setConfig
array('setOptions', 'setConfig', 'setHeader', 'setCallback', 'setContext', 'setActionContext', 'setActionContexts')Details- Type
- array
Methods

__construct(array | \Zend_Config $options = null) : voidConstructor
| Name | Type | Description |
|---|---|---|
| $options | array | \Zend_Config |

_getViewRenderer() : \Zend_Controller_Action_Helper_ViewRendererRetrieve ViewRenderer
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |

_setCallbacks(array $options) : \Zend_Controller_Action_Helper_ContextSwitchSet callbacks from array of context => callbacks pairs
| Name | Type | Description |
|---|---|---|
| $options | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

_setHeaders(array $options) : \Zend_Controller_Action_Helper_ContextSwitchSet headers from context => headers pairs
| Name | Type | Description |
|---|---|---|
| $options | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

_setSuffix(array $spec) : \Zend_Controller_Action_Helper_ContextSwitchSet suffix from array
| Name | Type | Description |
|---|---|---|
| $spec | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

_validateTrigger(string $trigger) : stringValidate trigger and return in normalized form
| Name | Type | Description |
|---|---|---|
| $trigger | string |
| Type | Description |
|---|---|
| string |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

addActionContext(string $action, string | array $context) : \Zend_Controller_Action_Helper_ContextSwitch | voidAdd one or more contexts to an action
| Name | Type | Description |
|---|---|---|
| $action | string | |
| $context | string | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | void | Provides a fluent interface |

addActionContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitchAdd multiple action/context pairs at once
| Name | Type | Description |
|---|---|---|
| $contexts | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

addContext(string $context, array $spec) : \Zend_Controller_Action_Helper_ContextSwitchAdd new context
| Name | Type | Description |
|---|---|---|
| $context | string | Context type |
| $spec | array | Context specification |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

addContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitchAdd multiple contexts
| Name | Type | Description |
|---|---|---|
| $contexts | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

addHeader(string $context, string $header, string $content) : \Zend_Controller_Action_Helper_ContextSwitchAdd header to context
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $header | string | |
| $content | string |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

addHeaders(string $context, array $headers) : \Zend_Controller_Action_Helper_ContextSwitchAdd multiple headers at once for a given context
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $headers | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

clearActionContexts(string $action = null) : \Zend_Controller_Action_Helper_ContextSwitchClear all contexts for a given controller action or all actions
| Name | Type | Description |
|---|---|---|
| $action | string |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

clearCallbacks(string $context) : \Zend_Controller_Action_Helper_ContextSwitchClear all callbacks for a given context
| Name | Type | Description |
|---|---|---|
| $context | string |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

clearContexts() : \Zend_Controller_Action_Helper_ContextSwitchRemove all contexts
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

clearHeaders(string $context) : \Zend_Controller_Action_Helper_ContextSwitchClear all headers for a given context
| Name | Type | Description |
|---|---|---|
| $context | string |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

direct() : \Zend_Controller_Action_Helper_ContextSwitchStrategy pattern: return object
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

getActionContexts(string $action = null) : arrayGet contexts for a given action or all actions in the controller
| Name | Type | Description |
|---|---|---|
| $action | string |
| Type | Description |
|---|---|
| array |

getActionController() : \Zend_Controller_ActionRetrieve current action controller
Inherited from: \Zend_Controller_Action_Helper_Abstract::getActionController()| Type | Description |
|---|---|
| \Zend_Controller_Action |

getAutoJsonSerialization() : booleanGet JSON context auto-serialization flag
| Type | Description |
|---|---|
| boolean |

getCallback(string $context, string $trigger) : string | array | nullGet a single callback for a given context and trigger
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $trigger | string |
| Type | Description |
|---|---|
| string | array | null |

getCallbacks(string $context) : arrayGet all callbacks for a given context
| Name | Type | Description |
|---|---|---|
| $context | string |
| Type | Description |
|---|---|
| array |

getContext(string $context) : array | nullRetrieve context specification
| Name | Type | Description |
|---|---|---|
| $context | string |
| Type | Description |
|---|---|
| array | null |

getContextParam() : stringReturn context format request parameter name
| Type | Description |
|---|---|
| string |

getCurrentContext() : null | stringReturn current context, if any
| Type | Description |
|---|---|
| null | string |

getFrontController() : \Zend_Controller_FrontRetrieve front controller instance
Inherited from: \Zend_Controller_Action_Helper_Abstract::getFrontController()| Type | Description |
|---|---|
| \Zend_Controller_Front |

getHeader(string $context, string $header) : string | nullRetrieve context header
Returns the value of a given header for a given context type
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $header | string |
| Type | Description |
|---|---|
| string | null |

getHeaders(string $context) : arrayRetrieve context headers
Returns all headers for a context as key/value pairs
| Name | Type | Description |
|---|---|---|
| $context | string |
| Type | Description |
|---|---|
| array |

getRequest() : \Zend_Controller_Request_Abstract
| Type | Description |
|---|---|
| \Zend_Controller_Request_Abstract | $request |

getResponse() : \Zend_Controller_Response_Abstract
| Type | Description |
|---|---|
| \Zend_Controller_Response_Abstract | $response |

getSuffix(string $type) : stringRetrieve suffix for given context type
| Name | Type | Description |
|---|---|---|
| $type | string | Context type |
| Type | Description |
|---|---|
| string |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

hasActionContext(string $action, string | array $context) : booleanDoes a particular controller action have the given context(s)?
| Name | Type | Description |
|---|---|---|
| $action | string | |
| $context | string | array |
| Type | Description |
|---|---|
| boolean |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

hasContext(string $context, boolean $throwException = false) : boolDoes the given context exist?
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $throwException | boolean |
| Type | Description |
|---|---|
| bool |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception | if context does not exist and throwException is true |

init() : voidInitialize at start of action controller
Reset the view script suffix to the original state, or store the original state.

initContext(mixed $format = null) : voidInitialize context detection and switching
| Name | Type | Description |
|---|---|---|
| $format | mixed |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

postDispatch() : voidPost dispatch processing
Execute postDispatch callback for current context, if available
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

preDispatch() : voidHook into action controller preDispatch() workflow
Inherited from: \Zend_Controller_Action_Helper_Abstract::preDispatch()
removeActionContext(string $action, string | array $context) : booleanRemove one or more contexts for a given controller action
| Name | Type | Description |
|---|---|---|
| $action | string | |
| $context | string | array |
| Type | Description |
|---|---|
| boolean |

removeCallback(string $context, string $trigger) : booleanClear a callback for a given context and trigger
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $trigger | string |
| Type | Description |
|---|---|
| boolean |

removeContext(string $context) : booleanRemove a context
| Name | Type | Description |
|---|---|---|
| $context | string |
| Type | Description |
|---|---|
| boolean |

removeHeader(string $context, string $header) : booleanRemove a single header from a context
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $header | string |
| Type | Description |
|---|---|
| boolean |

setActionContext(string $action, string | array $context) : \Zend_Controller_Action_Helper_ContextSwitch | voidSet a context as available for a given controller action
| Name | Type | Description |
|---|---|---|
| $action | string | |
| $context | string | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | void | Provides a fluent interface |

setActionContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitchOverwrite and set multiple action contexts at once
| Name | Type | Description |
|---|---|---|
| $contexts | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setActionController(\Zend_Controller_Action $actionController = null) : \Zend_Controller_ActionHelper_AbstractsetActionController()
Inherited from: \Zend_Controller_Action_Helper_Abstract::setActionController()| Name | Type | Description |
|---|---|---|
| $actionController | \Zend_Controller_Action |
| Type | Description |
|---|---|
| \Zend_Controller_ActionHelper_Abstract | Provides a fluent interface |

setAutoDisableLayout(boolean $flag) : \Zend_Controller_Action_Helper_ContextSwitchSet flag indicating if layout should be disabled
| Name | Type | Description |
|---|---|---|
| $flag | boolean |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setAutoJsonSerialization(boolean $flag) : \Zend_Controller_Action_Helper_ContextSwitchShould JSON contexts auto-serialize?
| Name | Type | Description |
|---|---|---|
| $flag | boolean |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setCallback(string $context, string $trigger, string | array $callback) : \Zend_Controller_Action_Helper_ContextSwitchSet a callback for a given context and trigger
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $trigger | string | |
| $callback | string | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

setCallbacks(string $context, array $callbacks) : \Zend_Controller_Action_Helper_ContextSwitchSet callbacks for a given context
Callbacks should be in trigger/callback pairs.
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $callbacks | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setConfig(\Zend_Config $config) : \Zend_Controller_Action_Helper_ContextSwitchSet object state from config object
| Name | Type | Description |
|---|---|---|
| $config | \Zend_Config |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setContext(string $context, array $spec) : \Zend_Controller_Action_Helper_ContextSwitchOverwrite existing context
| Name | Type | Description |
|---|---|---|
| $context | string | Context type |
| $spec | array | Context specification |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setContextParam(string $name) : \Zend_Controller_Action_Helper_ContextSwitchSet name of parameter to use when determining context format
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitchSet multiple contexts, after first removing all
| Name | Type | Description |
|---|---|---|
| $contexts | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setDefaultContext(string $type) : \Zend_Controller_Action_Helper_ContextSwitchIndicate default context to use when no context format provided
| Name | Type | Description |
|---|---|---|
| $type | string |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |

setHeader( $context, string $header, string $content) : \Zend_Controller_Action_Helper_ContextSwitchCustomize response header to use when switching context
Passing an empty header value to the setters disables the response header.
| Name | Type | Description |
|---|---|---|
| $context | ||
| $header | string | Header to set |
| $content | string | Header content |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setHeaders(string $context, array $headers) : \Zend_Controller_Action_Helper_ContextSwitchSet multiple headers at once for a given context
| Name | Type | Description |
|---|---|---|
| $context | string | |
| $headers | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setOptions(array $options) : \Zend_Controller_Action_Helper_ContextSwitchConfigure object from array of options
| Name | Type | Description |
|---|---|---|
| $options | array |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setSuffix(string $context, string $suffix, boolean $prependViewRendererSuffix = true) : \Zend_Controller_Action_Helper_ContextSwitchCustomize view script suffix to use when switching context.
Passing an empty suffix value to the setters disables the view script suffix change.
| Name | Type | Description |
|---|---|---|
| $context | string | Context type for which to set suffix |
| $suffix | string | Suffix to use |
| $prependViewRendererSuffix | boolean | Whether or not to prepend the new suffix to the viewrenderer suffix |
| Type | Description |
|---|---|
| \Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |
| Exception | Description |
|---|---|
| \Zend_Controller_Action_Exception |