Documentation

Stream

Interface \Hoa\Stream\Wrapper\IWrapper\Stream.

Interface for “stream stream wrapper” class.

Tags
copyright

Copyright © 2007-2017 Hoa community

license

New BSD License

Table of Contents

Methods

stream_cast()  : resource
Retrieve the underlaying resource.
stream_close()  : void
Close a resource.
stream_eof()  : bool
Tests for end-of-file on a file pointer.
stream_flush()  : bool
Flush the output.
stream_lock()  : bool
Advisory file locking.
stream_metadata()  : bool
Change stream options.
stream_open()  : bool
Open file or URL.
stream_read()  : string
Read from stream.
stream_seek()  : bool
Seek to specific location in a stream.
stream_set_option()  : bool
Change stream options.
stream_stat()  : array<string|int, mixed>
Retrieve information about a file resource.
stream_tell()  : int
Retrieve the current position of a stream.
stream_truncate()  : bool
Truncate a stream to a given length.
stream_write()  : int
Write to stream.

Methods

stream_cast()

Retrieve the underlaying resource.

public stream_cast(int $castAs) : resource
Parameters
$castAs : int

Can be STREAM_CAST_FOR_SELECT when stream_select() is calling stream_cast() or STREAM_CAST_AS_STREAM when stream_cast() is called for other uses.

Return values
resource

stream_close()

Close a resource.

public stream_close() : void

This method is called in response to fclose(). All resources that were locked, or allocated, by the wrapper should be released.

stream_eof()

Tests for end-of-file on a file pointer.

public stream_eof() : bool

This method is called in response to feof().

Return values
bool

stream_flush()

Flush the output.

public stream_flush() : bool

This method is called in response to fflush(). If we have cached data in our stream but not yet stored it into the underlying storage, we should do so now.

Return values
bool

stream_lock()

Advisory file locking.

public stream_lock(int $operation) : bool

This method is called in response to flock(), when file_put_contents() (when flags contains LOCK_EX), stream_set_blocking() and when closing the stream (LOCK_UN).

Parameters
$operation : int

Operation is one the following:

  • LOCK_SH to acquire a shared lock (reader) ;
  • LOCK_EX to acquire an exclusive lock (writer) ;
  • LOCK_UN to release a lock (shared or exclusive) ;
  • LOCK_NB if we don't want flock() to block while locking (not supported on Windows).
Return values
bool

stream_metadata()

Change stream options.

public stream_metadata(string $path, int $option, mixed $value) : bool

This method is called to set metadata on the stream. It is called when one of the following functions is called one a stream URL: touch, chmod, chown or chgrp.

Parameters
$path : string

The file path or URL to set metadata.

$option : int

One of the following:

  • STREAM_META_TOUCH,
  • STREAM_META_OWNER_NAME,
  • STREAM_META_OWNER,
  • STREAM_META_GROUP_NAME,
  • STREAM_META_GROUP,
  • STREAM_META_ACCESS.
$value : mixed

An array or a scalar depending of the option.

Return values
bool

stream_open()

Open file or URL.

public stream_open(string $path, string $mode, int $options, string &$openedPath) : bool

This method is called immediately after the wrapper is initialized (f.e. by fopen() and file_get_contents()).

Parameters
$path : string

Specifies the URL that was passed to the original function.

$mode : string

The mode used to open the file, as detailed for fopen().

$options : int

Holds additional flags set by the streams API. It can hold one or more of the following values OR'd together:

  • STREAM_USE_PATH, if path is relative, search for the resource using the include_path;
  • STREAM_REPORT_ERRORS, if this is set, you are responsible for raising errors using trigger_error during opening the stream. If this is not set, you should not raise any errors.
$openedPath : string

If the $path is opened successfully, and STREAM_USE_PATH is set in $options, $openedPath should be set to the full path of the file/resource that was actually opened.

Return values
bool

stream_read()

Read from stream.

public stream_read(int $count) : string

This method is called in response to fread() and fgets().

Parameters
$count : int

How many bytes of data from the current position should be returned.

Return values
string

stream_seek()

Seek to specific location in a stream.

public stream_seek(int $offset[, int $whence = SEEK_SET ]) : bool

This method is called in response to fseek(). The read/write position of the stream should be updated according to the $offset and $whence.

Parameters
$offset : int

The stream offset to seek to.

$whence : int = SEEK_SET

Possible values:

  • SEEK_SET to set position equal to $offset bytes ;
  • SEEK_CUR to set position to current location plus $offsete ;
  • SEEK_END to set position to end-of-file plus $offset.
Return values
bool

stream_set_option()

Change stream options.

public stream_set_option(int $option, int $arg1, int $arg2) : bool

This method is called to set options on the stream.

Parameters
$option : int

One of:

  • STREAM_OPTION_BLOCKING, the method was called in response to stream_set_blocking() ;
  • STREAM_OPTION_READ_TIMEOUT, the method was called in response to stream_set_timeout() ;
  • STREAM_OPTION_WRITE_BUFFER, the method was called in response to stream_set_write_buffer().
$arg1 : int

If $option is:

  • STREAM_OPTION_BLOCKING: requested blocking mode (1 meaning block, 0 not blocking) ;
  • STREAM_OPTION_READ_TIMEOUT: the timeout in seconds ;
  • STREAM_OPTION_WRITE_BUFFER: buffer mode (STREAM_BUFFER_NONE or STREAM_BUFFER_FULL).
$arg2 : int

If $option is:

  • STREAM_OPTION_BLOCKING: this option is not set ;
  • STREAM_OPTION_READ_TIMEOUT: the timeout in microseconds ;
  • STREAM_OPTION_WRITE_BUFFER: the requested buffer size.
Return values
bool

stream_stat()

Retrieve information about a file resource.

public stream_stat() : array<string|int, mixed>

This method is called in response to fstat().

Return values
array<string|int, mixed>

stream_tell()

Retrieve the current position of a stream.

public stream_tell() : int

This method is called in response to ftell().

Return values
int

stream_truncate()

Truncate a stream to a given length.

public stream_truncate(int $size) : bool
Parameters
$size : int

Size.

Return values
bool

stream_write()

Write to stream.

public stream_write(string $data) : int

This method is called in response to fwrite().

Parameters
$data : string

Should be stored into the underlying stream.

Return values
int

        
On this page

Search results