TrimFilter.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Anton E. Lebedevich                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: TrimFilter.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class TrimFilter implements Filtrator
00017     {
00018         const LEFT  = 'l';
00019         const RIGHT = 'r';
00020         const BOTH  = null;
00021         
00022         private $charlist   = null;
00023         private $direction  = self::BOTH;
00024         
00028         public static function create()
00029         {
00030             return new self;
00031         }
00032         
00036         public function setLeft()
00037         {
00038             $this->direction = self::LEFT;
00039             
00040             return $this;
00041         }
00042         
00046         public function setRight()
00047         {
00048             $this->direction = self::RIGHT;
00049             
00050             return $this;
00051         }
00052         
00056         public function setBoth()
00057         {
00058             $this->direction = self::BOTH;
00059             
00060             return $this;
00061         }
00062         
00063         public function apply($value)
00064         {
00065             $function = $this->direction.'trim';
00066             
00067             return (
00068                 $this->charlist
00069                     ? $function($value, $this->charlist)
00070                     : $function($value)
00071                 );
00072         }
00073         
00077         public function setCharlist($charlist)
00078         {
00079             $this->charlist = $charlist;
00080             
00081             return $this;
00082         }
00083     }
00084 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4