Elgg  Version master
Public Member Functions | List of all members
Elgg\Context Class Reference

Manages a global stack of strings for sharing information about the current execution context. More...

Public Member Functions

 __construct (HttpRequest $request)
 Initialize the context from the request. More...
 
 peek ()
 Get the most recently pushed context value. More...
 
 push (string $context)
 Push a context onto the top of the stack. More...
 
 pop ()
 Removes and returns the top context string from the stack. More...
 
 set (string $context)
 Sets the page context. More...
 
 contains (string $context)
 Check if this context exists anywhere in the stack. More...
 
 toArray ()
 Get the entire context stack as an array (e.g. More...
 
 fromArray (array $stack)
 Overwrite the entire context stack from an array of strings. More...
 

Detailed Description

Manages a global stack of strings for sharing information about the current execution context.

Views can modify their output based on the local context. You may want to display a list of blogs on a blog page or in a small widget. The rendered output could be different for those two contexts ('blog' vs 'widget').

Pages that pass through the page handling system set the context to the first string after the root url. Example: http://example.org/elgg/bookmarks/ results in the initial context being set to 'bookmarks'.

The context is a stack so that for a widget on a profile, the context stack may contain first 'profile' and then 'widget'.

Warning
The context is not available until the page_handler runs (after the 'init, system' event processing has completed).

Definition at line 27 of file Context.php.

Constructor & Destructor Documentation

Elgg\Context::__construct ( HttpRequest  $request)

Initialize the context from the request.

Parameters
HttpRequest$requestElgg request

Definition at line 36 of file Context.php.

Member Function Documentation

Elgg\Context::contains ( string  $context)

Check if this context exists anywhere in the stack.

This is useful for situations with more than one element in the stack. For example, a widget has a context of 'widget'. If a widget view needs to render itself differently based on being on the dashboard or profile pages, it can check the stack.

Parameters
string$contextThe context string to check for
Returns
bool

Definition at line 109 of file Context.php.

Elgg\Context::fromArray ( array  $stack)

Overwrite the entire context stack from an array of strings.

Parameters
string[]$stack All contexts to be placed on the stack
Returns
void

Definition at line 128 of file Context.php.

Elgg\Context::peek ( )

Get the most recently pushed context value.

Returns
string|null

Definition at line 53 of file Context.php.

Elgg\Context::pop ( )

Removes and returns the top context string from the stack.

Returns
string|null

Definition at line 73 of file Context.php.

Elgg\Context::push ( string  $context)

Push a context onto the top of the stack.

Parameters
string$contextThe context string to add to the context stack
Returns
void

Definition at line 64 of file Context.php.

Elgg\Context::set ( string  $context)

Sets the page context.

Parameters
string$contextThe context of the page
Returns
bool

Definition at line 83 of file Context.php.

Elgg\Context::toArray ( )

Get the entire context stack as an array (e.g.

for backing it up)

Returns
string[]

Definition at line 118 of file Context.php.


The documentation for this class was generated from the following file: