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 
00015     final class TrimFilter implements Filtrator
00016     {
00017         const LEFT  = 'l';
00018         const RIGHT = 'r';
00019         const BOTH  = null;
00020         
00021         private $charlist   = null;
00022         private $direction  = self::BOTH;
00023         
00027         public static function create()
00028         {
00029             return new self;
00030         }
00031         
00035         public function setLeft()
00036         {
00037             $this->direction = self::LEFT;
00038             
00039             return $this;
00040         }
00041         
00045         public function setRight()
00046         {
00047             $this->direction = self::RIGHT;
00048             
00049             return $this;
00050         }
00051         
00055         public function setBoth()
00056         {
00057             $this->direction = self::BOTH;
00058             
00059             return $this;
00060         }
00061         
00062         public function apply($value)
00063         {
00064             $function = $this->direction.'trim';
00065             
00066             return (
00067                 $this->charlist
00068                     ? $function($value, $this->charlist)
00069                     : $function($value)
00070                 );
00071         }
00072         
00076         public function setCharlist($charlist)
00077         {
00078             $this->charlist = $charlist;
00079             
00080             return $this;
00081         }
00082     }
00083 ?>