| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:05:09 2008 ] | [ onPHP 0.4.6 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /**************************************************************************** 3 * Copyright (C) 2005-2006 by Konstantin V. Arkhipov, Anton E. Lebedevich * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 ****************************************************************************/ 11 /* $Id: PlainForm.class.php 1684 2006-06-10 20:58:39Z voxus $ */ 12 13 /** 14 * Common Primitive-handling. 15 * 16 * @ingroup Form 17 **/ 18 abstract class PlainForm 19 { 20 protected $aliases = array(); 21 protected $primitives = array(); 22 23 public function addAlias($primitiveName, $alias) 24 { 25 if (!isset($this->primitives[$primitiveName])) 26 throw new MissingElementException( 27 "{$primitiveName} does not exist" 28 ); 29 30 $this->aliases[$alias] = $primitiveName; 31 32 return $this; 33 } 34 35 /** 36 * Bogus spelling of method defined below. 37 * 38 * @deprecated by primitiveExists($name) 39 **/ 40 public function primitiveExist($name) 41 { 42 return $this->primitiveExists($name); 43 } 44 45 public function primitiveExists($name) 46 { 47 return 48 ( 49 isset($this->primitives[$name]) || 50 isset($this->aliases[$name]) 51 ); 52 } 53 54 public function add(BasePrimitive $prm, $alias = null) 55 { 56 $name = $prm->getName(); 57 58 if (isset($this->primitives[$name])) 59 throw new WrongArgumentException( 60 "i'm already exists!" 61 ); 62 63 $this->primitives[$name] = $prm; 64 65 if ($alias) 66 $this->addAlias($name, $alias); 67 68 return $this; 69 } 70 71 public function drop($name) 72 { 73 if (!isset($this->primitives[$name])) 74 throw new MissingElementException( 75 "can not drop inexistent primitive '{$name}'" 76 ); 77 78 unset($this->primitives[$name]); 79 80 return $this; 81 } 82 83 public function &get($name) 84 { 85 if (isset($this->aliases[$name], $this->primitives[$this->aliases[$name]])) 86 return $this->primitives[$this->aliases[$name]]; 87 elseif (isset($this->primitives[$name])) 88 return $this->primitives[$name]; 89 90 throw new MissingElementException("knows nothing about '{$name}'"); 91 } 92 93 public function getValue($name) 94 { 95 return $this->get($name)->getValue(); 96 } 97 98 public function getRawValue($name) 99 { 100 return $this->get($name)->getRawValue(); 101 } 102 103 public function getActualValue($name) 104 { 105 return $this->get($name)->getActualValue(); 106 } 107 108 public function getDisplayValue($name) 109 { 110 $primitive = $this->get($name); 111 112 if ($primitive instanceof FiltrablePrimitive) 113 return $primitive->getDisplayValue(); 114 else 115 return $primitive->getActualValue(); 116 } 117 118 public function getChoiceValue($name) 119 { 120 $prm = $this->get($name); 121 122 Assert::isTrue($prm instanceof ListedPrimitive); 123 124 $list = $prm->getList(); 125 $value = $prm->getValue(); 126 127 if ($value instanceof Identifiable) 128 $value = $value->getId(); 129 130 if ($value !== null) 131 return $list[$value]; 132 133 return null; 134 } 135 136 public function getActualChoiceValue($name) 137 { 138 $prm = $this->get($name); 139 140 Assert::isTrue($prm instanceof ListedPrimitive); 141 142 $list = $prm->getList(); 143 $value = $prm->getActualValue(); 144 $default= $prm->getDefault(); 145 146 if ($value instanceof Identifiable) { 147 $value = $value->getId(); 148 149 if ($default) 150 $default = $default->getId(); 151 } 152 153 if ($value !== null && isset($list[$value])) 154 return $list[$value]; 155 elseif (isset($list[$default])) 156 return $list[$default]; 157 158 return null; 159 } 160 161 public function getRangeMax($name) 162 { 163 $range = $this->get($name)->getValue(); 164 165 return 166 $range instanceof Range 167 ? $range->getMax() 168 : null; 169 } 170 171 public function getRangeMin($name) 172 { 173 $range = $this->get($name)->getValue(); 174 175 return 176 $range instanceof Range 177 ? $range->getMin() 178 : null; 179 } 180 181 public function getActualRangeMax($name) 182 { 183 $range = $this->get($name)->getActualValue(); 184 185 return 186 $range instanceof Range 187 ? $range->getMax() 188 : null; 189 } 190 191 public function getActualRangeMin($name) 192 { 193 $range = $this->get($name)->getActualValue(); 194 195 return 196 $range instanceof Range 197 ? $range->getMin() 198 : null; 199 } 200 201 public function getPrimitiveNames() 202 { 203 return array_keys($this->primitives); 204 } 205 206 public function getPrimitiveList() 207 { 208 return $this->primitives; 209 } 210 } 211 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |