00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00018 abstract class FiltrablePrimitive extends RangedPrimitive
00019 {
00020 private $importFilter = null;
00021 private $displayFilter = null;
00022
00023 public function __construct($name)
00024 {
00025 parent::__construct($name);
00026
00027 $this->displayFilter = new FilterChain();
00028 $this->importFilter = new FilterChain();
00029 }
00030
00034 public function addDisplayFilter(Filtrator $filter)
00035 {
00036 $this->displayFilter->add($filter);
00037
00038 return $this;
00039 }
00040
00044 public function dropDisplayFilters()
00045 {
00046 $this->displayFilter->dropAll();
00047
00048 return $this;
00049 }
00050
00051 public function getDisplayValue()
00052 {
00053 if (is_array($value = $this->getActualValue())) {
00054 foreach ($value as &$element)
00055 $element = $this->displayFilter->apply($element);
00056
00057 return $value;
00058 }
00059
00060 return $this->displayFilter->apply($value);
00061 }
00062
00066 public function addImportFilter(Filtrator $filter)
00067 {
00068 $this->importFilter->add($filter);
00069
00070 return $this;
00071 }
00072
00076 public function dropImportFilters()
00077 {
00078 $this->importFilter->dropAll();
00079
00080 return $this;
00081 }
00082
00086 public function getImportFilter()
00087 {
00088 return $this->importFilter;
00089 }
00090
00094 public function getDisplayFilter()
00095 {
00096 return $this->displayFilter;
00097 }
00098
00102 protected function selfFilter()
00103 {
00104 if (is_array($this->value))
00105 foreach ($this->value as &$value)
00106 $value = $this->importFilter->apply($value);
00107 else
00108 $this->value = $this->importFilter->apply($this->value);
00109
00110 return $this;
00111 }
00112 }
00113 ?>