MediaWiki REL1_35
|
Public Member Functions | |
__construct ( $input, $filterCallback=null, $isFile=true, $options=[]) | |
Allow filtering an XML file. | |
getRootElement () | |
Get the root element. | |
Static Public Member Functions | |
static | newFromFilename ( $fname, $filterCallback=null) |
Alternative constructor: from filename. | |
static | newFromString ( $string, $filterCallback=null) |
Alternative constructor: from string. | |
Public Attributes | |
bool | $filterMatch = false |
Will be set to true if the optional element filter returned a match at some point. | |
mixed | $filterMatchType = false |
Will contain the type of filter hit if the optional element filter returned a match at some point. | |
string | $rootElement = '' |
Name of the document's root element, including any namespace as an expanded URL. | |
bool null | $wellFormed = null |
Will be set to true or false to indicate whether the file is well-formed XML. | |
Protected Attributes | |
string[] | $elementData = [] |
A stack of strings containing the data of each xml element as it's processed. | |
array | $elementDataContext = [] |
A stack of element names and attributes, as we process them. | |
callable null | $filterCallback |
int | $stackDepth = 0 |
Current depth of the data stack. | |
Private Member Functions | |
checkDTDIsSafe ( $internalSubset) | |
Check if the internal subset of the DTD is safe. | |
dtdHandler (XMLReader $reader) | |
Handle coming across a <!DOCTYPE declaration. | |
elementClose () | |
elementData ( $data) | |
elementOpen ( $name, $attribs) | |
expandNS ( $name, $namespaceURI) | |
getAttributesArray (XMLReader $r) | |
Get all of the attributes for an XMLReader's current node. | |
parseDTD ( $dtd) | |
Parse DTD into parts. | |
processingInstructionHandler ( $target, $data) | |
readNext (XMLReader $reader) | |
validate ( $reader) | |
validateFromInput ( $xml, $isFile) | |
Private Attributes | |
array | $parserOptions |
Additional parsing options. | |
Definition at line 28 of file XmlTypeCheck.php.
XmlTypeCheck::__construct | ( | $input, | |
$filterCallback = null , |
|||
$isFile = true , |
|||
$options = [] |
|||
) |
Allow filtering an XML file.
Filters should return either true or a string to indicate something is wrong with the file. $this->filterMatch will store if the file failed validation (true = failed validation). $this->filterMatchType will contain the validation error. $this->wellFormed will contain whether the xml file is well-formed.
string | $input | a filename or string containing the XML element |
callable | null | $filterCallback | (optional) Function to call to do additional custom validity checks from the SAX element handler event. This gives you access to the element namespace, name, attributes, and text contents. Filter should return a truthy value describing the error. |
bool | $isFile | (optional) indicates if the first parameter is a filename (default, true) or if it is a string (false) |
array | $options | list of additional parsing options: processing_instruction_handler: Callback for xml_set_processing_instruction_handler external_dtd_handler: Callback for the url of external dtd subset dtd_handler: Callback given the full text of the <!DOCTYPE declaration. require_safe_dtd: Only allow non-recursive entities in internal dtd (default true) |
Definition at line 110 of file XmlTypeCheck.php.
References $filterCallback, and validateFromInput().
|
private |
Check if the internal subset of the DTD is safe.
We whitelist an extremely restricted subset of DTD features.
Safe is defined as:
string | $internalSubset | The internal subset of the DTD |
Definition at line 434 of file XmlTypeCheck.php.
References $res.
Referenced by dtdHandler().
|
private |
Handle coming across a <!DOCTYPE declaration.
XMLReader | $reader | Reader currently pointing at DOCTYPE node. |
Definition at line 373 of file XmlTypeCheck.php.
References checkDTDIsSafe(), and parseDTD().
Referenced by validate().
|
private |
Definition at line 324 of file XmlTypeCheck.php.
References $filterCallback, and elementData().
Referenced by validate().
|
private |
string | $data |
Definition at line 343 of file XmlTypeCheck.php.
References elementData().
Referenced by elementClose(), elementData(), elementOpen(), and validate().
|
private |
string | $name | |
array | $attribs |
Definition at line 318 of file XmlTypeCheck.php.
References elementData().
Referenced by validate().
|
private |
string | $name | element or attribute name, maybe with a full or short prefix |
string | $namespaceURI |
Definition at line 305 of file XmlTypeCheck.php.
Referenced by getAttributesArray(), and validate().
|
private |
Get all of the attributes for an XMLReader's current node.
XMLReader | $r |
Definition at line 286 of file XmlTypeCheck.php.
References expandNS().
Referenced by validate().
XmlTypeCheck::getRootElement | ( | ) |
Get the root element.
Simple accessor to $rootElement
Definition at line 151 of file XmlTypeCheck.php.
References $rootElement.
|
static |
Alternative constructor: from filename.
string | $fname | the filename of an XML document |
callable | null | $filterCallback | (optional) Function to call to do additional custom validity checks from the SAX element handler event. This gives you access to the element namespace, name, and attributes, but not to text contents. Filter should return 'true' to toggle on $this->filterMatch |
Definition at line 127 of file XmlTypeCheck.php.
References $filterCallback, and true.
|
static |
Alternative constructor: from string.
string | $string | a string containing an XML element |
callable | null | $filterCallback | (optional) Function to call to do additional custom validity checks from the SAX element handler event. This gives you access to the element namespace, name, and attributes, but not to text contents. Filter should return 'true' to toggle on $this->filterMatch |
Definition at line 142 of file XmlTypeCheck.php.
References $filterCallback.
|
private |
Parse DTD into parts.
If there is an error parsing the dtd, sets wellFormed to false.
string | $dtd |
Definition at line 456 of file XmlTypeCheck.php.
References $res.
Referenced by dtdHandler().
|
private |
string | $target | |
string | $data |
Definition at line 352 of file XmlTypeCheck.php.
Referenced by validate().
|
private |
Definition at line 190 of file XmlTypeCheck.php.
Referenced by validate().
|
private |
Definition at line 199 of file XmlTypeCheck.php.
References dtdHandler(), elementClose(), elementData(), elementOpen(), expandNS(), getAttributesArray(), processingInstructionHandler(), and readNext().
Referenced by validateFromInput().
|
private |
string | $xml | |
bool | $isFile |
Definition at line 159 of file XmlTypeCheck.php.
References $s, and validate().
Referenced by __construct().
|
protected |
A stack of strings containing the data of each xml element as it's processed.
Append data to the top string of the stack, then pop off the string and process it when the element is closed.
Definition at line 59 of file XmlTypeCheck.php.
|
protected |
A stack of element names and attributes, as we process them.
Definition at line 64 of file XmlTypeCheck.php.
|
protected |
Definition at line 72 of file XmlTypeCheck.php.
Referenced by __construct(), elementClose(), newFromFilename(), and newFromString().
bool XmlTypeCheck::$filterMatch = false |
Will be set to true if the optional element filter returned a match at some point.
Definition at line 39 of file XmlTypeCheck.php.
mixed XmlTypeCheck::$filterMatchType = false |
Will contain the type of filter hit if the optional element filter returned a match at some point.
Definition at line 46 of file XmlTypeCheck.php.
|
private |
Additional parsing options.
Definition at line 77 of file XmlTypeCheck.php.
string XmlTypeCheck::$rootElement = '' |
Name of the document's root element, including any namespace as an expanded URL.
Definition at line 52 of file XmlTypeCheck.php.
Referenced by getRootElement().
|
protected |
Current depth of the data stack.
Definition at line 69 of file XmlTypeCheck.php.
bool null XmlTypeCheck::$wellFormed = null |
Will be set to true or false to indicate whether the file is well-formed XML.
Note that this doesn't check schema validity.
Definition at line 33 of file XmlTypeCheck.php.