Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
tool_customlang\local\mlang\phpparser Class Reference

Parser of Moodle strings defined as associative array. More...

Public Member Functions

 __clone ()
 Prevent from cloning the instance.
 
 parse (string $data, int $format=2)
 Parses the given data in Moodle PHP string format.
 

Static Public Member Functions

static get_instance ()
 Get the singleton instance fo this class.
 

Protected Member Functions

 decapsulate (string $text)
 Given one T_CONSTANT_ENCAPSED_STRING, return its value without quotes.
 
 extract_strings (string $data)
 Low level parsing method.
 

Detailed Description

Parser of Moodle strings defined as associative array.

Moodle core just includes this file format directly as normal PHP code. However for security reasons, we must not do this for files uploaded by anonymous users. This parser reconstructs the associative $string array without actually including the file.

Member Function Documentation

◆ decapsulate()

tool_customlang\local\mlang\phpparser::decapsulate ( string $text)
protected

Given one T_CONSTANT_ENCAPSED_STRING, return its value without quotes.

Also processes escaped quotes inside the text.

Note: This method is taken directly from local_amos as it is highly tested and robust.

Parameters
string$textvalue obtained by token_get_all()
Return values
stringvalue without quotes

◆ extract_strings()

tool_customlang\local\mlang\phpparser::extract_strings ( string $data)
protected

Low level parsing method.

Note: This method is adapted from local_amos as it is highly tested and robust. The priority is keeping it similar to the original one to make it easier to mantain.

Parameters
string$data
Return values
string[]the data strings

◆ get_instance()

static tool_customlang\local\mlang\phpparser::get_instance ( )
static

Get the singleton instance fo this class.

Return values
phpparsersingleton instance of phpparser

◆ parse()

tool_customlang\local\mlang\phpparser::parse ( string $data,
int $format = 2 )

Parses the given data in Moodle PHP string format.

Note: This method is adapted from local_amos as it is highly tested and robust. The priority is keeping it similar to the original one to make it easier to mantain.

Parameters
string$datadefinition of the associative array
int$formatthe data format on the input, defaults to the one used since 2.0
Return values
langstring[]array of langstrings of this file

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