Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Mlang PHP based on David Mudrak phpparser for local_amos.

Copyright: 2020 Ferran Recio <ferran@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 260 lines (9 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

phpparser:: (6 methods):
  __construct()
  __clone()
  get_instance()
  parse()
  extract_strings()
  decapsulate()


Class: phpparser  - X-Ref

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.
__construct()   X-Ref
Prevents direct creation of object


__clone()   X-Ref
Prevent from cloning the instance


get_instance()   X-Ref
Get the singleton instance fo this class

return: phpparser singleton instance of phpparser

parse(string $data, int $format = 2)   X-Ref
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.

param: string $data definition of the associative array
param: int $format the data format on the input, defaults to the one used since 2.0
return: langstring[] array of langstrings of this file

extract_strings(string $data)   X-Ref
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.

param: string $data
return: string[] the data strings

decapsulate(string $text)   X-Ref
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.

param: string $text value obtained by token_get_all()
return: string value without quotes