Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core\update\validator Class Reference

Validates the contents of extracted plugin ZIP file. More...

Public Member Functions

 assert_moodle_version ($required)
 Set the expectation that the plugin can be installed into the given Moodle version.
 
 assert_plugin_type ($required)
 Set the expected plugin type, fail the validation otherwise.
 
 execute ()
 Execute the validation process against all explicit and implicit requirements.
 
 get_language_file_name ()
 Returns the name of the English language file without the .php extension.
 
 get_messages ()
 Return the list of validation log messages.
 
 get_plugintype_location ($plugintype)
 Returns the full path to the root directory of the given plugin type.
 
 get_result ()
 Returns overall result of the validation.
 
 get_rootdir ()
 Returns the rootdir of the extracted package (after eventual renaming)
 
 get_versionphp_info ()
 Return the information provided by the the plugin's version.php.
 
 message_code_info ($msgcode, $addinfo)
 Localizes the message additional info if it exists.
 
 message_code_name ($msgcode)
 If defined, returns human readable validation code.
 
 message_help_icon ($msgcode)
 Returns help icon for the message code if defined.
 
 message_level_name ($level)
 Returns human readable localised name of the given log level.
 
 validate_target_location ()
 Returns false of the given add-on can't be installed into its location.
 

Static Public Member Functions

static instance ($zipcontentpath, array $zipcontentfiles)
 Factory method returning instance of the validator.
 

Public Attributes

const DEBUG = 'debug'
 Debugging message level, should be displayed in debugging mode only.
 
const ERROR = 'error'
 Critical error message level, causes the validation fail.
 
const INFO = 'info'
 Information message level that the admin should be aware of.
 
const WARNING = 'warning'
 Warning message level, validation does not fail but the admin should be always informed.
 

Protected Member Functions

 __construct ($zipcontentpath, array $zipcontentfiles)
 No public constructor, use self::instance() instead.
 
 add_message ($level, $msgcode, $a=null)
 Append the given message to the messages log.
 
 get_plugin_manager ()
 Returns plugin manager to use.
 
 get_stripped_file_contents ($fullpath)
 Returns bare PHP code from the given file.
 
 parse_version_php ($fullpath)
 Get as much information from existing version.php as possible.
 
 validate_files_layout ()
 Returns false if files in the ZIP do not have required layout.
 
 validate_language_pack ()
 Returns false if the English language pack is not provided correctly.
 
 validate_version_php ()
 Returns false if the version.php file does not declare required information.
 

Protected Attributes

array $assertions = null
 explicit list of expected/required characteristics of the ZIP
 
string $extractdir = null
 full path to the extracted ZIP contents
 
array $extractfiles = null
 as returned by zip_packer::extract_to_pathname()
 
string null $langfilename = null
 the name of found English language file without the .php extension
 
array $messages = array()
 of validation log messages
 
bool $result = null
 overall result of validation
 
string $rootdir = null
 the name of the plugin root directory
 
array null $versionphp = null
 array of relevant data obtained from version.php
 

Detailed Description

Validates the contents of extracted plugin ZIP file.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core\update\validator::__construct ( $zipcontentpath,
array $zipcontentfiles )
protected

No public constructor, use self::instance() instead.

Parameters
string$zipcontentpathfull path to the extracted ZIP contents
array$zipcontentfiles(string)filerelpath => (bool|string)true or error

Member Function Documentation

◆ add_message()

core\update\validator::add_message ( $level,
$msgcode,
$a = null )
protected

Append the given message to the messages log.

Parameters
string$levele.g. self\ERROR
string$msgcodemay form a string
string | array | object$aoptional additional info suitable for get_string()

◆ assert_moodle_version()

core\update\validator::assert_moodle_version ( $required)

Set the expectation that the plugin can be installed into the given Moodle version.

Parameters
string$requiredMoodle version we are about to install to

◆ assert_plugin_type()

core\update\validator::assert_plugin_type ( $required)

Set the expected plugin type, fail the validation otherwise.

Parameters
string$requiredplugin type

◆ execute()

core\update\validator::execute ( )

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 values
bool

◆ get_language_file_name()

core\update\validator::get_language_file_name ( )

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 values
null|string

◆ get_messages()

core\update\validator::get_messages ( )

Return the list of validation log messages.

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

Return values
arrayof (int)index => (stdClass) validation message

◆ get_plugin_manager()

core\update\validator::get_plugin_manager ( )
protected

Returns plugin manager to use.

Return values
core_plugin_manager

◆ get_plugintype_location()

core\update\validator::get_plugintype_location ( $plugintype)

Returns the full path to the root directory of the given plugin type.

Parameters
string$plugintype
Return values
string|null

◆ get_result()

core\update\validator::get_result ( )

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 values
bool|null

◆ get_rootdir()

core\update\validator::get_rootdir ( )

Returns the rootdir of the extracted package (after eventual renaming)

Return values
string|null

◆ get_stripped_file_contents()

core\update\validator::get_stripped_file_contents ( $fullpath)
protected

Returns bare PHP code from the given file.

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

Parameters
string$fullpathfull path to the file
Return values
string

◆ get_versionphp_info()

core\update\validator::get_versionphp_info ( )

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 values
null|array

◆ instance()

static core\update\validator::instance ( $zipcontentpath,
array $zipcontentfiles )
static

Factory method returning instance of the validator.

Parameters
string$zipcontentpathfull path to the extracted ZIP contents
array$zipcontentfiles(string)filerelpath => (bool|string)true or error
Return values
core\update\validator

◆ message_code_info()

core\update\validator::message_code_info ( $msgcode,
$addinfo )

Localizes the message additional info if it exists.

Parameters
string$msgcode
array | string | null$addinfovalue for the $a placeholder in the string
Return values
string

◆ message_code_name()

core\update\validator::message_code_name ( $msgcode)

If defined, returns human readable validation code.

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

Parameters
string$msgcode
Return values
string

◆ message_help_icon()

core\update\validator::message_help_icon ( $msgcode)

Returns help icon for the message code if defined.

Parameters
string$msgcode
Return values
help_icon|false

◆ message_level_name()

core\update\validator::message_level_name ( $level)

Returns human readable localised name of the given log level.

Parameters
string$levele.g. self\INFO
Return values
string

◆ parse_version_php()

core\update\validator::parse_version_php ( $fullpath)
protected

Get as much information from existing version.php as possible.

Parameters
string$fullpathfull path to the version.php file
Return values
arrayof found meta-info declarations

◆ validate_files_layout()

core\update\validator::validate_files_layout ( )
protected

Returns false if files in the ZIP do not have required layout.

Return values
bool

◆ validate_language_pack()

core\update\validator::validate_language_pack ( )
protected

Returns false if the English language pack is not provided correctly.

Return values
bool

◆ validate_target_location()

core\update\validator::validate_target_location ( )

Returns false of the given add-on can't be installed into its location.

Return values
bool

◆ validate_version_php()

core\update\validator::validate_version_php ( )
protected

Returns false if the version.php file does not declare required information.

Return values
bool

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