Grima 2018-08
Whispering into Alma's ear
Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | List of all members
XMLAsArrayOfWhateversSpecifiedByXPath Class Reference
Inheritance diagram for XMLAsArrayOfWhateversSpecifiedByXPath:
XMLAsArrayOfDOMNodeListsSpecifiedByXPath XMLAsArrayOfDOMNodesSpecifiedByXPath XMLAsArrayOfStringsSpecifiedByXPath

Public Member Functions

  __construct ( $xml, $context_node)
 
  __toString ()
 
  __get (string $name)
 
  __set (string $name, $value)
 
  __isset (string $name)
 
  __unset (string $name)
 

Public Attributes

  $xml
 
  $context_node
 

Protected Member Functions

  query (string $offset)
 

Private Attributes

  $xpath = null
 

Detailed Description

Definition at line 43 of file grima-xmlbag.php.

Constructor & Destructor Documentation

◆ __construct()

XMLAsArrayOfWhateversSpecifiedByXPath::__construct (   $xml,
  $context_node 
)

Definition at line 47 of file grima-xmlbag.php.

47 {
48 if( is_string($xml) ) {
49 $this->xml = new DOMDocument();
50 $this->xml->loadXML($xml);
51 } elseif( $xml instanceof DOMDocument ) {
52 $this->xml = $xml;
53 } else {
54 throw new Exception("<xml> must be of type DOMDocument in new XMLAsArrayOf...(xml,context)");
55 }
56 $this->xpath = new DOMXPath($this->xml);
57 if( is_string($context_node) ) {
58 $nodeList = $this->xpath->query($context_node);
59 //print( "Context ($context_node) is: " . xml_debug($nodeList) . "\n" );
60 if( $nodeList->length === 1 ) {
61 $this->context_node = $nodeList->item(0);
62 } else {
63 $this->context_node = $this->xml->documentElement;
64 }
65 } elseif( $context_node instanceof DOMElement ) {
66 $this->context_node = $context_node;
67 } else {
68 $this->context_node = $this->xml->documentElement;
69 }
70 }

References $context_node, and $xml.

Member Function Documentation

◆ __get()

XMLAsArrayOfWhateversSpecifiedByXPath::__get ( string  $name )

Definition at line 81 of file grima-xmlbag.php.

81 {
82 $class = get_class($this);
83 return new $class($this->xml, $this->query($name));
84 }

References query().

◆ __isset()

XMLAsArrayOfWhateversSpecifiedByXPath::__isset ( string  $name )

Definition at line 88 of file grima-xmlbag.php.

88 {
89 return isset($this[$name]);
90 }

◆ __set()

XMLAsArrayOfWhateversSpecifiedByXPath::__set ( string  $name,
  $value 
)

Definition at line 85 of file grima-xmlbag.php.

85 {
86 $this[$name] = $value;
87 }

◆ __toString()

XMLAsArrayOfWhateversSpecifiedByXPath::__toString ( )

Definition at line 78 of file grima-xmlbag.php.

78 {
79 return $this->xml->saveXML($this->context_node);
80 }

◆ __unset()

XMLAsArrayOfWhateversSpecifiedByXPath::__unset ( string  $name )

Definition at line 91 of file grima-xmlbag.php.

91 {
92 unset($this[$name]);
93 }

◆ query()

XMLAsArrayOfWhateversSpecifiedByXPath::query ( string  $offset )
protected

Member Data Documentation

◆ $context_node

XMLAsArrayOfWhateversSpecifiedByXPath::$context_node

Definition at line 45 of file grima-xmlbag.php.

Referenced by __construct().

◆ $xml

XMLAsArrayOfWhateversSpecifiedByXPath::$xml

Definition at line 44 of file grima-xmlbag.php.

Referenced by __construct().

◆ $xpath

XMLAsArrayOfWhateversSpecifiedByXPath::$xpath = null
private

Definition at line 46 of file grima-xmlbag.php.


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