Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
xhtml_container_stack Class Reference

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). More...
 
 pop ($type)
 Pop the HTML for the next closing container from the stack. More...
 
 pop_all_but_last ($shouldbenone=false)
 Close all but the last open container. More...
 
 push ($type, $closehtml)
 Push the close HTML for a recently opened container onto the stack. More...
 

Protected Member Functions

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

Protected Attributes

boolean $isdebugging
 Store whether we are developer debug mode. More...
 
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.
 

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: