Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mbz_packer Class Reference

Utility class - handles all packing/unpacking of .mbz files. More...

Inheritance diagram for mbz_packer:
file_packer

Public Member Functions

 archive_to_pathname (array $files, $archivefile, $ignoreinvalidfiles=true, file_progress $progress=null)
 Archive files and store the result in an OS file.
 
 archive_to_storage (array $files, $contextid, $component, $filearea, $itemid, $filepath, $filename, $userid=null, $ignoreinvalidfiles=true, file_progress $progress=null)
 Archive files and store the result in file storage.
 
 extract_to_pathname ($archivefile, $pathname, array $onlyfiles=null, file_progress $progress=null, $returnbool=false)
 Extract file to given file path (real OS filesystem), existing files are overwritten.
 
 extract_to_storage ($archivefile, $contextid, $component, $filearea, $itemid, $pathbase, $userid=null, file_progress $progress=null)
 Extract file to given file path (real OS filesystem), existing files are overwritten.
 
 list_files ($archivefile)
 Returns array of info about all files in archive.
 

Protected Member Functions

 get_packer_for_archive_operation ()
 Selects appropriate packer for new archive depending on system option and whether required extension is available.
 
 get_packer_for_read_operation ($archivefile)
 Selects appropriate packer for existing archive depending on file contents.
 

Detailed Description

Utility class - handles all packing/unpacking of .mbz files.

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

Member Function Documentation

◆ archive_to_pathname()

mbz_packer::archive_to_pathname ( array $files,
$archivefile,
$ignoreinvalidfiles = true,
file_progress $progress = null )

Archive files and store the result in an OS file.

Parameters
array$filesarray from archive path => pathname or stored_file
string$archivefilepath to target zip file
bool$ignoreinvalidfilestrue means ignore missing or invalid files, false means abort on any error
file_progress$progressProgress indicator callback or null if not required
Return values
booltrue if file created, false if not
Exceptions
coding_exceptionIf any archive paths do not meet the restrictions

Reimplemented from file_packer.

◆ archive_to_storage()

mbz_packer::archive_to_storage ( array $files,
$contextid,
$component,
$filearea,
$itemid,
$filepath,
$filename,
$userid = null,
$ignoreinvalidfiles = true,
file_progress $progress = null )

Archive files and store the result in file storage.

Any existing file at that location will be overwritten.

Parameters
array$filesarray from archive path => pathname or stored_file
int$contextidcontext ID
string$componentcomponent
string$fileareafile area
int$itemiditem ID
string$filepathfile path
string$filenamefile name
int$useriduser ID
bool$ignoreinvalidfilestrue means ignore missing or invalid files, false means abort on any error
file_progress$progressProgress indicator callback or null if not required
Return values
stored_file|boolfalse if error stored_file instance if ok
Exceptions
file_exceptionIf file operations fail
coding_exceptionIf any archive paths do not meet the restrictions

Reimplemented from file_packer.

◆ extract_to_pathname()

mbz_packer::extract_to_pathname ( $archivefile,
$pathname,
array $onlyfiles = null,
file_progress $progress = null,
$returnbool = false )

Extract file to given file path (real OS filesystem), existing files are overwritten.

Parameters
stored_file | string$archivefilefull pathname of zip file or stored_file instance
string$pathnametarget directory
array$onlyfilesonly extract files present in the array
file_progress$progressProgress indicator callback or null if not required
bool$returnboolWhether to return a basic true/false indicating error state, or full per-file error details.
Return values
arraylist of processed files (name=>true)
Exceptions
moodle_exceptionIf error

Reimplemented from file_packer.

◆ extract_to_storage()

mbz_packer::extract_to_storage ( $archivefile,
$contextid,
$component,
$filearea,
$itemid,
$pathbase,
$userid = null,
file_progress $progress = null )

Extract file to given file path (real OS filesystem), existing files are overwritten.

Parameters
string | stored_file$archivefilefull pathname of zip file or stored_file instance
int$contextidcontext ID
string$componentcomponent
string$fileareafile area
int$itemiditem ID
string$pathbasefile path
int$useriduser ID
file_progress$progressProgress indicator callback or null if not required
Return values
arraylist of processed files (name=>true)
Exceptions
moodle_exceptionIf error

Reimplemented from file_packer.

◆ get_packer_for_archive_operation()

mbz_packer::get_packer_for_archive_operation ( )
protected

Selects appropriate packer for new archive depending on system option and whether required extension is available.

Return values
file_packerSuitable packer

◆ get_packer_for_read_operation()

mbz_packer::get_packer_for_read_operation ( $archivefile)
protected

Selects appropriate packer for existing archive depending on file contents.

Parameters
string | stored_file$archivefilefull pathname of zip file or stored_file instance
Return values
file_packerSuitable packer

◆ list_files()

mbz_packer::list_files ( $archivefile)

Returns array of info about all files in archive.

Parameters
string | stored_file$archivefile
Return values
arrayof file infos

Reimplemented from file_packer.


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