標準のフィルタクラス群

フィルタチェイン

ひとつの値に対して、複数のフィルタを指定した順に適用しなければならないことがよくあります。 たとえば、ログインフォームで受け付けるユーザ名を 小文字の英字のみに限定する場合などです。 Zend_Filter は、複数のフィルタを連結する機能を提供しています。 以下のコードで、二つのフィルタをユーザ名に対して適用する方法を説明します。

  1. // フィルタチェインを作成し、そこにフィルタを追加します
  2. // ユーザ名をフィルタリングします
  3. 'username']);

フィルタは、Zend_Filter に追加した順に適用されます。 上の例では、まずユーザ名から非英字を除去したあとで、 大文字を小文字に変換します。

Zend_Filter_Interface を実装したオブジェクトなら何でも、 フィルタチェインに追加できます。

フィルタチェインの順序を変更

Since 1.10, the Zend_Filter chain also supports altering the chain by prepending or appending filters. For example, the next piece of code does exactly the same as the other username filter chain example:

  1. // Create a filter chain and add filters to the chain
  2. // this filter will be appended to the filter chain
  3. // this filter will be prepended at the beginning of the filter chain.
  4. // Filter the username
  5. 'username']);

標準のフィルタクラス群