00001 <?php 00002 /**************************************************************************** 00003 * Copyright (C) 2005-2008 by Anton E. Lebedevich, Konstantin V. Arkhipov * 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 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 setDisplayFilter(FilterChain $chain) 00035 { 00036 $this->displayFilter = $chain; 00037 00038 return $this; 00039 } 00040 00044 public function addDisplayFilter(Filtrator $filter) 00045 { 00046 $this->displayFilter->add($filter); 00047 00048 return $this; 00049 } 00050 00054 public function dropDisplayFilters() 00055 { 00056 $this->displayFilter = new FilterChain(); 00057 00058 return $this; 00059 } 00060 00061 public function getDisplayValue() 00062 { 00063 if (is_array($value = $this->getActualValue())) { 00064 foreach ($value as &$element) 00065 $element = $this->displayFilter->apply($element); 00066 00067 return $value; 00068 } 00069 00070 return $this->displayFilter->apply($value); 00071 } 00072 00076 public function setImportFilter(FilterChain $chain) 00077 { 00078 $this->importFilter = $chain; 00079 00080 return $this; 00081 } 00082 00086 public function addImportFilter(Filtrator $filter) 00087 { 00088 $this->importFilter->add($filter); 00089 00090 return $this; 00091 } 00092 00096 public function dropImportFilters() 00097 { 00098 $this->importFilter = new FilterChain(); 00099 00100 return $this; 00101 } 00102 00106 public function getImportFilter() 00107 { 00108 return $this->importFilter; 00109 } 00110 00114 public function getDisplayFilter() 00115 { 00116 return $this->displayFilter; 00117 } 00118 00122 protected function selfFilter() 00123 { 00124 if (is_array($this->value)) 00125 foreach ($this->value as &$value) 00126 $value = $this->importFilter->apply($value); 00127 else 00128 $this->value = $this->importFilter->apply($this->value); 00129 00130 return $this; 00131 } 00132 } 00133 ?>