Controller/Action/Helper/ContextSwitch.php

Show: PublicProtectedPrivateinherited
Table of Contents
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.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Controller  
Subpackage
Zend_Controller_Action_Helper  
Version
$Id$  

\Zend_Controller_Action_Helper_ContextSwitch

Package: Zend_Controller\Zend_Controller_Action_Helper
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-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Uses
 

Constants

>VConstant  TRIGGER_INIT = 'TRIGGER_INIT'
Trigger type constants
>VConstant  TRIGGER_POST = 'TRIGGER_POST'

Properties

>VPropertyprotectedboolean $_autoJsonSerialization = true
JSON auto-serialization flag
Default valuetrueDetails
Type
boolean
>VPropertyprotectedstring $_contextKey = 'contexts'
Controller property key to utilize for context switching
Default value'contexts'Details
Type
string
>VPropertyprotectedstring $_contextParam = 'format'
Request parameter containing requested context
Default value'format'Details
Type
string
>VPropertyprotectedarray $_contexts = array()
Supported contexts
Default valuearray()Details
Type
array
>VPropertyprotectedstring $_currentContext
Current context
Details
Type
string
>VPropertyprotectedstring $_defaultContext = 'xml'
Default context (xml)
Default value'xml'Details
Type
string
>VPropertyprotectedboolean $_disableLayout = true
Whether or not to disable layouts when switching contexts
Default valuetrueDetails
Type
boolean
>VPropertyprotectedarray $_specialConfig = array('setSuffix', 'setHeaders', 'setCallbacks')
Methods that require special configuration
Default valuearray('setSuffix', 'setHeaders', 'setCallbacks')Details
Type
array
>VPropertyprotectedarray $_unconfigurable = array('setOptions', 'setConfig', 'setHeader', 'setCallback', 'setContext', 'setActionContext', 'setActionContexts')
Methods that are not configurable via setOptions and setConfig
Default valuearray('setOptions', 'setConfig', 'setHeader', 'setCallback', 'setContext', 'setActionContext', 'setActionContexts')Details
Type
array
>VPropertyprotected\Zend_Controller_Action_Helper_ViewRenderer $_viewRenderer
>VPropertyprotectedstring $_viewSuffixOrig
Original view suffix prior to detecting context switch
Details
Type
string

Methods

methodpublic__construct(array | \Zend_Config $options = null) : void

Constructor

Parameters
NameTypeDescription
$optionsarray | \Zend_Config
methodprotected_getViewRenderer() : \Zend_Controller_Action_Helper_ViewRenderer

Retrieve ViewRenderer

Returns
TypeDescription
\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface
methodprotected_setCallbacks(array $options) : \Zend_Controller_Action_Helper_ContextSwitch

Set callbacks from array of context => callbacks pairs

Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodprotected_setHeaders(array $options) : \Zend_Controller_Action_Helper_ContextSwitch

Set headers from context => headers pairs

Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodprotected_setSuffix(array $spec) : \Zend_Controller_Action_Helper_ContextSwitch

Set suffix from array

Parameters
NameTypeDescription
$specarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodprotected_validateTrigger(string $trigger) : string

Validate trigger and return in normalized form

Parameters
NameTypeDescription
$triggerstring
Returns
TypeDescription
string
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublicaddActionContext(string $action, string | array $context) : \Zend_Controller_Action_Helper_ContextSwitch | void

Add one or more contexts to an action

Parameters
NameTypeDescription
$actionstring
$contextstring | array
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitch | voidProvides a fluent interface
methodpublicaddActionContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch

Add multiple action/context pairs at once

Parameters
NameTypeDescription
$contextsarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicaddContext(string $context, array $spec) : \Zend_Controller_Action_Helper_ContextSwitch

Add new context

Parameters
NameTypeDescription
$contextstring

Context type

$specarray

Context specification

Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublicaddContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch

Add multiple contexts

Parameters
NameTypeDescription
$contextsarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicaddHeader(string $context, string $header, string $content) : \Zend_Controller_Action_Helper_ContextSwitch

Add header to context

Parameters
NameTypeDescription
$contextstring
$headerstring
$contentstring
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublicaddHeaders(string $context, array $headers) : \Zend_Controller_Action_Helper_ContextSwitch

Add multiple headers at once for a given context

Parameters
NameTypeDescription
$contextstring
$headersarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicclearActionContexts(string $action = null) : \Zend_Controller_Action_Helper_ContextSwitch

Clear all contexts for a given controller action or all actions

Parameters
NameTypeDescription
$actionstring
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicclearCallbacks(string $context) : \Zend_Controller_Action_Helper_ContextSwitch

Clear all callbacks for a given context

Parameters
NameTypeDescription
$contextstring
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicclearContexts() : \Zend_Controller_Action_Helper_ContextSwitch

Remove all contexts

Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicclearHeaders(string $context) : \Zend_Controller_Action_Helper_ContextSwitch

Clear all headers for a given context

Parameters
NameTypeDescription
$contextstring
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicdirect() : \Zend_Controller_Action_Helper_ContextSwitch

Strategy pattern: return object

Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicgetActionContexts(string $action = null) : array

Get contexts for a given action or all actions in the controller

Parameters
NameTypeDescription
$actionstring
Returns
TypeDescription
array
methodpublicgetAutoDisableLayout() : boolean

Retrieve auto layout disable flag

Returns
TypeDescription
boolean
methodpublicgetAutoJsonSerialization() : boolean

Get JSON context auto-serialization flag

Returns
TypeDescription
boolean
methodpublicgetCallback(string $context, string $trigger) : string | array | null

Get a single callback for a given context and trigger

Parameters
NameTypeDescription
$contextstring
$triggerstring
Returns
TypeDescription
string | array | null
methodpublicgetCallbacks(string $context) : array

Get all callbacks for a given context

Parameters
NameTypeDescription
$contextstring
Returns
TypeDescription
array
methodpublicgetContext(string $context) : array | null

Retrieve context specification

Parameters
NameTypeDescription
$contextstring
Returns
TypeDescription
array | null
methodpublicgetContextParam() : string

Return context format request parameter name

Returns
TypeDescription
string
methodpublicgetContexts() : array

Retrieve context definitions

Returns
TypeDescription
array
methodpublicgetCurrentContext() : null | string

Return current context, if any

Returns
TypeDescription
null | string
methodpublicgetDefaultContext() : string

Return default context

Returns
TypeDescription
string
methodpublicgetHeader(string $context, string $header) : string | null

Retrieve context header

Returns the value of a given header for a given context type
Parameters
NameTypeDescription
$contextstring
$headerstring
Returns
TypeDescription
string | null
methodpublicgetHeaders(string $context) : array

Retrieve context headers

Returns all headers for a context as key/value pairs
Parameters
NameTypeDescription
$contextstring
Returns
TypeDescription
array
methodpublicgetSuffix(string $type) : string

Retrieve suffix for given context type

Parameters
NameTypeDescription
$typestring

Context type

Returns
TypeDescription
string
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublichasActionContext(string $action, string | array $context) : boolean

Does a particular controller action have the given context(s)?

Parameters
NameTypeDescription
$actionstring
$contextstring | array
Returns
TypeDescription
boolean
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublichasContext(string $context, boolean $throwException = false) : bool

Does the given context exist?

Parameters
NameTypeDescription
$contextstring
$throwExceptionboolean
Returns
TypeDescription
bool
Throws
ExceptionDescription
\Zend_Controller_Action_Exceptionif context does not exist and throwException is true
methodpublicinit() : void

Initialize at start of action controller

Reset the view script suffix to the original state, or store the original state.
methodpublicinitContext(mixed $format = null) : void

Initialize context detection and switching

Parameters
NameTypeDescription
$formatmixed
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublicinitJsonContext() : void

JSON context extra initialization

Turns off viewRenderer auto-rendering
methodpublicpostDispatch() : void

Post dispatch processing

Execute postDispatch callback for current context, if available
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublicpostJsonContext() : void

JSON post processing

JSON serialize view variables to response body
methodpublicremoveActionContext(string $action, string | array $context) : boolean

Remove one or more contexts for a given controller action

Parameters
NameTypeDescription
$actionstring
$contextstring | array
Returns
TypeDescription
boolean
methodpublicremoveCallback(string $context, string $trigger) : boolean

Clear a callback for a given context and trigger

Parameters
NameTypeDescription
$contextstring
$triggerstring
Returns
TypeDescription
boolean
methodpublicremoveContext(string $context) : boolean

Remove a context

Parameters
NameTypeDescription
$contextstring
Returns
TypeDescription
boolean
methodpublicremoveHeader(string $context, string $header) : boolean

Remove a single header from a context

Parameters
NameTypeDescription
$contextstring
$headerstring
Returns
TypeDescription
boolean
methodpublicsetActionContext(string $action, string | array $context) : \Zend_Controller_Action_Helper_ContextSwitch | void

Set a context as available for a given controller action

Parameters
NameTypeDescription
$actionstring
$contextstring | array
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitch | voidProvides a fluent interface
methodpublicsetActionContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch

Overwrite and set multiple action contexts at once

Parameters
NameTypeDescription
$contextsarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetAutoDisableLayout(boolean $flag) : \Zend_Controller_Action_Helper_ContextSwitch

Set flag indicating if layout should be disabled

Parameters
NameTypeDescription
$flagboolean
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetAutoJsonSerialization(boolean $flag) : \Zend_Controller_Action_Helper_ContextSwitch

Should JSON contexts auto-serialize?

Parameters
NameTypeDescription
$flagboolean
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetCallback(string $context, string $trigger, string | array $callback) : \Zend_Controller_Action_Helper_ContextSwitch

Set a callback for a given context and trigger

Parameters
NameTypeDescription
$contextstring
$triggerstring
$callbackstring | array
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublicsetCallbacks(string $context, array $callbacks) : \Zend_Controller_Action_Helper_ContextSwitch

Set callbacks for a given context

Callbacks should be in trigger/callback pairs.
Parameters
NameTypeDescription
$contextstring
$callbacksarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetConfig(\Zend_Config $config) : \Zend_Controller_Action_Helper_ContextSwitch

Set object state from config object

Parameters
NameTypeDescription
$config\Zend_Config
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetContext(string $context, array $spec) : \Zend_Controller_Action_Helper_ContextSwitch

Overwrite existing context

Parameters
NameTypeDescription
$contextstring

Context type

$specarray

Context specification

Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetContextParam(string $name) : \Zend_Controller_Action_Helper_ContextSwitch

Set name of parameter to use when determining context format

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetContexts(array $contexts) : \Zend_Controller_Action_Helper_ContextSwitch

Set multiple contexts, after first removing all

Parameters
NameTypeDescription
$contextsarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetDefaultContext(string $type) : \Zend_Controller_Action_Helper_ContextSwitch

Indicate default context to use when no context format provided

Parameters
NameTypeDescription
$typestring
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
methodpublicsetHeader( $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.
Parameters
NameTypeDescription
$context
$headerstring

Header to set

$contentstring

Header content

Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetHeaders(string $context, array $headers) : \Zend_Controller_Action_Helper_ContextSwitch

Set multiple headers at once for a given context

Parameters
NameTypeDescription
$contextstring
$headersarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetOptions(array $options) : \Zend_Controller_Action_Helper_ContextSwitch

Configure object from array of options

Parameters
NameTypeDescription
$optionsarray
Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
methodpublicsetSuffix(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.
Parameters
NameTypeDescription
$contextstring

Context type for which to set suffix

$suffixstring

Suffix to use

$prependViewRendererSuffixboolean

Whether or not to prepend the new suffix to the viewrenderer suffix

Returns
TypeDescription
\Zend_Controller_Action_Helper_ContextSwitchProvides a fluent interface
Throws
ExceptionDescription
\Zend_Controller_Action_Exception
Documentation was generated by phpDocumentor 2.2.0 .