Функция stream_wrapper_register()

14.01.2008

bool stream_wrapper_register ( string protocol, string classname )
stream_wrapper_register() allows you to implement

your own protocol handlers and streams for use with all the other

filesystem functions (such as ,
etc.).
To implement a wrapper, you need to define a class with a number of

member functions, as defined below. When someone fopens your stream,

PHP will create an instance of
and

then call methods on that instance. You must implement the methods

exactly as described below - doing otherwise will lead to undefined

behaviour.
stream_wrapper_register() FALSE already has a handler.
bool stream_open ( string path, string mode, int options, string opened_path )
This method is called immediately after your stream object is

created.
specifies the URL that was

passed to and that this object is

expected to retrieve. You can use
to break it apart.
is the mode used to open the file,

as detailed for
. You are responsible

for checking that
requested.
holds additional flags set

by the streams API. It can hold one or more of the following

values OR'd together.
is opened successfully,

and STREAM_USE_PATH is set in
,

you should set
to the full

path of the file/resource that was actually opened.
If the requested resource was opened successfully, you should

return
TRUE , otherwise you should return
FALSE void stream_close This method is called when the stream is closed, using
. You must release any resources

that were locked or allocated by the stream.
string stream_read This method is called in response to and calls on the stream. You

must return up-to
bytes of data

from the current read/write position as a string.

If there are less than
bytes available, return as many as are available. If no

more data is available, return either
FALSE or an

empty string.

You must also update the read/write position of the stream

by the number of bytes that were successfully read.
int stream_write This method is called in response to calls on the stream. You should store
into the underlying storage used by your stream. If there is not

enough room, try to store as many bytes as possible.

You should return the number of bytes that were successfully

stored in the stream, or 0 if none could be stored.

You must also update the read/write position of the stream

by the number of bytes that were successfully written.
bool stream_eof This method is called in response to calls on the stream. You should return
TRUE if the read/write

position is at the end of the stream and if no more data is available

to be read, or
FALSE otherwise.
int stream_tell This method is called in response to calls on the stream. You should return the current read/write

position of the stream.
bool stream_seek ( int offset, int whence )
This method is called in response to calls on the stream. You should update the read/write position

of the stream according to
. See
for more information about these parameters.

Return
TRUE if the position was updated,
FALSE otherwise.
bool stream_flush This method is called in response to calls on the stream. If you have cached data in your stream

but not yet stored it into the underlying storage, you should

do so now.

Return
TRUE if the cached data was successfully stored (or

if there was no data to store), or
FALSE if the data could

not be stored.
array stream_stat This method is called in response to calls on the stream and should return an array containing the same

values as appropriate for the stream.
bool unlink This method is called in response to .

It should return
TRUE FALSE on failure.

In order for the appropriate error message to be returned,

do not define this method if your wrapper does not support unlinking.
bool rename ( string path_from, string path_to )
This method is called in response to .

It should return
TRUE FALSE on failure.

In order for the appropriate error message to be returned,

do not define this method if your wrapper does not support renaming.
bool mkdir ( string path, int mode, int options )
This method is called in response to .

It should return
TRUE FALSE on failure.

In order for the appropriate error message to be returned,

do not define this method if your wrapper does not support

creating directories. Posible values for
STREAM_REPORT_ERRORS STREAM_MKDIR_RECURSIVE .
bool rmdir ( string path, int options )
This method is called in response to .

It should return
TRUE FALSE on failure.

In order for the appropriate error message to be returned,

do not define this method if your wrapper does not support

removing directories. Possible values for
STREAM_REPORT_ERRORS .
bool dir_opendir ( string path, int options )
This method is called immediately when your stream object is created for

examining directory contents with .
specifies the URL that was

passed to and that this object is

expected to explore. You can use
to break it apart.
array url_stat ( string path, int flags )
This method is called in response to calls on the URL paths associated with the wrapper and should

return as many elements in common with the system function as

possible. Unknown or unavailable values should be set to a

rational value (usually
0 ).
holds additional flags set

by the streams API. It can hold one or more of the following

values OR'd together.
string dir_readdir This method is called in response to and should return a string representing the next filename in the

location opened by dir_opendir() .
bool dir_rewinddir This method is called in response to and should reset the output generated by dir_readdir() .

i.e.: The next call to
dir_readdir() should return

the first entry in the location returned by dir_opendir() .
bool dir_closedir This method is called in response to .

You should release any resources which were locked or allocated during

the opening and use of the directory stream.
The example below implements a var:// protocol handler that

allows read/write access to a named global variable using

standard filesystem stream functions such as .

The var:// protocol implemented below, given the URL

"var://foo" will read/write data to/from $GLOBALS["foo"].

google.com bobrdobr.ru del.icio.us technorati.com linkstore.ru news2.ru rumarkz.ru memori.ru moemesto.ru

Рубрики: Без рубрики |

Оставить комментарий

Заметьте: Включена проверка комментариев. Нет смысла повторно отправлять комментарий.