Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00018 abstract class BasePrimitive
00019 {
00020 protected $name = null;
00021 protected $default = null;
00022 protected $value = null;
00023
00024 protected $required = false;
00025 protected $imported = false;
00026
00027 protected $raw = null;
00028
00029 protected $customError = null;
00030
00031 public function __construct($name)
00032 {
00033 $this->name = $name;
00034 }
00035
00036 public function getName()
00037 {
00038 return $this->name;
00039 }
00040
00044 public function setName($name)
00045 {
00046 $this->name = $name;
00047
00048 return $this;
00049 }
00050
00051 public function getDefault()
00052 {
00053 return $this->default;
00054 }
00055
00059 public function setDefault($default)
00060 {
00061 $this->default = $default;
00062
00063 return $this;
00064 }
00065
00066 public function getValue()
00067 {
00068 return $this->value;
00069 }
00070
00071 public function getRawValue()
00072 {
00073 return $this->raw;
00074 }
00075
00076 public function getActualValue()
00077 {
00078 if (null !== $this->value)
00079 return $this->value;
00080 elseif ($this->imported)
00081 return $this->raw;
00082
00083 return $this->default;
00084 }
00085
00086 public function getSafeValue()
00087 {
00088 if ($this->imported)
00089 return $this->value;
00090
00091 return $this->default;
00092 }
00093
00097 public function setValue($value)
00098 {
00099 $this->value = $value;
00100
00101 return $this;
00102 }
00103
00107 public function dropValue()
00108 {
00109 $this->value = null;
00110
00111 return $this;
00112 }
00113
00119 public function setRawValue($raw)
00120 {
00121 $this->raw = $raw;
00122
00123 return $this;
00124 }
00125
00126 public function isRequired()
00127 {
00128 return $this->required;
00129 }
00130
00134 public function setRequired($really = false)
00135 {
00136 $this->required = (true === $really ? true : false);
00137
00138 return $this;
00139 }
00140
00144 public function required()
00145 {
00146 $this->required = true;
00147
00148 return $this;
00149 }
00150
00154 public function optional()
00155 {
00156 $this->required = false;
00157
00158 return $this;
00159 }
00160
00161 public function isImported()
00162 {
00163 return $this->imported;
00164 }
00165
00169 public function clean()
00170 {
00171 $this->raw = null;
00172 $this->value = null;
00173 $this->imported = false;
00174
00175 return $this;
00176 }
00177
00178 public function importValue($value)
00179 {
00180 return $this->import(array($this->getName() => $value));
00181 }
00182
00183 public function exportValue()
00184 {
00185 return $this->value;
00186 }
00187
00188 public function getCustomError()
00189 {
00190 return $this->customError;
00191 }
00192
00193 protected function import($scope)
00194 {
00195 if (
00196 !empty($scope[$this->name])
00197 || (
00198 isset($scope[$this->name])
00199 && $scope[$this->name] !== ''
00200 )
00201 ) {
00202 $this->raw = $scope[$this->name];
00203
00204 return $this->imported = true;
00205 }
00206
00207 $this->clean();
00208
00209 return null;
00210 }
00211 }
00212 ?>