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

Static Public Member Functions

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

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. More...
 
 add_message ($level, $msgcode, $a=null)
 Append the given message to the messages log. More...
 
 get_plugin_manager ()
 Returns plugin manager to use. More...
 
 get_stripped_file_contents ($fullpath)
 Returns bare PHP code from the given file. More...
 
 parse_version_php ($fullpath)
 Get as much information from existing version.php as possible. More...
 
 validate_files_layout ()
 Returns false if files in the ZIP do not have required layout. More...
 
 validate_language_pack ()
 Returns false if the English language pack is not provided correctly. More...
 
 validate_version_php ()
 Returns false if the version.php file does not declare required information. More...
 

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

◆ 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: