Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Provides validation class to check the plugin ZIP contents Uses fragments of the local_plugins_archive_validator class copyrighted by Marina Glancy that is part of the local_plugins plugin.

Copyright: 2013, 2015 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 644 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: validator  - X-Ref

Validates the contents of extracted plugin ZIP file

instance($zipcontentpath, array $zipcontentfiles)   X-Ref
Factory method returning instance of the validator

param: string $zipcontentpath full path to the extracted ZIP contents
param: array $zipcontentfiles (string)filerelpath => (bool|string)true or error
return: \core\update\validator

assert_plugin_type($required)   X-Ref
Set the expected plugin type, fail the validation otherwise

param: string $required plugin type

assert_moodle_version($required)   X-Ref
Set the expectation that the plugin can be installed into the given Moodle version

param: string $required Moodle version we are about to install to

execute()   X-Ref
Execute the validation process against all explicit and implicit requirements

Returns true if the validation passes (all explicit and implicit requirements
pass) and the plugin can be installed. Returns false if the validation fails
(some explicit or implicit requirement fails) and the plugin must not be
installed.

return: bool

get_result()   X-Ref
Returns overall result of the validation.

Null is returned if the validation has not been executed yet. Otherwise
this method returns true (the installation can continue) or false (it is not
safe to continue with the installation).

return: bool|null

get_messages()   X-Ref
Return the list of validation log messages

Each validation message is a plain object with properties level, msgcode
and addinfo.

return: array of (int)index => (stdClass) validation message

message_level_name($level)   X-Ref
Returns human readable localised name of the given log level.

param: string $level e.g. self::INFO
return: string

message_code_name($msgcode)   X-Ref
If defined, returns human readable validation code.

Otherwise, it simply returns the code itself as a fallback.

param: string $msgcode
return: string

message_help_icon($msgcode)   X-Ref
Returns help icon for the message code if defined.

param: string $msgcode
return: \help_icon|false

message_code_info($msgcode, $addinfo)   X-Ref
Localizes the message additional info if it exists.

param: string $msgcode
param: array|string|null $addinfo value for the $a placeholder in the string
return: string

get_versionphp_info()   X-Ref
Return the information provided by the the plugin's version.php

If version.php was not found in the plugin, null is returned. Otherwise
the array is returned. It may be empty if no information was parsed
(which should not happen).

return: null|array

get_language_file_name()   X-Ref
Returns the name of the English language file without the .php extension

This can be used as a suggestion for fixing the plugin root directory in the
ZIP file during the upload. If no file was found, or multiple PHP files are
located in lang/en/ folder, then null is returned.

return: null|string

get_rootdir()   X-Ref
Returns the rootdir of the extracted package (after eventual renaming)

return: string|null

__construct($zipcontentpath, array $zipcontentfiles)   X-Ref
No public constructor, use {@link self::instance()} instead.

param: string $zipcontentpath full path to the extracted ZIP contents
param: array $zipcontentfiles (string)filerelpath => (bool|string)true or error

validate_files_layout()   X-Ref
Returns false if files in the ZIP do not have required layout.

return: bool

validate_version_php()   X-Ref
Returns false if the version.php file does not declare required information.

return: bool

validate_language_pack()   X-Ref
Returns false if the English language pack is not provided correctly.

return: bool

validate_target_location()   X-Ref
Returns false of the given add-on can't be installed into its location.

return: bool

parse_version_php($fullpath)   X-Ref
Get as much information from existing version.php as possible

param: string $fullpath full path to the version.php file
return: array of found meta-info declarations

add_message($level, $msgcode, $a = null)   X-Ref
Append the given message to the messages log

param: string $level e.g. self::ERROR
param: string $msgcode may form a string
param: string|array|object $a optional additional info suitable for {@link get_string()}

get_stripped_file_contents($fullpath)   X-Ref
Returns bare PHP code from the given file

Returns contents without PHP opening and closing tags, text outside php code,
comments and extra whitespaces.

param: string $fullpath full path to the file
return: string

get_plugintype_location($plugintype)   X-Ref
Returns the full path to the root directory of the given plugin type.

param: string $plugintype
return: string|null

get_plugin_manager()   X-Ref
Returns plugin manager to use.

return: core_plugin_manager