Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
xhtml_container_stack Class Reference

This class keeps track of which HTML tags are currently open. More...

Public Member Functions

 __construct ()
 Constructor.
 
 discard ()
 You can call this function if you want to throw away an instance of this class without properly emptying the stack (for example, in a unit test).
 
 pop ($type)
 Pop the HTML for the next closing container from the stack.
 
 pop_all_but_last ($shouldbenone=false)
 Close all but the last open container.
 
 push ($type, $closehtml)
 Push the close HTML for a recently opened container onto the stack.
 

Protected Member Functions

 log ($action, $type)
 Adds an entry to the log.
 
 output_log ()
 Outputs the log's contents as a HTML list.
 

Protected Attributes

boolean $isdebugging
 Store whether we are developer debug mode.
 
array $log = array()
 In developer debug mode, stores a stack trace of all opens and closes, so we can output helpful error messages when there is a mismatch.
 
array $opencontainers = array()
 Stores the list of open containers.
 

Detailed Description

This class keeps track of which HTML tags are currently open.

This makes it much easier to always generate well formed XHTML output, even if execution terminates abruptly. Any time you output some opening HTML without the matching closing HTML, you should push the necessary close tags onto the stack.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Since
Moodle 2.0

Member Function Documentation

◆ discard()

xhtml_container_stack::discard ( )

You can call this function if you want to throw away an instance of this class without properly emptying the stack (for example, in a unit test).

Calling this method stops the destruct method from outputting a developer debug warning. After calling this method, the instance can no longer be used.

◆ log()

xhtml_container_stack::log ( $action,
$type )
protected

Adds an entry to the log.

Parameters
string$actionThe name of the action
string$typeThe type of action

◆ output_log()

xhtml_container_stack::output_log ( )
protected

Outputs the log's contents as a HTML list.

Return values
stringHTML list of the log

◆ pop()

xhtml_container_stack::pop ( $type)

Pop the HTML for the next closing container from the stack.

The $type must match the type passed when the container was opened, otherwise a warning will be output.

Parameters
string$typeThe type of container.
Return values
stringthe HTML required to close the container.

◆ pop_all_but_last()

xhtml_container_stack::pop_all_but_last ( $shouldbenone = false)

Close all but the last open container.

This is useful in places like error handling, where you want to close all the open containers (apart from <body>) before outputting the error message.

Parameters
bool$shouldbenoneassert that the stack should be empty now - causes a developer debug warning if it isn't.
Return values
stringthe HTML required to close any open containers inside <body>.

◆ push()

xhtml_container_stack::push ( $type,
$closehtml )

Push the close HTML for a recently opened container onto the stack.

Parameters
string$typeThe type of container. This is checked when pop() is called and must match, otherwise a developer debug warning is output.
string$closehtmlThe HTML required to close the container.

Member Data Documentation

◆ $isdebugging

boolean xhtml_container_stack::$isdebugging
protected

Store whether we are developer debug mode.

We need this in several places including in the destructor where we may not have access to $CFG.


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