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

Public Member Functions

 __construct ($streamName, $mode=parent::MODE_APPEND_WRITE, $context=null, $wait=false)
 
 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.

New BSD License

Definition at line 49 of file Write.php.

Constructor & Destructor Documentation

Hoa\File\Link\Write::__construct (   $streamName,
  $mode = parent::MODE_APPEND_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 61 of file Write.php.

66  {
67  parent::__construct($streamName, $mode, $context, $wait);
68 
69  return;
70  }

Member Function Documentation

& Hoa\File\Link\Write::_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 81 of file Write.php.

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

Here is the call graph for this function:

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

Truncate a file to a given length.

Parameters
int$sizeSize.
Returns
bool

Implements Hoa\Stream\IStream\Out.

Definition at line 242 of file Write.php.

243  {
244  return ftruncate($this->getStream(), $size);
245  }

Here is the call graph for this function:

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

Write n characters.

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

Implements Hoa\Stream\IStream\Out.

Definition at line 121 of file Write.php.

122  {
123  if (0 > $length) {
124  throw new File\Exception(
125  'Length must be greater than 0, given %d.',
126  2,
127  $length
128  );
129  }
130 
131  return fwrite($this->getStream(), $string, $length);
132  }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 231 of file Write.php.

232  {
233  return $this->write($string, strlen($string));
234  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:

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

Write an array.

Parameters
array$arrayArray.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 201 of file Write.php.

202  {
203  $array = var_export($array, true);
204 
205  return $this->write($array, strlen($array));
206  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:

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

Write a boolean.

Parameters
bool$booleanBoolean.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 164 of file Write.php.

165  {
166  return $this->write((string) (bool) $boolean, 1);
167  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:

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

Write a character.

Parameters
string$charCharacter.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 153 of file Write.php.

154  {
155  return $this->write((string) $char[0], 1);
156  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:

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

Write a float.

Parameters
float$floatFloat.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 188 of file Write.php.

189  {
190  $float = (string) (float) $float;
191 
192  return $this->write($float, strlen($float));
193  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:

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

Write an integer.

Parameters
int$integerInteger.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 175 of file Write.php.

176  {
177  $integer = (string) (int) $integer;
178 
179  return $this->write($integer, strlen($integer));
180  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:

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

Write a line.

Parameters
string$lineLine.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 214 of file Write.php.

215  {
216  if (false === $n = strpos($line, "\n")) {
217  return $this->write($line . "\n", strlen($line) + 1);
218  }
219 
220  ++$n;
221 
222  return $this->write(substr($line, 0, $n), $n);
223  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:

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

Write a string.

Parameters
string$stringString.
Returns
mixed

Implements Hoa\Stream\IStream\Out.

Definition at line 140 of file Write.php.

141  {
142  $string = (string) $string;
143 
144  return $this->write($string, strlen($string));
145  }
write($string, $length)
Definition: Write.php:121

Here is the call graph for this function:


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