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

Class implementing one SAX progressive push parser. More...

Public Member Functions

 __construct ($case_folding=false)
 
 process ()
 
 set_contents ($contents)
 
 set_file ($file)
 
 set_processor ($processor)
 
 set_progress (\core\progress\base $progress)
 Sets the progress tracker for the parser.
 

Static Public Member Functions

static dirname ($path)
 Provides one cross-platform dirname function for handling parser paths, see MDL-24381
 

Protected Member Functions

 char_data ($parser, $data)
 
 end_tag ($parser, $tag)
 
 inform_end ($path)
 Inform to the processor that we have finished parsing one path.
 
 inform_start ($path)
 Inform to the processor that we have started parsing one path.
 
 parse ($data, $eof)
 
 postprocess_cdata ($data)
 
 publish ($data)
 
 start_tag ($parser, $tag, $attributes)
 

Protected Attributes

 $accum
 
 $attrs
 
 $contents
 
 $currtag
 
 $file
 
 $level
 
 $path
 
 $prevlevel
 
progressive_parser_processor $processor
 to be used to publish processed information
 
core progress base $progress
 Progress tracker called for each action.
 
 $topush
 
 $xml_parser
 

Detailed Description

Class implementing one SAX progressive push parser.

SAX parser able to process XML content from files/variables. It supports attributes and case folding and works only with UTF-8 content. It's one progressive push parser because, intead of loading big crunchs of information in memory, it "publishes" (pushes) small information in a "propietary array format" througt the corresponding @progressive_parser_processor, that will be the responsibe for returning information into handy formats to higher levels.

Note that, while this progressive parser is able to process any XML file, it is 100% progressive so it publishes the information in the original order it's parsed (that's the expected behaviour) so information belonging to the same path can be returned in different chunks if there are inner levels/paths in the middle. Be warned!

The "propietary array format" that the parser publishes to the @progressive_parser_processor is this: array ( 'path' => path where the tags belong to, 'level'=> level (1-based) of the tags 'tags => array ( 'name' => name of the tag, 'attrs'=> array( name of the attr => value of the attr), 'cdata => cdata of the tag ) )

TODO: Finish phpdocs

Member Function Documentation

◆ set_progress()

progressive_parser::set_progress ( \core\progress\base $progress)

Sets the progress tracker for the parser.

If set, the tracker will be called to report indeterminate progress for each chunk of XML.

The caller should have already called start_progress on the progress tracker.

Parameters
core\progress\base$progressProgress tracker

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