Hoa central
Public Member Functions | Protected Member Functions | List of all members
Hoa\File\Link\ReadWrite Class Reference
Inheritance diagram for Hoa\File\Link\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\Link\Link
 __construct ($streamName, $mode, $context=null, $wait=false)
 
 getStatistic ()
 
 changeGroup ($group)
 
 changeOwner ($user)
 
 getPermissions ()
 
 getTarget ()
 
 getTargetName ()
 
- 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\Link\Link
static create ($name, $target)
 
- 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 50 of file ReadWrite.php.

Constructor & Destructor Documentation

Hoa\File\Link\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 parent::MODE_* constants.
string$contextContext ID (please, see the class).
bool$waitDiffer opening or not.
Returns
void

Definition at line 65 of file ReadWrite.php.

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

Member Function Documentation

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

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

Here is the call graph for this function:

Hoa\File\Link\ReadWrite::eof ( )

Test for end-of-file.

Returns
bool

Implements Hoa\Stream\IStream\In.

Definition at line 124 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Read n characters.

Parameters
int$lengthLength.
Returns
string
Exceptions

Implements Hoa\Stream\IStream\In.

Definition at line 136 of file ReadWrite.php.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

Hoa\File\Link\ReadWrite::readBoolean ( )

Read a boolean.

Returns
bool

Implements Hoa\Stream\IStream\In.

Definition at line 175 of file ReadWrite.php.

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

Here is the call graph for this function:

Hoa\File\Link\ReadWrite::readCharacter ( )

Read a character.

Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 165 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Read a float.

Parameters
int$lengthLength.
Returns
float

Implements Hoa\Stream\IStream\In.

Definition at line 197 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Read an integer.

Parameters
int$lengthLength.
Returns
int

Implements Hoa\Stream\IStream\In.

Definition at line 186 of file ReadWrite.php.

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

Here is the call graph for this function:

Hoa\File\Link\ReadWrite::readLine ( )

Read a line.

Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 219 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Alias of $this->read().

Parameters
int$lengthLength.
Returns
string

Implements Hoa\Stream\IStream\In.

Definition at line 155 of file ReadWrite.php.

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Truncate a file to a given length.

Parameters
int$sizeSize.
Returns
bool

Implements Hoa\Stream\IStream\Out.

Definition at line 375 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write n characters.

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

Implements Hoa\Stream\IStream\Out.

Definition at line 254 of file ReadWrite.php.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 364 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write an array.

Parameters
array$arrayArray.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 334 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write a boolean.

Parameters
bool$booleanBoolean.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 297 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write a character.

Parameters
string$charCharacter.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 286 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write a float.

Parameters
float$floatFloat.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 321 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write an integer.

Parameters
int$integerInteger.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 308 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write a line.

Parameters
string$lineLine.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 347 of file ReadWrite.php.

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

Here is the call graph for this function:

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

Write a string.

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 273 of file ReadWrite.php.

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

Here is the call graph for this function:


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