Hoa central
Read.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Xml\Element;
38 
39 use Hoa\Stream;
41 use Hoa\Xml;
42 
51 class Read extends Basic implements Stream\IStream\In
52 {
58  public function eof()
59  {
60  if (null === parent::$_buffer) {
61  return true;
62  }
63 
64  return parent::$_buffer->eof();
65  }
66 
74  public function read($length)
75  {
76  if (0 > $length) {
77  throw new Xml\Exception(
78  'Length must be greater than 0, given %d.',
79  0,
80  $length
81  );
82  }
83 
84  if (null === parent::$_buffer) {
85  parent::$_buffer = new Stringbuffer\ReadWrite();
86  parent::$_buffer->initializeWith($this->__toString());
87  }
88 
89  return parent::$_buffer->read($length);
90  }
91 
98  public function readString($length)
99  {
100  return $this->read($length);
101  }
102 
108  public function readCharacter()
109  {
110  return $this->read(1);
111  }
112 
118  public function readBoolean()
119  {
120  return (bool) $this->read(1);
121  }
122 
129  public function readInteger($length = 1)
130  {
131  return (int) $this->read($length);
132  }
133 
140  public function readFloat($length = 1)
141  {
142  return (float) $this->read($length);
143  }
144 
151  public function readArray($argument = null)
152  {
153  return (array) $this;
154  }
155 
161  public function readLine()
162  {
163  $handle = $this->readAll();
164  $n = strpos($handle, "\n");
165 
166  if (false === $n) {
167  return $handle;
168  }
169 
170  return substr($handle, 0, $n);
171  }
172 
179  public function readAll($offset = 0)
180  {
181  return $this->__toString();
182  }
183 
190  public function scanf($format)
191  {
192  return sscanf($this->readAll(), $format);
193  }
194 }
readFloat($length=1)
Definition: Read.php:140
read($length)
Definition: Read.php:74
readAll($offset=0)
Definition: Read.php:179
scanf($format)
Definition: Read.php:190
readArray($argument=null)
Definition: Read.php:151
readAll($offset=0)
Definition: Read.php:162
read($length)
Definition: Read.php:68
readInteger($length=1)
Definition: Read.php:129
readString($length)
Definition: Read.php:98