PlainForm.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov, 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 /* $Id: PlainForm.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     abstract class PlainForm
00019     {
00020         protected $aliases      = array();
00021         protected $primitives   = array();
00022         
00026         public function clean()
00027         {
00028             foreach ($this->primitives as $prm)
00029                 $prm->clean();
00030             
00031             return $this;
00032         }
00033         
00038         public function addAlias($primitiveName, $alias)
00039         {
00040             if (!isset($this->primitives[$primitiveName]))
00041                 throw new MissingElementException(
00042                     "{$primitiveName} does not exist"
00043                 );
00044 
00045             $this->aliases[$alias] = $primitiveName;
00046             
00047             return $this;
00048         }
00049         
00050         public function primitiveExists($name)
00051         {
00052             return
00053                 (
00054                     isset($this->primitives[$name])
00055                     || isset($this->aliases[$name])
00056                 );
00057         }
00058         
00063         public function add(BasePrimitive $prm, $alias = null)
00064         {
00065             $name = $prm->getName();
00066             
00067             Assert::isFalse(
00068                 isset($this->primitives[$name]),
00069                 'i am already exists!'
00070             );
00071 
00072             $this->primitives[$name] = $prm;
00073             
00074             if ($alias)
00075                 $this->addAlias($name, $alias);
00076             
00077             return $this;
00078         }
00079         
00084         public function drop($name)
00085         {
00086             if (!isset($this->primitives[$name]))
00087                 throw new MissingElementException(
00088                     "can not drop inexistent primitive '{$name}'"
00089                 );
00090             
00091             unset($this->primitives[$name]);
00092             
00093             return $this;
00094         }
00095 
00100         public function &get($name)
00101         {
00102             if (isset($this->aliases[$name], $this->primitives[$this->aliases[$name]]))
00103                 return $this->primitives[$this->aliases[$name]];
00104             elseif (isset($this->primitives[$name]))
00105                 return $this->primitives[$name];
00106 
00107             throw new MissingElementException("knows nothing about '{$name}'");
00108         }
00109         
00110         public function getValue($name)
00111         {
00112             return $this->get($name)->getValue();
00113         }
00114         
00115         public function getRawValue($name)
00116         {
00117             return $this->get($name)->getRawValue();
00118         }
00119         
00120         public function getActualValue($name)
00121         {
00122             return $this->get($name)->getActualValue();
00123         }
00124         
00125         public function getSafeValue($name)
00126         {
00127             return $this->get($name)->getSafeValue();
00128         }
00129         
00130         public function getChoiceValue($name)
00131         {
00132             Assert::isTrue(($prm = $this->get($name)) instanceof ListedPrimitive);
00133             
00134             return $prm->getChoiceValue();
00135         }
00136         
00137         public function getActualChoiceValue($name)
00138         {
00139             Assert::isTrue(($prm = $this->get($name)) instanceof ListedPrimitive);
00140             
00141             return $prm->getActualChoiceValue();
00142         }
00143 
00144         public function getDisplayValue($name)
00145         {
00146             $primitive = $this->get($name);
00147             
00148             if ($primitive instanceof FiltrablePrimitive)
00149                 return $primitive->getDisplayValue();
00150             else
00151                 return $primitive->getActualValue();        
00152         }
00153 
00154         public function getPrimitiveNames()
00155         {
00156             return array_keys($this->primitives);
00157         }
00158         
00159         public function getPrimitiveList()
00160         {
00161             return $this->primitives;
00162         }
00163     }
00164 ?>

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