FiltrablePrimitive.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2005-2007 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 /* $Id: FiltrablePrimitive.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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 ?>

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