Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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