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

Public Member Functions

 __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 ()
 

Static Public Member Functions

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

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 Member Functions

_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

- 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 File.php.

Constructor & Destructor Documentation

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

Open a file.

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

Definition at line 142 of file File.php.

147  {
148  $this->setMode($mode);
149 
150  switch ($streamName) {
151 
152  case '0':
153  $streamName = 'php://stdin';
154 
155  break;
156 
157  case '1':
158  $streamName = 'php://stdout';
159 
160  break;
161 
162  case '2':
163  $streamName = 'php://stderr';
164 
165  break;
166 
167  default:
168  if (true === ctype_digit($streamName)) {
169  if (PHP_VERSION_ID >= 50306) {
170  $streamName = 'php://fd/' . $streamName;
171  } else {
172  throw new Exception(
173  'You need PHP5.3.6 to use a file descriptor ' .
174  'other than 0, 1 or 2 (tried %d with PHP%s).',
175  0,
176  [$streamName, PHP_VERSION]
177  );
178  }
179  }
180  }
181 
182  parent::__construct($streamName, $context, $wait);
183 
184  return;
185  }
setMode($mode)
Definition: Generic.php:517

Here is the call graph for this function:

Member Function Documentation

Hoa\File\File::_close ( )
protected

Close the current stream.

Returns
bool

Definition at line 242 of file File.php.

243  {
244  return @fclose($this->getStream());
245  }

Here is the call graph for this function:

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

197  {
198  if (substr($streamName, 0, 4) == 'file' &&
199  false === is_dir(dirname($streamName))) {
200  throw new Exception(
201  'Directory %s does not exist. Could not open file %s.',
202  1,
203  [dirname($streamName), basename($streamName)]
204  );
205  }
206 
207  if (null === $context) {
208  if (false === $out = @fopen($streamName, $this->getMode(), true)) {
209  throw new Exception(
210  'Failed to open stream %s.',
211  2,
212  $streamName
213  );
214  }
215 
216  return $out;
217  }
218 
219  $out = @fopen(
220  $streamName,
221  $this->getMode(),
222  true,
223  $context->getContext()
224  );
225 
226  if (false === $out) {
227  throw new Exception(
228  'Failed to open stream %s.',
229  3,
230  $streamName
231  );
232  }
233 
234  return $out;
235  }

Here is the call graph for this function:

static Hoa\File\File::create (   $name,
  $dummy 
)
static

Create a file.

Parameters
string$nameFile name.
mixed$dummyTo be compatible with childs.
Returns
bool

Definition at line 362 of file File.php.

363  {
364  if (file_exists($name)) {
365  return true;
366  }
367 
368  return touch($name);
369  }
touch($time=-1, $atime=-1)
Definition: Generic.php:286

Here is the call graph for this function:

Hoa\File\File::deleteBuffer ( )

Delete buffer.

Returns
bool

Implements Hoa\Stream\IStream\Bufferable.

Definition at line 279 of file File.php.

280  {
281  return $this->disableStreamBuffer();
282  }

Here is the call graph for this function:

Hoa\File\File::flush ( )

Flush the output to a stream.

Returns
bool

Implements Hoa\Stream\IStream\Bufferable.

Definition at line 269 of file File.php.

270  {
271  return fflush($this->getStream());
272  }

Here is the call graph for this function:

Hoa\File\File::getBufferLevel ( )

Get bufffer level.

Returns
int

Implements Hoa\Stream\IStream\Bufferable.

Definition at line 289 of file File.php.

290  {
291  return 1;
292  }
Hoa\File\File::getBufferSize ( )

Get buffer size.

Returns
int

Implements Hoa\Stream\IStream\Bufferable.

Definition at line 299 of file File.php.

300  {
301  return $this->getStreamBufferSize();
302  }

Here is the call graph for this function:

Hoa\File\File::lock (   $operation)

Portable advisory locking.

Parameters
int$operationOperation, use the ::LOCK_* constants.
Returns
bool

Implements Hoa\Stream\IStream\Lockable.

Definition at line 311 of file File.php.

312  {
313  return flock($this->getStream(), $operation);
314  }

Here is the call graph for this function:

Hoa\File\File::newBuffer (   $callable = null,
  $size = null 
)

Start a new buffer. The callable acts like a light filter.

Parameters
mixed$callableCallable.
int$sizeSize.
Returns
int

Implements Hoa\Stream\IStream\Bufferable.

Definition at line 255 of file File.php.

256  {
257  $this->setStreamBuffer($size);
258 
259  //@TODO manage $callable as a filter?
260 
261  return 1;
262  }
setStreamBuffer($buffer)
Definition: Stream.php:465

Here is the call graph for this function:

Hoa\File\File::rewind ( )

Rewind the position of a stream pointer.

Returns
bool

Implements Hoa\Stream\IStream\Pointable.

Definition at line 321 of file File.php.

322  {
323  return rewind($this->getStream());
324  }

Here is the call graph for this function:

Hoa\File\File::seek (   $offset,
  $whence = Stream\IStream\Pointable::SEEK_SET 
)

Seek on a stream pointer.

Parameters
int$offsetOffset (negative value should be supported).
int$whenceWhence, use the ::SEEK_* constants.
Returns
int

Implements Hoa\Stream\IStream\Pointable.

Definition at line 334 of file File.php.

335  {
336  return fseek($this->getStream(), $offset, $whence);
337  }

Here is the call graph for this function:

Hoa\File\File::tell ( )

Get the current position of the stream pointer.

Returns
int

Implements Hoa\Stream\IStream\Pointable.

Definition at line 344 of file File.php.

345  {
346  $stream = $this->getStream();
347 
348  if (null === $stream) {
349  return 0;
350  }
351 
352  return ftell($stream);
353  }

Here is the call graph for this function:

Member Data Documentation

const Hoa\File\File::MODE_APPEND_READ_WRITE = 'a+b'

Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

string

Definition at line 104 of file File.php.

const Hoa\File\File::MODE_APPEND_WRITE = 'ab'

Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.

string

Definition at line 96 of file File.php.

const Hoa\File\File::MODE_CREATE_READ_WRITE = 'x+b'

Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call with fail by returning false and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL | O_CREAT flags for the underlying open(2) system call.

string

Definition at line 126 of file File.php.

const Hoa\File\File::MODE_CREATE_WRITE = 'xb'

Create and open for writing only; place the file pointer at the beginning of the file. If the file already exits, the fopen() call with fail by returning false and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL | O_CREAT flags for the underlying open(2) system call.

string

Definition at line 115 of file File.php.

const Hoa\File\File::MODE_READ = 'rb'

Open for reading only; place the file pointer at the beginning of the file.

string

Definition at line 62 of file File.php.

const Hoa\File\File::MODE_READ_WRITE = 'r+b'

Open for reading and writing; place the file pointer at the beginning of the file.

string

Definition at line 70 of file File.php.

const Hoa\File\File::MODE_TRUNCATE_READ_WRITE = 'w+b'

Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

string

Definition at line 88 of file File.php.

const Hoa\File\File::MODE_TRUNCATE_WRITE = 'wb'

Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.

string

Definition at line 79 of file File.php.


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