Hoa central
Public Member Functions | List of all members
Hoa\Xml\Element\ReadWrite Class Reference
Inheritance diagram for Hoa\Xml\Element\ReadWrite:

Public Member Functions

 eof ()
 
 read ($length)
 
 readString ($length)
 
 readCharacter ()
 
 readBoolean ()
 
 readInteger ($length=1)
 
 readFloat ($length=1)
 
 readArray ($argument=null)
 
 readLine ()
 
 readAll ($offset=0)
 
 scanf ($format)
 
 readDOM ()
 
 write ($string, $length)
 
 writeString ($string)
 
 writeCharacter ($char)
 
 writeBoolean ($boolean)
 
 writeInteger ($integer)
 
 writeFloat ($float)
 
 writeArray (Array $array)
 
 writeLine ($line)
 
 writeAll ($string)
 
 truncate ($size)
 
 writeDOM (\DOMNode $dom)
 
 writeAttributes (Array $attributes)
 
 writeAttribute ($name, $value)
 
 writeCustomAttributes ($set, Array $pairs)
 
 removeAttribute ($name)
 
- Public Member Functions inherited from Hoa\Xml\Element\Basic
 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)
 

Additional Inherited Members

- Static Public Member Functions inherited from Hoa\Xml\Element\Basic
static getCssToXPathInstance ()
 
- Static Protected Attributes inherited from Hoa\Xml\Element\Basic
static $_cssToXPath = null
 
static $_buffer = null
 

Detailed Description

Class .

Read/write a XML element.

Definition at line 51 of file ReadWrite.php.

Member Function Documentation

Hoa\Xml\Element\ReadWrite::eof ( )

Test for end-of-file.

Returns
bool

Implements Hoa\Stream\IStream\In.

Definition at line 61 of file ReadWrite.php.

62  {
63  if (null === parent::$_buffer) {
64  return true;
65  }
66 
67  return parent::$_buffer->eof();
68  }
Hoa\Xml\Element\ReadWrite::read (   $length)

Read n characters.

Parameters
int$lengthLength.
Returns
string
Exceptions

Implements Hoa\Stream\IStream\In.

Definition at line 77 of file ReadWrite.php.

78  {
79  if (0 > $length) {
80  throw new Xml\Exception(
81  'Length must be greater than 0, given %d.',
82  0,
83  $length
84  );
85  }
86 
87  if (null === parent::$_buffer) {
88  parent::$_buffer = new Stringbuffer\ReadWrite();
89  parent::$_buffer->initializeWith($this->__toString());
90  }
91 
92  return parent::$_buffer->read($length);
93  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::readAll (   $offset = 0)

Read all, i.e. read as much as possible.

Parameters
int$offsetOffset (not used).
Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 182 of file ReadWrite.php.

183  {
184  return $this->__toString();
185  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::readArray (   $argument = null)

Read the XML tree as an array.

Parameters
string$argumentNot use here.
Returns
array

Implements Hoa\Stream\IStream\In.

Definition at line 154 of file ReadWrite.php.

155  {
156  return (array) $this;
157  }
Hoa\Xml\Element\ReadWrite::readBoolean ( )

Read a boolean.

Returns
bool

Implements Hoa\Stream\IStream\In.

Definition at line 121 of file ReadWrite.php.

122  {
123  return (bool) $this->read(1);
124  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::readCharacter ( )

Read a character.

Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 111 of file ReadWrite.php.

112  {
113  return $this->read(1);
114  }

Here is the call graph for this function:

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

Read content as a DOM tree.

Returns
DOMElement

Definition at line 203 of file ReadWrite.php.

204  {
205  return dom_import_simplexml($this);
206  }

Here is the caller graph for this function:

Hoa\Xml\Element\ReadWrite::readFloat (   $length = 1)

Read a float.

Parameters
int$lengthLength.
Returns
float

Implements Hoa\Stream\IStream\In.

Definition at line 143 of file ReadWrite.php.

144  {
145  return (float) $this->read($length);
146  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::readInteger (   $length = 1)

Read an integer.

Parameters
int$lengthLength.
Returns
int

Implements Hoa\Stream\IStream\In.

Definition at line 132 of file ReadWrite.php.

133  {
134  return (int) $this->read($length);
135  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::readLine ( )

Read a line.

Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 164 of file ReadWrite.php.

165  {
166  $handle = $this->readAll();
167  $n = strpos($handle, "\n");
168 
169  if (false === $n) {
170  return $handle;
171  }
172 
173  return substr($handle, 0, $n);
174  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::readString (   $length)

Alias of $this->read().

Parameters
int$lengthLength.
Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 101 of file ReadWrite.php.

102  {
103  return $this->read($length);
104  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::removeAttribute (   $name)

Remove an attribute.

Parameters
string$nameName.
Returns
void

Definition at line 483 of file ReadWrite.php.

484  {
485  unset($this[$name]);
486 
487  return;
488  }
Hoa\Xml\Element\ReadWrite::scanf (   $format)

Parse input from a stream according to a format.

Parameters
string$formatFormat (see printf's formats).
Returns
array

Implements Hoa\Stream\IStream\In.

Definition at line 193 of file ReadWrite.php.

194  {
195  return sscanf($this->readAll(), $format);
196  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::truncate (   $size)

Truncate to a given length.

Parameters
int$sizeSize.
Returns
bool

Implements Hoa\Stream\IStream\Out.

Definition at line 400 of file ReadWrite.php.

401  {
402  if (null === parent::$_buffer) {
403  parent::$_buffer = new Stringbuffer\ReadWrite();
404  parent::$_buffer->initializeWith($this->__toString());
405  }
406 
407  return parent::$_buffer->truncate($size);
408  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::write (   $string,
  $length 
)

Write n characters.

Parameters
string$stringString.
int$lengthLength.
Returns
mixed
Exceptions

Implements Hoa\Stream\IStream\Out.

Definition at line 216 of file ReadWrite.php.

217  {
218  if (0 > $length) {
219  throw new Xml\Exception(
220  'Length must be greater than 0, given %d.',
221  1,
222  $length
223  );
224  }
225 
226  if (null === parent::$_buffer) {
227  parent::$_buffer = new Stringbuffer\ReadWrite();
228  parent::$_buffer->initializeWith($this->__toString());
229  }
230 
231  $l = parent::$_buffer->write($string, $length);
232 
233  if ($l !== $length) {
234  return false;
235  }
236 
237  $this[0] = parent::$_buffer->readAll();
238 
239  return $l;
240  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeAll (   $string)

Write all, i.e. as much as possible.

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 389 of file ReadWrite.php.

390  {
391  return $this->write($string, strlen($string));
392  }
write($string, $length)
Definition: ReadWrite.php:189

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeArray ( Array  $array)

Write an array.

Parameters
array$arrayArray.
Returns
mixed readArray does not return attributes and so…

Implements Hoa\Stream\IStream\Out.

Definition at line 310 of file ReadWrite.php.

311  {
312  $document = $this->readDOM()->ownerDocument;
313 
314  foreach ($array as $name => $value) {
315  if (is_object($value)) {
316  if (!isset($this->{$name})) {
317  $this->addChild($name);
318  }
319 
320  $this->{$name}->readDOM()->parentNode->appendChild(
321  $document->importNode(clone $value->readDOM(), true)
322  );
323  } elseif (is_array($value) && !empty($value)) {
324  if (!isset($value[0])) {
325  $handle = $this->addChild($name);
326  }
327 
328  foreach ($value as $subname => $subvalue) {
329  if (is_object($subvalue)) {
330  if (!isset($this->{$name})) {
331  $this->addChild($name);
332  }
333 
334  $this->{$name}->readDOM()->parentNode->appendChild(
335  $document->importNode(clone $subvalue->readDOM(), true)
336  );
337  } else {
338  if (!isset($this->{$name})) {
339  $this->addChild($name);
340  }
341 
342  if (is_array($subvalue)) {
343  $handle->addChild($subname, null)
344  ->writeArray($subvalue);
345 
346  continue;
347  }
348 
349  if (is_bool($subvalue)) {
350  $subvalue = $subvalue ? 'true' : 'false';
351  }
352 
353  if (is_string($subname)) {
354  $handle->addChild($subname, $subvalue);
355  } else {
356  $this->addChild($name, $subvalue);
357  }
358  }
359  }
360  }
361  }
362 
363  return;
364  }

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeAttribute (   $name,
  $value 
)

Write an attribute. If the attribute does not exist, it will be created.

Parameters
string$nameName.
string$valueValue.
Returns
void

Definition at line 450 of file ReadWrite.php.

451  {
452  $this[$name] = $value;
453 
454  return;
455  }

Here is the caller graph for this function:

Hoa\Xml\Element\ReadWrite::writeAttributes ( Array  $attributes)

Write attributes. If an attribute does not exist, it will be created.

Parameters
array$attributesAttributes.
Returns
void

Definition at line 433 of file ReadWrite.php.

434  {
435  foreach ($attributes as $name => $value) {
436  $this->writeAttribute($name, $value);
437  }
438 
439  return;
440  }
writeAttribute($name, $value)
Definition: ReadWrite.php:450

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeBoolean (   $boolean)

Write a boolean.

Parameters
bool$booleanBoolean.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 272 of file ReadWrite.php.

273  {
274  return $this->write((string) (bool) $boolean, 1);
275  }
write($string, $length)
Definition: ReadWrite.php:189

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeCharacter (   $char)

Write a character.

Parameters
string$charCharacter.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 261 of file ReadWrite.php.

262  {
263  return $this->write((string) $char[0], 1);
264  }
write($string, $length)
Definition: ReadWrite.php:189

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeCustomAttributes (   $set,
Array  $pairs 
)

Write 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.
array$pairsPairs of attribute/value (e.g. abc => def, uvw => xyz).
Returns
void

Definition at line 468 of file ReadWrite.php.

469  {
470  foreach ($pairs as $attribute => $value) {
471  $this->writeAttribute($set . '-' . $attribute, $value);
472  }
473 
474  return;
475  }
writeAttribute($name, $value)
Definition: ReadWrite.php:450

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeDOM ( \DOMNode  $dom)

Write a DOM tree.

Parameters
\DOMNode$domDOM tree.
Returns
mixed
Todo:

Definition at line 417 of file ReadWrite.php.

418  {
419  $sx = simplexml_import_dom($dom, get_class($this));
420 
421  throw new Xml\Exception('Hmm, TODO?', 42);
422 
423  return true;
424  }
Hoa\Xml\Element\ReadWrite::writeFloat (   $float)

Write a float.

Parameters
float$floatFloat.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 296 of file ReadWrite.php.

297  {
298  $float = (string) (float) $float;
299 
300  return $this->write($float, strlen($float));
301  }
write($string, $length)
Definition: ReadWrite.php:189

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeInteger (   $integer)

Write an integer.

Parameters
int$integerInteger.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 283 of file ReadWrite.php.

284  {
285  $integer = (string) (int) $integer;
286 
287  return $this->write($integer, strlen($integer));
288  }
write($string, $length)
Definition: ReadWrite.php:189

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeLine (   $line)

Write a line.

Parameters
string$lineLine.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 372 of file ReadWrite.php.

373  {
374  if (false === $n = strpos($line, "\n")) {
375  return $this->write($line . "\n", strlen($line) + 1);
376  }
377 
378  ++$n;
379 
380  return $this->write(substr($line, 0, $n), $n);
381  }
write($string, $length)
Definition: ReadWrite.php:189

Here is the call graph for this function:

Hoa\Xml\Element\ReadWrite::writeString (   $string)

Write a string.

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 248 of file ReadWrite.php.

249  {
250  $string = (string) $string;
251 
252  return $this->write($string, strlen($string));
253  }
write($string, $length)
Definition: ReadWrite.php:189

Here is the call graph for this function:


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