class php_user_filter (View source)

Children of this class are passed to stream_filter_register. Note that the __construct method is not called; instead, php_user_filter::onCreate should be used for initialization.

Properties

$filtername
$params
$stream

Methods

int
filter(resource $in, resource $out, int $consumed, bool $closing)

Called when applying the filter

bool
onCreate()

Called when creating the filter

void
onClose()

Called when closing the filter

bool
seek(int $offset, int $whence, int $chain)

No description

Details

int filter(resource $in, resource $out, int $consumed, bool $closing)

Called when applying the filter

This method is called whenever data is read from or written to the attached stream (such as with fread or fwrite).

Parameters

resource $in

is a resource pointing to a bucket brigadebucket objects containing data to be filtered.

resource $out

is a resource pointing to a second bucket brigade into which your modified buckets should be placed.

int $consumed

which must always be declared by reference, should be incremented by the length of the data which your filter reads in and alters. In most cases this means you will increment consumed by $bucket->datalen for each $bucket.

bool $closing

If the stream is in the process of closing (and therefore this is the last pass through the filterchain), the closing parameter will be set to TRUE

Return Value

int

The filter() method must return one of three values upon completion.

Return Value Meaning
PSFS_PASS_ON Filter processed successfully with data available in the out``` bucket brigade.
PSFS_FEED_ME Filter processed successfully, however no data was available to return. More data is required from the stream or prior filter.
PSFS_ERR_FATAL (default) The filter experienced an unrecoverable error and cannot continue.

bool onCreate()

Called when creating the filter

This method is called during instantiation of the filter class object. If your filter allocates or initializes any other resources (such as a buffer), this is the place to do it.

Return Value

bool

Your implementation of this method should return false on failure, or true on success.

void onClose()

Called when closing the filter

This method is called upon filter shutdown (typically, this is also during stream shutdown), and is executed after the flush method is called. If any resources were allocated or initialized during onCreate() this would be the time to destroy or dispose of them.

Return Value

void

bool seek(int $offset, int $whence, int $chain)

Since: 8.6

No description

Parameters

int $offset
int $whence
int $chain

Return Value

bool