<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.filter.writing_filters">

    <title>Writing Filters</title>

    <para>
        Zend_Filter supplies a set of commonly needed filters, but developers will often need to write custom
        filters for their particular use cases. The task of writing a custom filter is facilitated by
        implementing <classname>Zend_Filter_Interface</classname>.
    </para>

    <para>
        <classname>Zend_Filter_Interface</classname> defines a single method, <code>filter()</code>, that may be
        implemented by user classes. An object that implements this interface may be added to a filter chain
        with <classname>Zend_Filter::addFilter()</classname>.
    </para>

    <para>
        The following example demonstrates how to write a custom filter:

        <programlisting role="php"><![CDATA[
class MyFilter implements Zend_Filter_Interface
{
    public function filter($value)
    {
        // perform some transformation upon $value to arrive on $valueFiltered

        return $valueFiltered;
    }
}
]]></programlisting>

    </para>

    <para>
        To add an instance of the filter defined above to a filter chain:

        <programlisting role="php"><![CDATA[
$filterChain = new Zend_Filter();
$filterChain->addFilter(new MyFilter());
]]></programlisting>

    </para>

</sect1>
<!--
vim:se ts=4 sw=4 et:
-->