Hoa central
ReadWrite.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Xml;
38 
39 use Hoa\Core;
40 use Hoa\Stream;
41 
50 class ReadWrite
51  extends Xml
52  implements Stream\IStream\In,
54 {
60  protected $_autoSave = true;
61 
62 
63 
79  public function __construct(
80  Stream\IStream\In $stream,
81  $initializeNamespace = true,
82  $entityResolver = null,
83  $autoSave = true
84  ) {
85  if (true === $autoSave && !($stream instanceof Stream\IStream\Out)) {
86  throw new Exception(
87  'The stream %s (that has opened %s) must implement ' .
88  '\Hoa\Stream\IStream\In and \Hoa\Stream\IStream\Out interfaces.',
89  0,
90  [get_class($stream), $stream->getStreamName()]
91  );
92  }
93 
94  parent::__construct(
95  '\Hoa\Xml\Element\ReadWrite',
96  $stream,
97  $initializeNamespace,
98  $entityResolver
99  );
100 
101  if (true === $autoSave) {
102  event(
103  'hoa://Event/Stream/' . $stream->getStreamName() .
104  ':close-before'
105  )->attach(xcallable($this, '_close'));
106  }
107 
108  $this->_autoSave = $autoSave;
109 
110  return;
111  }
112 
122  public function _close(Core\Event\Bucket $bucket)
123  {
124  if (false === $this->isAutoSaveEnabled()) {
125  return;
126  }
127 
128  $handle = $this->getStream()->selectRoot()->asXML();
129 
130  if (true === $this->getInnerStream()->truncate(0)) {
131  $this->getInnerStream()->writeAll($handle);
132  }
133 
134  return;
135  }
136 
142  public function eof()
143  {
144  return $this->getStream()->eof();
145  }
146 
154  public function read($length)
155  {
156  return $this->getStream()->read($length);
157  }
158 
165  public function readString($length)
166  {
167  return $this->getStream()->readString($length);
168  }
169 
175  public function readCharacter()
176  {
177  return $this->getStream()->readCharacter();
178  }
179 
185  public function readBoolean()
186  {
187  return $this->getStream()->readBoolean();
188  }
189 
196  public function readInteger($length = 1)
197  {
198  return $this->getStream()->readInteger($length);
199  }
200 
207  public function readFloat($length = 1)
208  {
209  return $this->getStream()->readFloat($length);
210  }
211 
218  public function readArray($argument = null)
219  {
220  return $this->getStream()->readArray($argument);
221  }
222 
228  public function readLine()
229  {
230  return $this->getStream()->readLine();
231  }
232 
239  public function readAll($offset = 0)
240  {
241  return $this->getStream()->readAll($offset);
242  }
243 
250  public function scanf($format)
251  {
252  return $this->getStream()->scanf($format);
253  }
254 
260  public function readDOM()
261  {
262  return $this->getStream()->readDOM();
263  }
264 
273  public function write($string, $length)
274  {
275  return $this->getStream()->write($string, $length);
276  }
277 
284  public function writeString($string)
285  {
286  return $this->getStream()->writeString($string);
287  }
288 
295  public function writeCharacter($char)
296  {
297  return $this->getStream()->writeCharacter($char);
298  }
299 
306  public function writeBoolean($boolean)
307  {
308  return $this->getStream()->writeBoolean($boolean);
309  }
310 
317  public function writeInteger($integer)
318  {
319  return $this->getStream()->writeInteger($integer);
320  }
321 
328  public function writeFloat($float)
329  {
330  return $this->getStream()->writeFloat($float);
331  }
332 
339  public function writeArray(Array $array)
340  {
341  return $this->getStream()->writeArray($array);
342  }
343 
350  public function writeLine($line)
351  {
352  return $this->getStream()->writeLine($line);
353  }
354 
361  public function writeAll($string)
362  {
363  return $this->getStream()->writeAll($string);
364  }
365 
372  public function truncate($size)
373  {
374  return $this->getStream()->truncate($size);
375  }
376 
383  public function writeDOM(\DOMNode $dom)
384  {
385  return $this->getStream()->writeDOM($dom);
386  }
387 
394  public function writeAttributes(Array $attributes)
395  {
396  return $this->getStream()->writeAttributes($attributes);
397  }
398 
406  public function writeAttribute($name, $value)
407  {
408  return $this->getStream()->writeAttribute($name, $value);
409  }
410 
416  public function isAutoSaveEnabled()
417  {
418  return $this->_autoSave;
419  }
420 }
writeFloat($float)
Definition: ReadWrite.php:328
_close(Core\Event\Bucket $bucket)
Definition: ReadWrite.php:122
readAll($offset=0)
Definition: ReadWrite.php:239
writeCharacter($char)
Definition: ReadWrite.php:295
readFloat($length=1)
Definition: ReadWrite.php:207
readString($length)
Definition: ReadWrite.php:165
writeDOM(\DOMNode $dom)
Definition: ReadWrite.php:383
write($string, $length)
Definition: ReadWrite.php:273
writeAttributes(Array $attributes)
Definition: ReadWrite.php:394
writeAttribute($name, $value)
Definition: ReadWrite.php:406
writeArray(Array $array)
Definition: ReadWrite.php:339
writeString($string)
Definition: ReadWrite.php:284
readInteger($length=1)
Definition: ReadWrite.php:196
writeInteger($integer)
Definition: ReadWrite.php:317
writeBoolean($boolean)
Definition: ReadWrite.php:306
writeAll($string)
Definition: ReadWrite.php:361
readArray($argument=null)
Definition: ReadWrite.php:218
__construct(Stream\IStream\In $stream, $initializeNamespace=true, $entityResolver=null, $autoSave=true)
Definition: ReadWrite.php:79