PlainForm.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2005-2008 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 
00018     abstract class PlainForm
00019     {
00020         protected $primitives = array();
00021         
00025         public function clean()
00026         {
00027             foreach ($this->primitives as $prm)
00028                 $prm->clean();
00029             
00030             return $this;
00031         }
00032         
00033         public function exists($name)
00034         {
00035             return isset($this->primitives[$name]);
00036         }
00037 
00041         public function primitiveExists($name)
00042         {
00043             return $this->exists($name);
00044         }
00045         
00050         public function add(BasePrimitive $prm)
00051         {
00052             $name = $prm->getName();
00053             
00054             Assert::isFalse(
00055                 isset($this->primitives[$name]),
00056                 'i am already exists!'
00057             );
00058             
00059             $this->primitives[$name] = $prm;
00060             
00061             return $this;
00062         }
00063         
00067         public function set(BasePrimitive $prm)
00068         {
00069             $this->primitives[$prm->getName()] = $prm;
00070             
00071             return $this;
00072         }
00073         
00078         public function drop($name)
00079         {
00080             if (!isset($this->primitives[$name]))
00081                 throw new MissingElementException(
00082                     "can not drop inexistent primitive '{$name}'"
00083                 );
00084             
00085             unset($this->primitives[$name]);
00086             
00087             return $this;
00088         }
00089         
00094         public function get($name)
00095         {
00096             if (isset($this->primitives[$name]))
00097                 return $this->primitives[$name];
00098             
00099             throw new MissingElementException("knows nothing about '{$name}'");
00100         }
00101         
00102         public function getValue($name)
00103         {
00104             return $this->get($name)->getValue();
00105         }
00106         
00107         public function setValue($name, $value)
00108         {
00109             $this->get($name)->setValue($value);
00110             
00111             return $this;
00112         }
00113         
00114         public function getRawValue($name)
00115         {
00116             return $this->get($name)->getRawValue();
00117         }
00118         
00119         public function getActualValue($name)
00120         {
00121             return $this->get($name)->getActualValue();
00122         }
00123         
00124         public function getSafeValue($name)
00125         {
00126             return $this->get($name)->getSafeValue();
00127         }
00128         
00129         public function getChoiceValue($name)
00130         {
00131             Assert::isTrue(($prm = $this->get($name)) instanceof ListedPrimitive);
00132             
00133             return $prm->getChoiceValue();
00134         }
00135         
00136         public function getActualChoiceValue($name)
00137         {
00138             Assert::isTrue(($prm = $this->get($name)) instanceof ListedPrimitive);
00139             
00140             return $prm->getActualChoiceValue();
00141         }
00142         
00143         public function getDisplayValue($name)
00144         {
00145             $primitive = $this->get($name);
00146             
00147             if ($primitive instanceof FiltrablePrimitive)
00148                 return $primitive->getDisplayValue();
00149             else
00150                 return $primitive->getActualValue();
00151         }
00152         
00153         public function getPrimitiveNames()
00154         {
00155             return array_keys($this->primitives);
00156         }
00157         
00158         public function getPrimitiveList()
00159         {
00160             return $this->primitives;
00161         }
00162     }
00163 ?>