MediaWiki  1.28.0
XmlTypeCheck Class Reference

Public Member Functions

 __construct ($input, $filterCallback=null, $isFile=true, $options=[])
 
 getRootElement ()
 Get the root element. More...
 
 XmlErrorHandler ($errno, $errstr)
 

Static Public Member Functions

static newFromFilename ($fname, $filterCallback=null)
 Alternative constructor: from filename. More...
 
static newFromString ($string, $filterCallback=null)
 Alternative constructor: from string. More...
 

Public Attributes

 $filterMatch = false
 Will be set to true if the optional element filter returned a match at some point. More...
 
mixed $filterMatchType = false
 Will contain the type of filter hit if the optional element filter returned a match at some point. More...
 
 $rootElement = ''
 Name of the document's root element, including any namespace as an expanded URL. More...
 
 $wellFormed = null
 Will be set to true or false to indicate whether the file is well-formed XML. More...
 

Protected Attributes

 $elementData = []
 A stack of strings containing the data of each xml element as it's processed. More...
 
 $elementDataContext = []
 A stack of element names and attributes, as we process them. More...
 
 $stackDepth = 0
 Current depth of the data stack. More...
 

Private Member Functions

 elementClose ()
 
 elementData ($data)
 
 elementOpen ($name, $attribs)
 
 expandNS ($name, $namespaceURI)
 
 getAttributesArray (XMLReader $r)
 Get all of the attributes for an XMLReader's current node. More...
 
 processingInstructionHandler ($target, $data)
 
 readNext (XMLReader $reader)
 
 validate ($reader)
 
 validateFromInput ($xml, $isFile)
 

Private Attributes

 $parserOptions
 Additional parsing options. More...
 

Detailed Description

Definition at line 28 of file XmlTypeCheck.php.

Constructor & Destructor Documentation

XmlTypeCheck::__construct (   $input,
  $filterCallback = null,
  $isFile = true,
  $options = [] 
)
Parameters
string$inputa filename or string containing the XML element
callable$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 'true' to toggle on $this->filterMatch
bool$isFile(optional) indicates if the first parameter is a filename (default, true) or if it is a string (false)
array$optionslist of additional parsing options: processing_instruction_handler: Callback for xml_set_processing_instruction_handler

Definition at line 90 of file XmlTypeCheck.php.

References $options, and validateFromInput().

Member Function Documentation

XmlTypeCheck::elementClose ( )
private

Definition at line 299 of file XmlTypeCheck.php.

References $attribs, $name, elementData(), and list.

Referenced by validate().

XmlTypeCheck::elementData (   $data)
private
Parameters
$data

Definition at line 323 of file XmlTypeCheck.php.

Referenced by elementClose(), elementOpen(), and validate().

XmlTypeCheck::elementOpen (   $name,
  $attribs 
)
private
Parameters
$name
$attribs

Definition at line 291 of file XmlTypeCheck.php.

References $attribs, $name, and elementData().

Referenced by validate().

XmlTypeCheck::expandNS (   $name,
  $namespaceURI 
)
private
Parameters
$nameelement or attribute name, maybe with a full or short prefix
$namespaceURIthe namespaceURI
Returns
string the name prefixed with namespaceURI

Definition at line 278 of file XmlTypeCheck.php.

References $name.

Referenced by getAttributesArray(), and validate().

XmlTypeCheck::getAttributesArray ( XMLReader  $r)
private

Get all of the attributes for an XMLReader's current node.

Parameters
$rXMLReader
Returns
array of attributes

Definition at line 259 of file XmlTypeCheck.php.

References $name, and expandNS().

Referenced by validate().

XmlTypeCheck::getRootElement ( )

Get the root element.

Simple accessor to $rootElement

Returns
string

Definition at line 131 of file XmlTypeCheck.php.

References $rootElement.

static XmlTypeCheck::newFromFilename (   $fname,
  $filterCallback = null 
)
static

Alternative constructor: from filename.

Parameters
string$fnamethe filename of an XML document
callable$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
Returns
XmlTypeCheck

Definition at line 107 of file XmlTypeCheck.php.

References $fname, and true.

static XmlTypeCheck::newFromString (   $string,
  $filterCallback = null 
)
static

Alternative constructor: from string.

Parameters
string$stringa string containing an XML element
callable$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
Returns
XmlTypeCheck

Definition at line 122 of file XmlTypeCheck.php.

References false.

Referenced by XmlTypeCheckTest\testMalFormedXML(), XmlTypeCheckTest\testRecursiveEntity(), and XmlTypeCheckTest\testWellFormedXML().

XmlTypeCheck::processingInstructionHandler (   $target,
  $data 
)
private
Parameters
$target
$data

Definition at line 332 of file XmlTypeCheck.php.

Referenced by validate().

XmlTypeCheck::readNext ( XMLReader  $reader)
private

Definition at line 166 of file XmlTypeCheck.php.

References $ret.

Referenced by validate().

XmlTypeCheck::validate (   $reader)
private
XmlTypeCheck::validateFromInput (   $xml,
  $isFile 
)
private
Parameters
string$fnamethe filename

Definition at line 138 of file XmlTypeCheck.php.

References $e, $s, and validate().

Referenced by __construct().

XmlTypeCheck::XmlErrorHandler (   $errno,
  $errstr 
)

Definition at line 173 of file XmlTypeCheck.php.

Member Data Documentation

XmlTypeCheck::$elementData = []
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.

XmlTypeCheck::$elementDataContext = []
protected

A stack of element names and attributes, as we process them.

Definition at line 64 of file XmlTypeCheck.php.

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.

XmlTypeCheck::$parserOptions
private
Initial value:
= [
'processing_instruction_handler' => ''

Additional parsing options.

Definition at line 74 of file XmlTypeCheck.php.

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().

XmlTypeCheck::$stackDepth = 0
protected

Current depth of the data stack.

Definition at line 69 of file XmlTypeCheck.php.

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.


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