This class keeps track of which HTML tags are currently open.
More...
|
| __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.
|
|
|
| log ($action, $type) |
| Adds an entry to the log.
|
|
| output_log () |
| Outputs the log's contents as a HTML list.
|
|
|
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.
|
|
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.
- Copyright
- 2009 Tim Hunt
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- Since
- Moodle 2.0
◆ 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 | $action | The name of the action |
string | $type | The type of action |
◆ output_log()
xhtml_container_stack::output_log |
( |
| ) |
|
|
protected |
Outputs the log's contents as a HTML list.
- Return values
-
string | HTML 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 | $type | The type of container. |
- Return values
-
string | the 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 | $shouldbenone | assert that the stack should be empty now - causes a developer debug warning if it isn't. |
- Return values
-
string | the 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 | $type | The type of container. This is checked when pop() is called and must match, otherwise a developer debug warning is output. |
string | $closehtml | The HTML required to close the container. |
◆ $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: