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

    <para>
        <classname>Zend_Filter</classname> 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,
        <methodname>filter()</methodname>, that may be implemented by user classes. An object that
        implements this interface may be added to a filter chain with
        <methodname>Zend_Filter::addFilter()</methodname>.
    </para>

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

    <programlisting language="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>
        To add an instance of the filter defined above to a filter chain:
    </para>

    <programlisting language="php"><![CDATA[
$filterChain = new Zend_Filter();
$filterChain->addFilter(new MyFilter());
]]></programlisting>
</sect1>
<!--
vim:se ts=4 sw=4 et:
-->
