00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 ?>