Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Controller_Action_Helper_ContextSwitch Class Reference

Public Member Functions

 __construct ($options=null)
 Constructor.
 
 init ()
 Initialize at start of action controller.
 
 setOptions (array $options)
 Configure object from array of options.
 
 setConfig (Zend_Config $config)
 Set object state from config object.
 
 direct ()
 Strategy pattern: return object.
 
 initContext ($format=null)
 Initialize context detection and switching.
 
 initJsonContext ()
 JSON context extra initialization.
 
 setAutoJsonSerialization ($flag)
 Should JSON contexts auto-serialize?
 
 getAutoJsonSerialization ()
 Get JSON context auto-serialization flag.
 
 setSuffix ($context, $suffix, $prependViewRendererSuffix=true)
 Customize view script suffix to use when switching context.
 
 getSuffix ($type)
 Retrieve suffix for given context type.
 
 hasContext ($context, $throwException=false)
 Does the given context exist?
 
 addHeader ($context, $header, $content)
 Add header to context.
 
 setHeader ($context, $header, $content)
 Customize response header to use when switching context.
 
 addHeaders ($context, array $headers)
 Add multiple headers at once for a given context.
 
 setHeaders ($context, array $headers)
 Set multiple headers at once for a given context.
 
 getHeader ($context, $header)
 Retrieve context header.
 
 getHeaders ($context)
 Retrieve context headers.
 
 removeHeader ($context, $header)
 Remove a single header from a context.
 
 clearHeaders ($context)
 Clear all headers for a given context.
 
 setCallback ($context, $trigger, $callback)
 Set a callback for a given context and trigger.
 
 setCallbacks ($context, array $callbacks)
 Set callbacks for a given context.
 
 getCallback ($context, $trigger)
 Get a single callback for a given context and trigger.
 
 getCallbacks ($context)
 Get all callbacks for a given context.
 
 removeCallback ($context, $trigger)
 Clear a callback for a given context and trigger.
 
 clearCallbacks ($context)
 Clear all callbacks for a given context.
 
 setContextParam ($name)
 Set name of parameter to use when determining context format.
 
 getContextParam ()
 Return context format request parameter name.
 
 setDefaultContext ($type)
 Indicate default context to use when no context format provided.
 
 getDefaultContext ()
 Return default context.
 
 setAutoDisableLayout ($flag)
 Set flag indicating if layout should be disabled.
 
 getAutoDisableLayout ()
 Retrieve auto layout disable flag.
 
 addContext ($context, array $spec)
 Add new context.
 
 setContext ($context, array $spec)
 Overwrite existing context.
 
 addContexts (array $contexts)
 Add multiple contexts.
 
 setContexts (array $contexts)
 Set multiple contexts, after first removing all.
 
 getContext ($context)
 Retrieve context specification.
 
 getContexts ()
 Retrieve context definitions.
 
 removeContext ($context)
 Remove a context.
 
 clearContexts ()
 Remove all contexts.
 
 getCurrentContext ()
 Return current context, if any.
 
 postDispatch ()
 Post dispatch processing.
 
 postJsonContext ()
 JSON post processing.
 
 addActionContext ($action, $context)
 Add one or more contexts to an action.
 
 setActionContext ($action, $context)
 Set a context as available for a given controller action.
 
 addActionContexts (array $contexts)
 Add multiple action/context pairs at once.
 
 setActionContexts (array $contexts)
 Overwrite and set multiple action contexts at once.
 
 hasActionContext ($action, $context)
 Does a particular controller action have the given context(s)?
 
 getActionContexts ($action=null)
 Get contexts for a given action or all actions in the controller.
 
 removeActionContext ($action, $context)
 Remove one or more contexts for a given controller action.
 
 clearActionContexts ($action=null)
 Clear all contexts for a given controller action or all actions.
 
- Public Member Functions inherited from Zend_Controller_Action_Helper_Abstract
 setActionController (Zend_Controller_Action $actionController=null)
 setActionController()
 
 getActionController ()
 Retrieve current action controller.
 
 getFrontController ()
 Retrieve front controller instance.
 
 init ()
 Hook into action controller initialization.
 
 preDispatch ()
 Hook into action controller preDispatch() workflow.
 
 postDispatch ()
 Hook into action controller postDispatch() workflow.
 
 getRequest ()
 getRequest() -
 
 getResponse ()
 getResponse() -
 
 getName ()
 getName()
 

Public Attributes

const TRIGGER_INIT = 'TRIGGER_INIT'
 Trigger type constants.
 
const TRIGGER_POST = 'TRIGGER_POST'
 

Protected Member Functions

 _setSuffix (array $spec)
 Set suffix from array.
 
 _setHeaders (array $options)
 Set headers from context => headers pairs.
 
 _validateTrigger ($trigger)
 Validate trigger and return in normalized form.
 
 _setCallbacks (array $options)
 Set callbacks from array of context => callbacks pairs.
 
 _getViewRenderer ()
 Retrieve ViewRenderer.
 

Protected Attributes

 $_contexts = array()
 
 $_autoJsonSerialization = true
 
 $_contextKey = 'contexts'
 
 $_contextParam = 'format'
 
 $_currentContext
 
 $_defaultContext = 'xml'
 
 $_disableLayout = true
 
 $_specialConfig
 
 $_unconfigurable
 
 $_viewRenderer
 
 $_viewSuffixOrig
 
- Protected Attributes inherited from Zend_Controller_Action_Helper_Abstract
 $_actionController = null
 $_actionController
 
 $_frontController = null
 

Constructor & Destructor Documentation

__construct (   $options = null)

Constructor.

Parameters
array | Zend_Config$options
Returns
void

Member Function Documentation

_getViewRenderer ( )
protected

Retrieve ViewRenderer.

Returns
Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
_setCallbacks ( array  $options)
protected

Set callbacks from array of context => callbacks pairs.

Parameters
array$options
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
_setHeaders ( array  $options)
protected

Set headers from context => headers pairs.

Parameters
array$options
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
_setSuffix ( array  $spec)
protected

Set suffix from array.

Parameters
array$spec
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
See Also
Zend_Controller_Action_Exception
_validateTrigger (   $trigger)
protected

Validate trigger and return in normalized form.

Parameters
string$trigger
Exceptions
Zend_Controller_Action_Exception
Returns
string
See Also
Zend_Controller_Action_Exception
addActionContext (   $action,
  $context 
)

Add one or more contexts to an action.

Parameters
string$action
string | array$context
Returns
Zend_Controller_Action_Helper_ContextSwitch|void Provides a fluent interface
addActionContexts ( array  $contexts)

Add multiple action/context pairs at once.

Parameters
array$contexts
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
addContext (   $context,
array  $spec 
)

Add new context.

Parameters
string$contextContext type
array$specContext specification
Exceptions
Zend_Controller_Action_Exception
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
See Also
Zend_Controller_Action_Exception
addContexts ( array  $contexts)

Add multiple contexts.

Parameters
array$contexts
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
addHeader (   $context,
  $header,
  $content 
)

Add header to context.

Parameters
string$context
string$header
string$content
Exceptions
Zend_Controller_Action_Exception
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
See Also
Zend_Controller_Action_Exception
addHeaders (   $context,
array  $headers 
)

Add multiple headers at once for a given context.

Parameters
string$context
array$headers
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
clearActionContexts (   $action = null)

Clear all contexts for a given controller action or all actions.

Parameters
string$action
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
clearCallbacks (   $context)

Clear all callbacks for a given context.

Parameters
string$context
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
clearContexts ( )

Remove all contexts.

Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
clearHeaders (   $context)

Clear all headers for a given context.

Parameters
string$context
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
direct ( )

Strategy pattern: return object.

Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
getActionContexts (   $action = null)

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

Parameters
string$action
Returns
array
getAutoDisableLayout ( )

Retrieve auto layout disable flag.

Returns
boolean
getAutoJsonSerialization ( )

Get JSON context auto-serialization flag.

Returns
boolean
getCallback (   $context,
  $trigger 
)

Get a single callback for a given context and trigger.

Parameters
string$context
string$trigger
Returns
string|array|null
getCallbacks (   $context)

Get all callbacks for a given context.

Parameters
string$context
Returns
array
getContext (   $context)

Retrieve context specification.

Parameters
string$context
Returns
array|null
getContextParam ( )

Return context format request parameter name.

Returns
string
getContexts ( )

Retrieve context definitions.

Returns
array
getCurrentContext ( )

Return current context, if any.

Returns
null|string
getDefaultContext ( )

Return default context.

Returns
string
getHeader (   $context,
  $header 
)

Retrieve context header.

Returns the value of a given header for a given context type

Parameters
string$context
string$header
Returns
string|null
getHeaders (   $context)

Retrieve context headers.

Returns all headers for a context as key/value pairs

Parameters
string$context
Returns
array
getSuffix (   $type)

Retrieve suffix for given context type.

Parameters
string$typeContext type
Exceptions
Zend_Controller_Action_Exception
Returns
string
See Also
Zend_Controller_Action_Exception
hasActionContext (   $action,
  $context 
)

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

Parameters
string$action
string | array$context
Exceptions
Zend_Controller_Action_Exception
Returns
boolean
See Also
Zend_Controller_Action_Exception
Zend_Controller_Action_Exception
hasContext (   $context,
  $throwException = false 
)

Does the given context exist?

Parameters
string$context
boolean$throwException
Exceptions
Zend_Controller_Action_Exceptionif context does not exist and throwException is true
Returns
bool
See Also
Zend_Controller_Action_Exception
init ( )

Initialize at start of action controller.

Reset the view script suffix to the original state, or store the original state.

Returns
void
initContext (   $format = null)

Initialize context detection and switching.

Parameters
mixed$format
Exceptions
Zend_Controller_Action_Exception
Returns
void
See Also
Zend_Layout
Zend_Controller_Action_Exception
initJsonContext ( )

JSON context extra initialization.

Turns off viewRenderer auto-rendering

Returns
void
postDispatch ( )

Post dispatch processing.

Execute postDispatch callback for current context, if available

Exceptions
Zend_Controller_Action_Exception
Returns
void
See Also
Zend_Controller_Action_Exception
postJsonContext ( )

JSON post processing.

JSON serialize view variables to response body

Returns
void
See Also
Zend_Json
removeActionContext (   $action,
  $context 
)

Remove one or more contexts for a given controller action.

Parameters
string$action
string | array$context
Returns
boolean
removeCallback (   $context,
  $trigger 
)

Clear a callback for a given context and trigger.

Parameters
string$context
string$trigger
Returns
boolean
removeContext (   $context)

Remove a context.

Parameters
string$context
Returns
boolean
removeHeader (   $context,
  $header 
)

Remove a single header from a context.

Parameters
string$context
string$header
Returns
boolean
setActionContext (   $action,
  $context 
)

Set a context as available for a given controller action.

Parameters
string$action
string | array$context
Returns
Zend_Controller_Action_Helper_ContextSwitch|void Provides a fluent interface
setActionContexts ( array  $contexts)

Overwrite and set multiple action contexts at once.

Parameters
array$contexts
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setAutoDisableLayout (   $flag)

Set flag indicating if layout should be disabled.

Parameters
boolean$flag
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setAutoJsonSerialization (   $flag)

Should JSON contexts auto-serialize?

Parameters
boolean$flag
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setCallback (   $context,
  $trigger,
  $callback 
)

Set a callback for a given context and trigger.

Parameters
string$context
string$trigger
string | array$callback
Exceptions
Zend_Controller_Action_Exception
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
See Also
Zend_Controller_Action_Exception
setCallbacks (   $context,
array  $callbacks 
)

Set callbacks for a given context.

Callbacks should be in trigger/callback pairs.

Parameters
string$context
array$callbacks
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setConfig ( Zend_Config  $config)

Set object state from config object.

Parameters
Zend_Config$config
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setContext (   $context,
array  $spec 
)

Overwrite existing context.

Parameters
string$contextContext type
array$specContext specification
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setContextParam (   $name)

Set name of parameter to use when determining context format.

Parameters
string$name
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setContexts ( array  $contexts)

Set multiple contexts, after first removing all.

Parameters
array$contexts
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setDefaultContext (   $type)

Indicate default context to use when no context format provided.

Parameters
string$type
Exceptions
Zend_Controller_Action_Exception
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
See Also
Zend_Controller_Action_Exception
setHeader (   $context,
  $header,
  $content 
)

Customize response header to use when switching context.

Passing an empty header value to the setters disables the response header.

Parameters
string$typeContext type for which to set suffix
string$headerHeader to set
string$contentHeader content
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setHeaders (   $context,
array  $headers 
)

Set multiple headers at once for a given context.

Parameters
string$context
array$headers
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setOptions ( array  $options)

Configure object from array of options.

Parameters
array$options
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
setSuffix (   $context,
  $suffix,
  $prependViewRendererSuffix = true 
)

Customize view script suffix to use when switching context.

Passing an empty suffix value to the setters disables the view script suffix change.

Parameters
string$contextContext type for which to set suffix
string$suffixSuffix to use
boolean$prependViewRendererSuffixWhether or not to prepend the new suffix to the viewrenderer suffix
Exceptions
Zend_Controller_Action_Exception
Returns
Zend_Controller_Action_Helper_ContextSwitch Provides a fluent interface
See Also
Zend_Controller_Action_Exception

Member Data Documentation

$_autoJsonSerialization = true
protected
$_contextKey = 'contexts'
protected
$_contextParam = 'format'
protected
$_contexts = array()
protected
$_currentContext
protected
$_defaultContext = 'xml'
protected
$_disableLayout = true
protected
$_specialConfig
protected
Initial value:
= array(
'setSuffix',
'setHeaders',
'setCallbacks',
)
$_unconfigurable
protected
Initial value:
= array(
'setOptions',
'setConfig',
'setHeader',
'setCallback',
'setContext',
'setActionContext',
'setActionContexts',
)
$_viewRenderer
protected
$_viewSuffixOrig
protected
const TRIGGER_INIT = 'TRIGGER_INIT'

Trigger type constants.

const TRIGGER_POST = 'TRIGGER_POST'