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

Public Member Functions

 __construct ($streamName, $mode=parent::MODE_APPEND_READ_WRITE, $context=null, $wait=false)
 
 eof ()
 
 read ($length)
 
 readString ($length)
 
 readCharacter ()
 
 readBoolean ()
 
 readInteger ($length=1)
 
 readFloat ($length=1)
 
 readArray ($format=null)
 
 readLine ()
 
 readAll ($offset=0)
 
 scanf ($format)
 
 write ($string, $length)
 
 writeString ($string)
 
 writeCharacter ($char)
 
 writeBoolean ($boolean)
 
 writeInteger ($integer)
 
 writeFloat ($float)
 
 writeArray (Array $array)
 
 writeLine ($line)
 
 writeAll ($string)
 
 truncate ($size)
 
- Public Member Functions inherited from Hoa\File\File
 __construct ($streamName, $mode, $context=null, $wait=false)
 
 newBuffer ($callable=null, $size=null)
 
 flush ()
 
 deleteBuffer ()
 
 getBufferLevel ()
 
 getBufferSize ()
 
 lock ($operation)
 
 rewind ()
 
 seek ($offset, $whence=Stream\IStream\Pointable::SEEK_SET)
 
 tell ()
 
- Public Member Functions inherited from Hoa\File\Generic
 getBasename ()
 
 getDirname ()
 
 getSize ()
 
 getStatistic ()
 
 getATime ()
 
 getCTime ()
 
 getMTime ()
 
 getGroup ()
 
 getOwner ()
 
 getPermissions ()
 
 getReadablePermissions ()
 
 isReadable ()
 
 isWritable ()
 
 isExecutable ()
 
 clearStatisticCache ()
 
 touch ($time=-1, $atime=-1)
 
 copy ($to, $force=Stream\IStream\Touchable::DO_NOT_OVERWRITE)
 
 move ($name, $force=Stream\IStream\Touchable::DO_NOT_OVERWRITE, $mkdir=Stream\IStream\Touchable::DO_NOT_MAKE_DIRECTORY)
 
 delete ()
 
 changeGroup ($group)
 
 changeMode ($mode)
 
 changeOwner ($user)
 
 isFile ()
 
 isLink ()
 
 isDirectory ()
 
 isSocket ()
 
 isFIFOPipe ()
 
 isCharacterSpecial ()
 
 isBlockSpecial ()
 
 isUnknown ()
 
 getMode ()
 
 getINode ()
 
 getRealPath ()
 
 getExtension ()
 
 getFilename ()
 
- Public Member Functions inherited from Hoa\Stream\Stream
 __construct ($streamName, $context=null, $wait=false)
 
 open ()
 
 close ()
 
 getStreamName ()
 
 getStreamContext ()
 
 _setStream ($stream)
 
 isOpened ()
 
 setStreamTimeout ($seconds, $microseconds=0)
 
 setStreamBlocking ($mode)
 
 setStreamBuffer ($buffer)
 
 disableStreamBuffer ()
 
 getStreamBufferSize ()
 
 getStreamWrapperName ()
 
 getStreamMetaData ()
 
 isBorrowing ()
 
 on ($listenerId, $callable)
 
 _notify ($ncode, $severity, $message, $code, $transferred, $max)
 
 __toString ()
 
 __destruct ()
 

Protected Member Functions

_open ($streamName, Stream\Context $context=null)
 
- Protected Member Functions inherited from Hoa\File\File
_open ($streamName, Stream\Context $context=null)
 
 _close ()
 
- Protected Member Functions inherited from Hoa\File\Generic
 setMode ($mode)
 
- Protected Member Functions inherited from Hoa\Stream\Stream
_open ($streamName, Context $context=null)
 
 _close ()
 
 getStream ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Hoa\File\File
static create ($name, $dummy)
 
- Static Public Member Functions inherited from Hoa\File\Generic
static clearAllStatisticCaches ()
 
static umask ($umask=null)
 
static isCaseSensitive ()
 
- Static Public Member Functions inherited from Hoa\Stream\Stream
static getStreamHandler ($streamName)
 
static _Hoa_Stream ()
 
- Public Attributes inherited from Hoa\File\File
const MODE_READ = 'rb'
 
const MODE_READ_WRITE = 'r+b'
 
const MODE_TRUNCATE_WRITE = 'wb'
 
const MODE_TRUNCATE_READ_WRITE = 'w+b'
 
const MODE_APPEND_WRITE = 'ab'
 
const MODE_APPEND_READ_WRITE = 'a+b'
 
const MODE_CREATE_WRITE = 'xb'
 
const MODE_CREATE_READ_WRITE = 'x+b'
 
- Public Attributes inherited from Hoa\Stream\Stream
const NAME = 0
 
const HANDLER = 1
 
const RESOURCE = 2
 
const CONTEXT = 3
 
- Public Attributes inherited from Hoa\Stream\IStream\Statable
const SIZE_UNDEFINED = -1
 
- Public Attributes inherited from Hoa\Stream\IStream\Touchable
const OVERWRITE = true
 
const DO_NOT_OVERWRITE = false
 
const MAKE_DIRECTORY = true
 
const DO_NOT_MAKE_DIRECTORY = false
 
- Public Attributes inherited from Hoa\Stream\IStream\Lockable
const LOCK_SHARED = LOCK_SH
 
const LOCK_EXCLUSIVE = LOCK_EX
 
const LOCK_RELEASE = LOCK_UN
 
const LOCK_NO_BLOCK = LOCK_NB
 
- Public Attributes inherited from Hoa\Stream\IStream\Pointable
const SEEK_SET = SEEK_SET
 
const SEEK_CURRENT = SEEK_CUR
 
const SEEK_END = SEEK_END
 
- Protected Attributes inherited from Hoa\File\Generic
 $_mode = null
 
- Protected Attributes inherited from Hoa\Stream\Stream
 $_bucket = []
 
 $_bufferSize = 8192
 
 $_streamName = null
 
 $_context = null
 
 $_hasBeenDiffered = false
 
 $_on = null
 
 $_borrowed = false
 

Detailed Description

Class .

File handler.

Definition at line 49 of file ReadWrite.php.

Constructor & Destructor Documentation

Hoa\File\ReadWrite::__construct (   $streamName,
  $mode = parent::MODE_APPEND_READ_WRITE,
  $context = null,
  $wait = false 
)

Open a file.

Parameters
string$streamNameStream name.
string$modeOpen mode, see the self::MODE_* constants.
string$contextContext ID (please, see the class).
bool$waitDiffer opening or not.
Returns
void

Definition at line 64 of file ReadWrite.php.

69  {
70  parent::__construct($streamName, $mode, $context, $wait);
71 
72  return;
73  }

Member Function Documentation

& Hoa\File\ReadWrite::_open (   $streamName,
Stream\Context  $context = null 
)
protected

Open the stream and return the associated resource.

Parameters
string$streamNameStream name (e.g. path or URL).
\Hoa\Stream\Context$contextContext.
Returns
resource
Exceptions

Definition at line 84 of file ReadWrite.php.

85  {
86  static $createModes = [
87  parent::MODE_READ_WRITE,
88  parent::MODE_TRUNCATE_READ_WRITE,
89  parent::MODE_APPEND_READ_WRITE,
90  parent::MODE_CREATE_READ_WRITE
91  ];
92 
93  if (!in_array($this->getMode(), $createModes)) {
94  throw new Exception(
95  'Open mode are not supported; given %d. Only %s are supported.',
96  0,
97  [$this->getMode(), implode(', ', $createModes)]
98  );
99  }
100 
101  preg_match('#^(\w+)://#', $streamName, $match);
102 
103  if (((isset($match[1]) && $match[1] == 'file') || !isset($match[1])) &&
104  !file_exists($streamName) &&
105  parent::MODE_READ_WRITE == $this->getMode()) {
106  throw new Exception\FileDoesNotExist(
107  'File %s does not exist.',
108  1,
109  $streamName
110  );
111  }
112 
113  $out = parent::_open($streamName, $context);
114 
115  return $out;
116  }

Here is the call graph for this function:

Hoa\File\ReadWrite::eof ( )

Test for end-of-file.

Returns
bool

Implements Hoa\Stream\IStream\In.

Definition at line 123 of file ReadWrite.php.

124  {
125  return feof($this->getStream());
126  }

Here is the call graph for this function:

Hoa\File\ReadWrite::read (   $length)

Read n characters.

Parameters
int$lengthLength.
Returns
string
Exceptions

Implements Hoa\Stream\IStream\In.

Definition at line 135 of file ReadWrite.php.

136  {
137  if (0 > $length) {
138  throw new Exception(
139  'Length must be greater than 0, given %d.',
140  2,
141  $length
142  );
143  }
144 
145  return fread($this->getStream(), $length);
146  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\File\ReadWrite::readAll (   $offset = 0)

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

Parameters
int$offsetOffset.
Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 229 of file ReadWrite.php.

230  {
231  return stream_get_contents($this->getStream(), -1, $offset);
232  }

Here is the call graph for this function:

Hoa\File\ReadWrite::readArray (   $format = null)

Read an array. Alias of the $this->scanf() method.

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

Implements Hoa\Stream\IStream\In.

Definition at line 208 of file ReadWrite.php.

209  {
210  return $this->scanf($format);
211  }

Here is the call graph for this function:

Hoa\File\ReadWrite::readBoolean ( )

Read a boolean.

Returns
bool

Implements Hoa\Stream\IStream\In.

Definition at line 174 of file ReadWrite.php.

175  {
176  return (bool) $this->read(1);
177  }

Here is the call graph for this function:

Hoa\File\ReadWrite::readCharacter ( )

Read a character.

Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 164 of file ReadWrite.php.

165  {
166  return fgetc($this->getStream());
167  }

Here is the call graph for this function:

Hoa\File\ReadWrite::readFloat (   $length = 1)

Read a float.

Parameters
int$lengthLength.
Returns
float

Implements Hoa\Stream\IStream\In.

Definition at line 196 of file ReadWrite.php.

197  {
198  return (float) $this->read($length);
199  }

Here is the call graph for this function:

Hoa\File\ReadWrite::readInteger (   $length = 1)

Read an integer.

Parameters
int$lengthLength.
Returns
int

Implements Hoa\Stream\IStream\In.

Definition at line 185 of file ReadWrite.php.

186  {
187  return (int) $this->read($length);
188  }

Here is the call graph for this function:

Hoa\File\ReadWrite::readLine ( )

Read a line.

Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 218 of file ReadWrite.php.

219  {
220  return fgets($this->getStream());
221  }

Here is the call graph for this function:

Hoa\File\ReadWrite::readString (   $length)

Alias of $this->read().

Parameters
int$lengthLength.
Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 154 of file ReadWrite.php.

155  {
156  return $this->read($length);
157  }

Here is the call graph for this function:

Hoa\File\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 240 of file ReadWrite.php.

241  {
242  return fscanf($this->getStream(), $format);
243  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\File\ReadWrite::truncate (   $size)

Truncate a file to a given length.

Parameters
int$sizeSize.
Returns
bool

Implements Hoa\Stream\IStream\Out.

Definition at line 374 of file ReadWrite.php.

375  {
376  return ftruncate($this->getStream(), $size);
377  }

Here is the call graph for this function:

Hoa\File\ReadWrite::write (   $string,
  $length 
)

Write n characters.

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

Implements Hoa\Stream\IStream\Out.

Definition at line 253 of file ReadWrite.php.

254  {
255  if (0 > $length) {
256  throw new Exception(
257  'Length must be greater than 0, given %d.',
258  3,
259  $length
260  );
261  }
262 
263  return fwrite($this->getStream(), $string, $length);
264  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\File\ReadWrite::writeAll (   $string)

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

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 363 of file ReadWrite.php.

364  {
365  return $this->write($string, strlen($string));
366  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\File\ReadWrite::writeArray ( Array  $array)

Write an array.

Parameters
array$arrayArray.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 333 of file ReadWrite.php.

334  {
335  $array = var_export($array, true);
336 
337  return $this->write($array, strlen($array));
338  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:

Hoa\File\ReadWrite::writeBoolean (   $boolean)

Write a boolean.

Parameters
bool$booleanBoolean.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 296 of file ReadWrite.php.

297  {
298  return $this->write((string) (bool) $boolean, 1);
299  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:

Hoa\File\ReadWrite::writeCharacter (   $char)

Write a character.

Parameters
string$charCharacter.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 285 of file ReadWrite.php.

286  {
287  return $this->write((string) $char[0], 1);
288  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:

Hoa\File\ReadWrite::writeFloat (   $float)

Write a float.

Parameters
float$floatFloat.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 320 of file ReadWrite.php.

321  {
322  $float = (string) (float) $float;
323 
324  return $this->write($float, strlen($float));
325  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:

Hoa\File\ReadWrite::writeInteger (   $integer)

Write an integer.

Parameters
int$integerInteger.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 307 of file ReadWrite.php.

308  {
309  $integer = (string) (int) $integer;
310 
311  return $this->write($integer, strlen($integer));
312  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:

Hoa\File\ReadWrite::writeLine (   $line)

Write a line.

Parameters
string$lineLine.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 346 of file ReadWrite.php.

347  {
348  if (false === $n = strpos($line, "\n")) {
349  return $this->write($line . "\n", strlen($line) + 1);
350  }
351 
352  ++$n;
353 
354  return $this->write(substr($line, 0, $n), $n);
355  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:

Hoa\File\ReadWrite::writeString (   $string)

Write a string.

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 272 of file ReadWrite.php.

273  {
274  $string = (string) $string;
275 
276  return $this->write($string, strlen($string));
277  }
write($string, $length)
Definition: ReadWrite.php:253

Here is the call graph for this function:


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