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 44 of file grima-xmlbag.php.

Constructor & Destructor Documentation

◆ __construct()

XMLAsArrayOfWhateversSpecifiedByXPath::__construct (   $xml,
  $context_node 
)

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

References $context_node, and $xml.

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

Member Function Documentation

◆ __get()

XMLAsArrayOfWhateversSpecifiedByXPath::__get ( string  $name)

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

References query().

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

◆ __isset()

XMLAsArrayOfWhateversSpecifiedByXPath::__isset ( string  $name)

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

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

◆ __set()

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

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

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

◆ __toString()

XMLAsArrayOfWhateversSpecifiedByXPath::__toString ( )

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

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

◆ __unset()

XMLAsArrayOfWhateversSpecifiedByXPath::__unset ( string  $name)

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

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

◆ query()

XMLAsArrayOfWhateversSpecifiedByXPath::query ( string  $offset)
protected

Member Data Documentation

◆ $context_node

XMLAsArrayOfWhateversSpecifiedByXPath::$context_node

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

Referenced by __construct().

◆ $xml

XMLAsArrayOfWhateversSpecifiedByXPath::$xml

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

Referenced by __construct().

◆ $xpath

XMLAsArrayOfWhateversSpecifiedByXPath::$xpath = null
private

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


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