Hoa central
Public Member Functions | Static Public Member Functions | Static Protected Attributes | List of all members
Hoa\Xml\Element\Basic Class Reference
Inheritance diagram for Hoa\Xml\Element\Basic:

Public Member Functions

 selectRoot ()
 
 selectAnyElements ()
 
 selectElements ($E=null)
 
 selectDescendantElements ($F=null)
 
 selectChildElements ($F=null)
 
 selectAdjacentSiblingElement ($F)
 
 selectSiblingElements ($F=null)
 
 querySelector ($query)
 
 querySelectorAll ($query)
 
 readAttributes ()
 
 readAttribute ($name)
 
 attributeExists ($name)
 
 readAttributesAsList ()
 
 readAttributeAsList ($name)
 
 readCustomAttributes ($set)
 
 readCustomAttributesAsList ($set)
 
 readAttributesAsString ()
 
 readXML ()
 
 readDOM ()
 
 readAsPhrasingModel ($namespace= '', $element= '__text')
 
 useNamespace ($namespace)
 

Static Public Member Functions

static getCssToXPathInstance ()
 

Static Protected Attributes

static $_cssToXPath = null
 
static $_buffer = null
 

Detailed Description

Class .

This class represents a XML element in a XML tree.

Definition at line 50 of file Basic.php.

Member Function Documentation

Hoa\Xml\Element\Basic::attributeExists (   $name)

Whether an attribute exists.

Parameters
string$nameAttribute's name.
Returns
bool

Definition at line 257 of file Basic.php.

258  {
259  return true === array_key_exists($name, $this->readAttributes());
260  }

Here is the call graph for this function:

static Hoa\Xml\Element\Basic::getCssToXPathInstance ( )
static

Get CSS to XPath compiler instance.

Returns

Definition at line 430 of file Basic.php.

431  {
432  if (null === self::$_cssToXPath) {
433  self::$_cssToXPath = new \Hoa\Xml\CssToXPath();
434  self::$_cssToXPath->setDefaultNamespacePrefix('__current_ns');
435  }
436 
437  return self::$_cssToXPath;
438  }

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::querySelector (   $query)

Execute a query selector and return the first result.

Parameters
string$queryQuery.
Returns
Exceptions

Implements Hoa\Stream\IStream\Structural.

Definition at line 187 of file Basic.php.

188  {
189  $handle = $this->querySelectorAll($query);
190 
191  if (empty($handle)) {
192  return false;
193  }
194 
195  return $handle[0];
196  }
querySelectorAll($query)
Definition: Basic.php:205

Here is the call graph for this function:

Hoa\Xml\Element\Basic::querySelectorAll (   $query)

Execute a query selector and return one or many results.

Parameters
string$queryQuery.
Returns
Exceptions
array

Implements Hoa\Stream\IStream\Structural.

Definition at line 205 of file Basic.php.

206  {
207  self::$_buffer = null;
208  $_cssToXPath = self::getCssToXPathInstance();
209  $_cssToXPath->compile($query);
210 
211  return $this->xpath($_cssToXPath->getXPath());
212  }
static $_cssToXPath
Definition: Basic.php:60

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::readAsPhrasingModel (   $namespace = '',
  $element = '__text' 
)

Read children as a phrasing model, i.e. transform: <foo>abc<bar>def</bar>ghi</foo> into <foo><???>abc</???><bar>def</bar><???>ghi</???></foo> where <???> is the value of the $element argument, i.e. the inter-text element name. Please, see the interface.

Parameters
string$namespaceNamespace to use ('' if none).
string$elementInter-text element name.
Returns
array

Definition at line 378 of file Basic.php.

379  {
380  $out = [];
381  $list = $this->readDOM()->childNodes;
382  $class = get_class($this);
383 
384  for ($i = 0, $max = $list->length; $i < $max; ++$i) {
385  $node = $list->item($i);
386 
387  switch ($node->nodeType) {
388  case XML_ELEMENT_NODE:
389  $out[] = simplexml_import_dom($node, $class);
390 
391  break;
392 
393  case XML_TEXT_NODE:
394  $out[] = new $class(
395  '<' . $element . '>' . $node->nodeValue .
396  '</' . $element . '>',
397  LIBXML_NOXMLDECL,
398  false,
399  $namespace,
400  false
401  );
402 
403  break;
404  }
405  }
406 
407  return $out;
408  }

Here is the call graph for this function:

Hoa\Xml\Element\Basic::readAttribute (   $name)

Read a specific attribute.

Parameters
string$nameAttribute's name.
Returns
string

Definition at line 240 of file Basic.php.

241  {
242  $attributes = $this->readAttributes();
243 
244  if (false === array_key_exists($name, $attributes)) {
245  return null;
246  }
247 
248  return $attributes[$name];
249  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::readAttributeAsList (   $name)

Read a attribute value as a list.

Parameters
string$nameAttribute's name.
Returns
array

Definition at line 284 of file Basic.php.

285  {
286  return explode(' ', $this->readAttribute($name));
287  }
readAttribute($name)
Definition: Basic.php:240

Here is the call graph for this function:

Hoa\Xml\Element\Basic::readAttributes ( )

Read all attributes.

Returns
array

Definition at line 219 of file Basic.php.

220  {
221  $handle = (array) $this->attributes();
222 
223  if (!isset($handle['@attributes'])) {
224  $handle = (array) $this;
225 
226  if (!isset($handle['@attributes'])) {
227  return [];
228  }
229  }
230 
231  return $handle['@attributes'];
232  }

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::readAttributesAsList ( )

Read attributes value as a list.

Returns
array

Definition at line 267 of file Basic.php.

268  {
269  $attributes = $this->readAttributes();
270 
271  foreach ($attributes as $name => &$value) {
272  $value = explode(' ', $value);
273  }
274 
275  return $attributes;
276  }

Here is the call graph for this function:

Hoa\Xml\Element\Basic::readAttributesAsString ( )

Read attributes as a string.

Returns
string

Definition at line 335 of file Basic.php.

336  {
337  $out = null;
338 
339  foreach ($this->readAttributes() as $name => $value) {
340  $out .= ' ' . $name . '="' . str_replace('"', '\"', $value) . '"';
341  }
342 
343  return $out;
344  }

Here is the call graph for this function:

Hoa\Xml\Element\Basic::readCustomAttributes (   $set)

Read custom attributes (as a set). For example: <component data-abc="def" data-uvw="xyz"> “data” is a custom attribute, so the $set.

Parameters
string$setSet name.
Returns
array

Definition at line 298 of file Basic.php.

299  {
300  $out = [];
301  $set .= '-';
302  $strlen = strlen($set);
303 
304  foreach ($this->readAttributes() as $name => $value) {
305  if ($set === substr($name, 0, $strlen)) {
306  $out[substr($name, $strlen)] = $value;
307  }
308  }
309 
310  return $out;
311  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::readCustomAttributesAsList (   $set)

Read custom attributes values as a list.

Parameters
string$setSet name.
Returns
array

Definition at line 319 of file Basic.php.

320  {
321  $out = [];
322 
323  foreach ($this->readCustomAttributes($set) as $name => $value) {
324  $out[$name] = explode(' ', $value);
325  }
326 
327  return $out;
328  }
readCustomAttributes($set)
Definition: Basic.php:298

Here is the call graph for this function:

Hoa\Xml\Element\Basic::readDOM ( )

Read content as a DOM tree.

Returns

Definition at line 361 of file Basic.php.

362  {
363  return dom_import_simplexml($this);
364  }

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::readXML ( )

Read all with XML node.

Returns
string

Definition at line 351 of file Basic.php.

352  {
353  return $this->asXML();
354  }
Hoa\Xml\Element\Basic::selectAdjacentSiblingElement (   $F)

Select an F element immediately preceded by an E element: E + F.

Parameters
string$FElement F.
Returns

Implements Hoa\Stream\IStream\Structural.

Definition at line 149 of file Basic.php.

150  {
151  self::$_buffer = null;
152  $handle = $this->xpath(
153  'following-sibling::__current_ns:*[1]/self::__current_ns:' . $F
154  );
155 
156  if (empty($handle)) {
157  return false;
158  }
159 
160  return $handle[0];
161  }
Hoa\Xml\Element\Basic::selectAnyElements ( )

Select any elements: *.

Returns
array

Implements Hoa\Stream\IStream\Structural.

Definition at line 91 of file Basic.php.

92  {
93  self::$_buffer = null;
94 
95  return $this->xpath('//__current_ns:*');
96  }

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::selectChildElements (   $F = null)

Select F elements children of an E element: E > F.

Parameters
string$FElement F.
Returns
array

Implements Hoa\Stream\IStream\Structural.

Definition at line 132 of file Basic.php.

133  {
134  self::$_buffer = null;
135 
136  if (null === $F || '*' == $F) {
137  return $this->xpath('child::__current_ns:*');
138  }
139 
140  return $this->xpath('child::__current_ns:' . $F);
141  }
Hoa\Xml\Element\Basic::selectDescendantElements (   $F = null)

Select F elements descendant of an E element: E F.

Parameters
string$FElement F.
Returns
array

Implements Hoa\Stream\IStream\Structural.

Definition at line 121 of file Basic.php.

122  {
123  return $this->selectElements($F);
124  }
selectElements($E=null)
Definition: Basic.php:104

Here is the call graph for this function:

Hoa\Xml\Element\Basic::selectElements (   $E = null)

Select elements of type E: E.

Parameters
string$EElement E.
Returns
array

Implements Hoa\Stream\IStream\Structural.

Definition at line 104 of file Basic.php.

105  {
106  if (null === $E) {
107  return $this->selectAnyElements();
108  }
109 
110  self::$_buffer = null;
111 
112  return $this->xpath('//__current_ns:' . $E);
113  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Xml\Element\Basic::selectRoot ( )

Select root of the document: :root.

Returns

Implements Hoa\Stream\IStream\Structural.

Definition at line 76 of file Basic.php.

77  {
78  self::$_buffer = null;
79 
80  return simplexml_import_dom(
81  $this->readDOM()->ownerDocument->documentElement,
82  get_class($this)
83  );
84  }

Here is the call graph for this function:

Hoa\Xml\Element\Basic::selectSiblingElements (   $F = null)

Select F elements preceded by an E element: E ~ F.

Parameters
string$FElement F.
Returns
array

Implements Hoa\Stream\IStream\Structural.

Definition at line 169 of file Basic.php.

170  {
171  if (null === $F) {
172  $F = '*';
173  }
174 
175  self::$_buffer = null;
176 
177  return $this->xpath('following-sibling::__current_ns:' . $F);
178  }
Hoa\Xml\Element\Basic::useNamespace (   $namespace)

Use a specific namespace. For performance reason, we did not test if the namespace exists in the document. Please, see the ::namespaceExists() method to do that.

Parameters
string$namespaceNamespace.
Returns

Definition at line 418 of file Basic.php.

419  {
420  $this->registerXPathNamespace('__current_ns', $namespace);
421 
422  return $this;
423  }

Member Data Documentation

Hoa\Xml\Element\Basic::$_buffer = null
staticprotected

Definition at line 67 of file Basic.php.

Hoa\Xml\Element\Basic::$_cssToXPath = null
staticprotected

Definition at line 60 of file Basic.php.


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