diff --git a/reference/stream/book.xml b/reference/stream/book.xml index b621dd730c..79a00273e0 100644 --- a/reference/stream/book.xml +++ b/reference/stream/book.xml @@ -70,6 +70,7 @@ &reference.stream.contexts; &reference.stream.errors; &reference.stream.examples; + &reference.stream.php-user-filter; &reference.stream.streamwrapper; &reference.stream.reference; diff --git a/reference/stream/functions/stream-filter-register.xml b/reference/stream/functions/stream-filter-register.xml index 587569b5bc..6e3f9ac83b 100644 --- a/reference/stream/functions/stream-filter-register.xml +++ b/reference/stream/functions/stream-filter-register.xml @@ -37,133 +37,13 @@ To implement a filter, you need to define a class as an extension of - php_user_filter with a number of member functions - as defined below. When performing read/write operations on the stream + php_user_filter with a number of member + functions. When performing read/write operations on the stream to which your filter is attached, PHP will pass the data through your filter (and any other filters attached to that stream) so that the data may be modified as desired. You must implement the methods - exactly as described below - doing otherwise will lead to undefined - behaviour. - - - intfilter - resourcein - resourceout - intconsumed - boolclosing - - - This method is called whenever data is read from or written to - the attached stream (such as with fread or fwrite). - in is a resource pointing to a bucket brigade - which contains one or more bucket objects containing data to be filtered. - out is a resource pointing to a second bucket brigade - into which your modified buckets should be placed. - 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. 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;. - 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. - - - - - - - - boolonCreate - - - - 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. Your implementation of - this method should return &false; on failure, or &true; on success. - - - When your filter is first instantiated, and - yourfilter->onCreate() is called, a number of properties - will be available as shown in the table below. - - - - - - - Property - Contents - - - - - FilterClass->filtername - - A string containing the name the filter was instantiated with. - Filters may be registered under multiple names or under wildcards. - Use this property to determine which name was used. - - - - FilterClass->params - - The contents of the params parameter passed - to stream_filter_append - or stream_filter_prepend. - - - - FilterClass->stream - - The stream resource being filtered. Maybe available only during - filter calls when the - closing parameter is set to &false;. - - - - - - - - voidonClose - - - - 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. + exactly as described in php_user_filter - doing + otherwise will lead to undefined behaviour. diff --git a/reference/stream/php-user-filter.xml b/reference/stream/php-user-filter.xml new file mode 100644 index 0000000000..6412bb5b07 --- /dev/null +++ b/reference/stream/php-user-filter.xml @@ -0,0 +1,103 @@ + + + + + + The php_user_filter class + php_user_filter + + + + +
+ &reftitle.intro; + + Children of this class are passed to + stream_filter_register. + +
+ + +
+ &reftitle.classsynopsis; + + + + php_user_filter + + + + + php_user_filter + + + + &Properties; + + public + filtername + + + public + params + + + + &Methods; + + + + +
+ + + +
+ &reftitle.properties; + + + filtername + + + Name of the filter registered by + stream_filter_append. + + + + + params + + + + + +
+ + + +
+ + &reference.stream.entities.php-user-filter; + +
+ + diff --git a/reference/stream/php_user_filter/filter.xml b/reference/stream/php_user_filter/filter.xml new file mode 100644 index 0000000000..aa06f6f3d8 --- /dev/null +++ b/reference/stream/php_user_filter/filter.xml @@ -0,0 +1,134 @@ + + + + + + php_user_filter::filter + Called when applying the filter + + + + &reftitle.description; + + public intphp_user_filter::filter + resourcein + resourceout + intconsumed + boolclosing + + + This method is called whenever data is read from or written to + the attached stream (such as with fread or fwrite). + + + + + + &reftitle.parameters; + + + in + + + in is a resource pointing to a bucket brigade + which contains one or more bucket objects containing data to be filtered. + + + + + out + + + out is a resource pointing to a second bucket brigade + into which your modified buckets should be placed. + + + + + consumed + + + 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. + + + + + 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;. + + + + + + + + &reftitle.returnvalues; + + 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. + + + + + + + + + + + + diff --git a/reference/stream/php_user_filter/onclose.xml b/reference/stream/php_user_filter/onclose.xml new file mode 100644 index 0000000000..767d43b586 --- /dev/null +++ b/reference/stream/php_user_filter/onclose.xml @@ -0,0 +1,60 @@ + + + + + + php_user_filter::onClose + Called when closing the filter + + + + &reftitle.description; + + public voidphp_user_filter::onClose + + + + 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. + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + Return value is ignored. + + + + + + + diff --git a/reference/stream/php_user_filter/oncreate.xml b/reference/stream/php_user_filter/oncreate.xml new file mode 100644 index 0000000000..375a9e377e --- /dev/null +++ b/reference/stream/php_user_filter/oncreate.xml @@ -0,0 +1,103 @@ + + + + + + php_user_filter::onCreate + Called when creating the filter + + + + &reftitle.description; + + public boolphp_user_filter::onCreate + + + + 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. + + + + When your filter is first instantiated, and + yourfilter->onCreate() is called, a number of properties + will be available as shown in the table below. + + + + + + + Property + Contents + + + + + FilterClass->filtername + + A string containing the name the filter was instantiated with. + Filters may be registered under multiple names or under wildcards. + Use this property to determine which name was used. + + + + FilterClass->params + + The contents of the params parameter passed + to stream_filter_append + or stream_filter_prepend. + + + + FilterClass->stream + + The stream resource being filtered. Maybe available only during + filter calls when the + closing parameter is set to &false;. + + + + + + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + Your implementation of + this method should return &false; on failure, or &true; on success. + + + + + + + diff --git a/reference/stream/setup.xml b/reference/stream/setup.xml index ec24976e92..b7c339fa1c 100644 --- a/reference/stream/setup.xml +++ b/reference/stream/setup.xml @@ -28,7 +28,7 @@ using the class definition shown on that manual page. - class php_user_filter is predefined and is an abstract + Class php_user_filter is predefined and is an abstract baseclass for use with user defined filters. See the manual page for stream_filter_register for details on implementing user defined filters.