Hoa central
Write.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 Write extends Xml implements Stream\IStream\Out
51 {
63  public function __construct(
64  Stream\IStream\Out $stream,
65  $initializeNamespace = true,
66  $entityResolver = null
67  ) {
68  parent::__construct(
69  '\Hoa\Xml\Element\Write',
70  $stream,
71  $initializeNamespace,
72  $entityResolver
73  );
74 
75  event('hoa://Event/Stream/' . $stream->getStreamName() . ':close-before')
76  ->attach(xcallable($this, '_close'));
77 
78  return;
79  }
80 
90  public function _close(Core\Event\Bucket $bucket)
91  {
92  $handle = $this->getStream()->selectRoot()->asXML();
93 
94  if (true === $this->getInnerStream()->truncate(0)) {
95  $this->getInnerStream()->writeAll($handle);
96  }
97 
98  return;
99  }
100 
109  public function write($string, $length)
110  {
111  return $this->getStream()->write($string, $length);
112  }
113 
120  public function writeString($string)
121  {
122  return $this->getStream()->writeString($string);
123  }
124 
131  public function writeCharacter($char)
132  {
133  return $this->getStream()->writeCharacter($char);
134  }
135 
142  public function writeBoolean($boolean)
143  {
144  return $this->getStream()->writeBoolean($boolean);
145  }
146 
153  public function writeInteger($integer)
154  {
155  return $this->getStream()->writeInteger($integer);
156  }
157 
164  public function writeFloat($float)
165  {
166  return $this->getStream()->writeFloat($float);
167  }
168 
175  public function writeArray(Array $array)
176  {
177  return $this->getStream()->writeArray($array);
178  }
179 
186  public function writeLine($line)
187  {
188  return $this->getStream()->writeLine($line);
189  }
190 
197  public function writeAll($string)
198  {
199  return $this->getStream()->writeAll($string);
200  }
201 
208  public function truncate($size)
209  {
210  return $this->getStream()->truncate($size);
211  }
212 
219  public function writeDOM(\DOMNode $dom)
220  {
221  return $this->getStream()->writeDOM($dom);
222  }
223 
230  public function writeAttributes(Array $attributes)
231  {
232  return $this->getStream()->writeAttributes($attributes);
233  }
234 
242  public function writeAttribute($name, $value)
243  {
244  return $this->getStream()->writeAttribute($name, $value);
245  }
246 }
writeArray(Array $array)
Definition: Write.php:175
writeLine($line)
Definition: Write.php:186
writeAttribute($name, $value)
Definition: Write.php:242
writeAttributes(Array $attributes)
Definition: Write.php:230
write($string, $length)
Definition: Write.php:109
writeFloat($float)
Definition: Write.php:164
writeDOM(\DOMNode $dom)
Definition: Write.php:219
writeAll($string)
Definition: Write.php:197
_close(Core\Event\Bucket $bucket)
Definition: Write.php:90
writeBoolean($boolean)
Definition: Write.php:142
writeCharacter($char)
Definition: Write.php:131
truncate($size)
Definition: Write.php:208
writeInteger($integer)
Definition: Write.php:153
__construct(Stream\IStream\Out $stream, $initializeNamespace=true, $entityResolver=null)
Definition: Write.php:63
writeString($string)
Definition: Write.php:120