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 license@zend.com so we can send you a copy immediately.
Simplify context switching based on requested format

boolean
$_autoJsonSerialization= 'true'
JSON auto-serialization flag
true
Details
string
$_contextKey= ''contexts''
Controller property key to utilize for context switching
'contexts'
Details
string
$_contextParam= ''format''
Request parameter containing requested context
'format'
Details
boolean
$_disableLayout= 'true'
Whether or not to disable layouts when switching contexts
true
Details
array
$_specialConfig= 'array(
'setSuffix''
Methods that require special configuration
array(
'setSuffix'
Details
array
$_unconfigurable= 'array(
'setOptions''
Methods that are not configurable via setOptions and setConfig
array(
'setOptions'
Details
__construct(
array|\Zend_Config $options
=
null
)
:
void
Constructor
Name | Type | Description |
---|---|---|
$options | array|\Zend_Config |

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

_setCallbacks(
array $options
)
:
\Zend_Controller_Action_Helper_ContextSwitch
Set 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_ContextSwitch
Set 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_ContextSwitch
Set suffix from array
Name | Type | Description |
---|---|---|
$spec | array |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

_validateTrigger(
string $trigger
)
:
string
Validate 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|void
Add 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_ContextSwitch
Add 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_ContextSwitch
Add 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_ContextSwitch
Add 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_ContextSwitch
Add 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_ContextSwitch
Add 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_ContextSwitch
Clear 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_ContextSwitch
Clear 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_ContextSwitch
Remove all contexts
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

clearHeaders(
string $context
)
:
\Zend_Controller_Action_Helper_ContextSwitch
Clear 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_ContextSwitch
Strategy pattern: return object
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

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

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

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

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

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

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

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

getHeader(
string $context, string $header
)
:
string|null
Retrieve 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
)
:
array
Retrieve context headers
Returns all headers for a context as key/value pairs
Name | Type | Description |
---|---|---|
$context | string |
Type | Description |
---|---|
array |

getSuffix(
string $type
)
:
string
Retrieve 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
)
:
boolean
Does 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
)
:
bool
Does 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(
)
:
void
Initialize at start of action controller
Reset the view script suffix to the original state, or store the original state.

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

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

removeActionContext(
string $action, string|array $context
)
:
boolean
Remove 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
)
:
boolean
Clear a callback for a given context and trigger
Name | Type | Description |
---|---|---|
$context | string | |
$trigger | string |
Type | Description |
---|---|
boolean |

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

removeHeader(
string $context, string $header
)
:
boolean
Remove 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|void
Set 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_ContextSwitch
Overwrite and set multiple action contexts at once
Name | Type | Description |
---|---|---|
$contexts | array |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ContextSwitch | Provides a fluent interface |

setAutoDisableLayout(
boolean $flag
)
:
\Zend_Controller_Action_Helper_ContextSwitch
Set 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_ContextSwitch
Should 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_ContextSwitch
Set 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_ContextSwitch
Set 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_ContextSwitch
Set 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_ContextSwitch
Overwrite 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_ContextSwitch
Set 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_ContextSwitch
Set 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_ContextSwitch
Indicate 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_ContextSwitch
Customize 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_ContextSwitch
Set 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_ContextSwitch
Configure 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_ContextSwitch
Customize 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 |